Bug 1253479 - [e10s] Make widget/tests/test_assign_event_data.html work under e10s. r=masayuki
authorDrew Willcoxon <adw@mozilla.com>
Thu, 10 Mar 2016 16:56:13 -0800
changeset 288145 a73b90e53f9c46e4e93310e98c0e61832ce6ce1d
parent 288144 e83eb1ba4b838f8f8b8de3d1875421f4daec1613
child 288146 47c57a3f7007445c9750d1fc0fcb74bfc584ee10
push id73323
push userdwillcoxon@mozilla.com
push dateFri, 11 Mar 2016 00:56:24 +0000
treeherdermozilla-inbound@a73b90e53f9c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1253479
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1253479 - [e10s] Make widget/tests/test_assign_event_data.html work under e10s. r=masayuki
widget/tests/mochitest.ini
widget/tests/test_assign_event_data.html
--- a/widget/tests/mochitest.ini
+++ b/widget/tests/mochitest.ini
@@ -1,11 +1,11 @@
 [DEFAULT]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 support-files = utils.js
 
 [test_assign_event_data.html]
-skip-if = toolkit == "cocoa" || e10s # Mac: Bug 933303
+skip-if = toolkit == "cocoa" # Mac: Bug 933303
 [test_bug565392.html]
 skip-if = toolkit != "windows" || (e10s && os == 'win')
 [test_picker_no_crash.html]
 skip-if = toolkit != "windows" || (e10s && os == 'win')
 support-files = window_picker_no_crash_child.html
--- a/widget/tests/test_assign_event_data.html
+++ b/widget/tests/test_assign_event_data.html
@@ -193,55 +193,59 @@ const kTests = [
     canRun: function () {
       return (kIsMac || kIsWin);
     },
     todoMismatch: [],
   },
   { description: "WidgetKeyboardEvent (keyup during composition)",
     targetID: "input-text", eventType: "keyup",
     dispatchEvent: function () {
-      SpecialPowers.setBoolPref("dom.keyboardevent.dispatch_during_composition", true);
-      document.getElementById(this.targetID).value = "";
-      document.getElementById(this.targetID).focus();
-      synthesizeCompositionChange({ "composition":
-        { "string": "\u306D",
-          "clauses":
-          [
-            { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
-          ]
-        },
-        "caret": { "start": 1, "length": 0 },
-        "key": { key: "a", code: "KeyA", keyCode: KeyboardEvent.DOM_VK_A },
+      setAndObserveCompositionPref(true, () => {
+        document.getElementById(this.targetID).value = "";
+        document.getElementById(this.targetID).focus();
+        synthesizeCompositionChange({ "composition":
+          { "string": "\u306D",
+            "clauses":
+            [
+              { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
+            ]
+          },
+          "caret": { "start": 1, "length": 0 },
+          "key": { key: "a", code: "KeyA", keyCode: KeyboardEvent.DOM_VK_A },
+        });
+        synthesizeComposition({ type: "compositioncommitasis" });
+        setAndObserveCompositionPref(null, runNextTest);
       });
-      synthesizeComposition({ type: "compositioncommitasis" });
-      SpecialPowers.clearUserPref("dom.keyboardevent.dispatch_during_composition");
+      return true;
     },
     canRun: function () {
       return true;
     },
     todoMismatch: [ ],
   },
   { description: "WidgetKeyboardEvent (keydown during composition)",
     targetID: "input-text", eventType: "keydown",
     dispatchEvent: function () {
-      SpecialPowers.setBoolPref("dom.keyboardevent.dispatch_during_composition", true);
-      document.getElementById(this.targetID).value = "";
-      document.getElementById(this.targetID).focus();
-      synthesizeCompositionChange({ "composition":
-        { "string": "\u306D",
-          "clauses":
-          [
-            { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
-          ]
-        },
-        "caret": { "start": 1, "length": 0 }
+      setAndObserveCompositionPref(true, () => {
+        document.getElementById(this.targetID).value = "";
+        document.getElementById(this.targetID).focus();
+        synthesizeCompositionChange({ "composition":
+          { "string": "\u306D",
+            "clauses":
+            [
+              { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
+            ]
+          },
+          "caret": { "start": 1, "length": 0 }
+        });
+        synthesizeComposition({ type: "compositioncommitasis",
+          key: { key: "KEY_Enter", code: "Enter" } });
+        setAndObserveCompositionPref(null, runNextTest);
       });
-      synthesizeComposition({ type: "compositioncommitasis",
-        key: { key: "KEY_Enter", code: "Enter" } });
-      SpecialPowers.clearUserPref("dom.keyboardevent.dispatch_during_composition");
+      return true;
     },
     canRun: function () {
       return true;
     },
     todoMismatch: [ ],
   },
   { description: "WidgetMouseEvent (mousedown of left button without modifier)",
     targetID: "button", eventType: "mousedown",
@@ -615,16 +619,43 @@ const kTests = [
     },
     canRun: function () {
       return true;
     },
     todoMismatch: [],
   },
 ];
 
+/**
+ * Sets or clears dom.keyboardevent.dispatch_during_composition and calls the
+ * given callback when the change is observed.
+ *
+ * @param aValue
+ *        Pass null to clear the pref.  Otherwise pass a bool.
+ * @param aCallback
+ *        Called when the pref change is observed.
+ */
+function setAndObserveCompositionPref(aValue, aCallback) {
+  let pref = "dom.keyboardevent.dispatch_during_composition";
+  let branch = SpecialPowers.Cc["@mozilla.org/preferences-service;1"].
+               getService(SpecialPowers.Ci.nsIPrefService).
+               getBranch(pref);
+  let obs = SpecialPowers.wrapCallback(function () {
+    branch.removeObserver("", obs);
+    // Make sure the code under test sees the change first, so executeSoon().
+    SimpleTest.executeSoon(aCallback);
+  });
+  branch.addObserver("", obs, false);
+  if (aValue === null) {
+    SpecialPowers.clearUserPref(pref);
+  } else {
+    SpecialPowers.setBoolPref(pref, aValue);
+  }
+}
+
 function doTest(aTest)
 {
   if (!aTest.canRun()) {
     SimpleTest.executeSoon(runNextTest);
     return;
   }
   gEvent = null;
   gCopiedEvent = [];
@@ -647,19 +678,21 @@ function doTest(aTest)
         todo_is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")");
       } else if (name == "offsetX" || name == "offsetY") {
         // do nothing; these are defined to return different values during event dispatch
         // vs not during event dispatch
       } else {
         is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")");
       }
     }
-    runNextTest();
+    if (!testWillCallRunNextTest) {
+      runNextTest();
+    }
   };
-  aTest.dispatchEvent();
+  var testWillCallRunNextTest = aTest.dispatchEvent();
 }
 
 var gIndex = -1;
 function runNextTest()
 {
   if (++gIndex == kTests.length) {
     if (gCallPreventDefault) {
       finish();