Bug 1266575 - Regression test. r?felipe draft
authorMike Conley <mconley@mozilla.com>
Mon, 16 May 2016 10:41:25 -0400
changeset 367956 daecc6227743f963056bf1f9182400b8f608e1e4
parent 367955 18f650e5527c59b344631943295c180da58d59f1
child 521147 89a122fac3203cc5472c6f3a1532d9c1e4dff123
push id18395
push usermconley@mozilla.com
push dateTue, 17 May 2016 19:37:22 +0000
reviewersfelipe
bugs1266575
milestone49.0a1
Bug 1266575 - Regression test. r?felipe MozReview-Commit-ID: 7mOVDXFqozL
browser/base/content/test/general/browser_selectpopup.js
--- a/browser/base/content/test/general/browser_selectpopup.js
+++ b/browser/base/content/test/general/browser_selectpopup.js
@@ -270,8 +270,75 @@ add_task(function*() {
     is(rect.left, expectedX, "step " + (stepIndex + 1) + " x");
     is(rect.top, expectedY, "step " + (stepIndex + 1) + " y");
 
     yield hideSelectPopup(selectPopup);
   }
 
   yield BrowserTestUtils.removeTab(tab);
 });
+
+// Test that we get the right events when a select popup is changed.
+add_task(function* test_event_order() {
+  const URL = "data:text/html," + escape(PAGECONTENT_SMALL);
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: URL,
+  }, function*(browser) {
+    let menulist = document.getElementById("ContentSelectDropdown");
+    let selectPopup = menulist.menupopup;
+
+    yield openSelectPopup(selectPopup, true, "#one");
+
+    let eventsPromise = ContentTask.spawn(browser, null, function*() {
+      // According to https://html.spec.whatwg.org/#the-select-element,
+      // we want to fire input, change, and then click events on the
+      // <select> (in that order) when it has changed.
+      let expected = [
+        {
+          type: "input",
+          cancelable: false,
+        },
+        {
+          type: "change",
+          cancelable: false,
+        },
+        {
+          type: "mousedown",
+          cancelable: true,
+        },
+        {
+          type: "mouseup",
+          cancelable: true,
+        },
+        {
+          type: "click",
+          cancelable: true,
+        },
+      ];
+
+      return new Promise((resolve) => {
+        function onEvent(event) {
+          select.removeEventListener(event.type, onEvent);
+          let expectation = expected.shift();
+          Assert.equal(event.type, expectation.type,
+                       "Expected the right event order");
+          Assert.ok(event.bubbles, "All of these events should bubble");
+          Assert.equal(event.cancelable, expectation.cancelable,
+                       "Cancellation property should match");
+          if (!expected.length) {
+            resolve();
+          }
+        }
+
+        let select = content.document.getElementById("one");
+        for (let expectation of expected) {
+          select.addEventListener(expectation.type, onEvent);
+        }
+      });
+    });
+
+    EventUtils.synthesizeKey("KEY_ArrowDown", { code: "ArrowDown" });
+    yield hideSelectPopup(selectPopup, false);
+    yield eventsPromise;
+  });
+});
+