Bug 1401876 - (Part 2) Add browser-chrome test for reopening picker. r=mconley draft
authorScott Wu <scottcwwu@gmail.com>
Mon, 25 Sep 2017 17:43:27 +0800
changeset 669733 73a697b5707d4bf49627eb35b435ab4f49ea444f
parent 669732 6ab1955bfbb73934eb2ef603976d92ba7389f7b9
child 733038 5904199251d3a2bba1d168f624902feb624165b6
push id81414
push userbmo:scwwu@mozilla.com
push dateMon, 25 Sep 2017 10:06:39 +0000
reviewersmconley
bugs1401876
milestone58.0a1
Bug 1401876 - (Part 2) Add browser-chrome test for reopening picker. r=mconley MozReview-Commit-ID: BjR0rVxkdT
toolkit/content/tests/browser/browser_datetime_datepicker.js
toolkit/content/tests/browser/head.js
--- a/toolkit/content/tests/browser/browser_datetime_datepicker.js
+++ b/toolkit/content/tests/browser/browser_datetime_datepicker.js
@@ -168,16 +168,38 @@ add_task(async function test_datepicker_
   });
 
   Assert.equal(content.document.querySelector("input").value, firstDayOnCalendar);
 
   await helper.tearDown();
 });
 
 /**
+ * Make sure picker is in correct state when it is reopened.
+ */
+add_task(async function test_datepicker_reopen_state() {
+  const inputValue = "2016-12-15";
+  const nextMonth = "2017-01-01";
+
+  await helper.openPicker(`data:text/html, <input type="date" value="${inputValue}">`);
+  // Navigate to the next month but does not commit the change
+  Assert.equal(helper.getElement(MONTH_YEAR).textContent, DATE_FORMAT(new Date(inputValue)));
+  helper.click(helper.getElement(BTN_NEXT_MONTH));
+  Assert.equal(helper.getElement(MONTH_YEAR).textContent, DATE_FORMAT(new Date(nextMonth)));
+  EventUtils.synthesizeKey("VK_ESCAPE", {}, window);
+
+  // Ensures the picker opens to the month of the input value
+  await BrowserTestUtils.synthesizeMouseAtCenter("input", {}, gBrowser.selectedBrowser);
+  await helper.waitForPickerReady();
+  Assert.equal(helper.getElement(MONTH_YEAR).textContent, DATE_FORMAT(new Date(inputValue)));
+
+  await helper.tearDown();
+});
+
+/**
  * When min and max attributes are set, calendar should show some dates as
  * out-of-range.
  */
 add_task(async function test_datepicker_min_max() {
   const inputValue = "2016-12-15";
   const inputMin = "2016-12-05";
   const inputMax = "2016-12-25";
 
--- a/toolkit/content/tests/browser/head.js
+++ b/toolkit/content/tests/browser/head.js
@@ -143,18 +143,22 @@ class DateTimeTestHelper {
   async openPicker(pageUrl) {
     this.tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
     await BrowserTestUtils.synthesizeMouseAtCenter("input", {}, gBrowser.selectedBrowser);
     // If dateTimePopupFrame doesn't exist yet, wait for the binding to be attached
     if (!this.panel.dateTimePopupFrame) {
       await BrowserTestUtils.waitForEvent(this.panel, "DateTimePickerBindingReady")
     }
     this.frame = this.panel.dateTimePopupFrame;
+    await this.waitForPickerReady();
+  }
+
+  async waitForPickerReady() {
     await BrowserTestUtils.waitForEvent(this.frame, "load", true);
-    // Wait for picker elements to be ready and open panel transition to end
+    // Wait for picker elements to be ready
     await BrowserTestUtils.waitForEvent(this.frame.contentDocument, "PickerReady");
   }
 
   /**
    * Find an element on the picker.
    *
    * @param  {String} selector
    * @return {DOMElement}