Bug 1263784 - Fix test_modal_prompts.html and test_modal_select.html to run under E10S. r=adw draft
authorJustin Dolske <dolske@mozilla.com>
Fri, 15 Apr 2016 13:43:25 -0700
changeset 352164 fd30b56983e4d7f7236c66be4ff075fca714b6e8
parent 352163 f9842066a0ad5dde957e1084cdbe3d858b34ea56
child 352165 1d825baf000359c127707e0f1c77d1465f257788
push id15634
push userjdolske@mozilla.com
push dateFri, 15 Apr 2016 20:44:40 +0000
reviewersadw
bugs1263784
milestone48.0a1
Bug 1263784 - Fix test_modal_prompts.html and test_modal_select.html to run under E10S. r=adw Make expected-state object independent from ui object. MozReview-Commit-ID: 547tN5kSyDt
toolkit/components/prompts/test/test_modal_prompts.html
--- a/toolkit/components/prompts/test/test_modal_prompts.html
+++ b/toolkit/components/prompts/test/test_modal_prompts.html
@@ -56,37 +56,56 @@ function checkExpectedState(ui, state, a
         is(ui.button2.label, state.butt2Label, "Checking extra1-button label");
     }
 
     function isDefaultButton(b) {
         return (b.hasAttribute("default") &&
                 b.getAttribute("default") == "true");
     }
 
-    let shouldBeDefault;
-    shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button0);
-    is(isDefaultButton(ui.button0), shouldBeDefault, "checking button0 default");
-    shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button1);
-    is(isDefaultButton(ui.button1), shouldBeDefault, "checking button1 default");
-    shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button2);
-    is(isDefaultButton(ui.button2), shouldBeDefault, "checking button2 default");
+    is(isDefaultButton(ui.button0), state.defButton == "button0", "checking button0 default");
+    is(isDefaultButton(ui.button1), state.defButton == "button1", "checking button1 default");
+    is(isDefaultButton(ui.button2), state.defButton == "button2", "checking button2 default");
 
     let fm = Cc["@mozilla.org/focus-manager;1"].
              getService(Ci.nsIFocusManager);
     let e = fm.focusedElement;
     ok(true, "focused element is a " + (e ? e.localName : "<null>"));
     if (isLinux && !e) {
         todo(false, "Focus seems missing on Linux");
+    } else if (isOSX && state.focused && state.focused.startsWith("button")) {
+        ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X");
+    } else if (state.focused == null) {
+        is(e, null, "Not expecting a focused element");
     } else {
-        if (isOSX && state.focused && state.focused.localName == "button")
-            ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X");
-        else if (state.focused)
-            ok(SpecialPowers.compare(state.focused, e), "Checking focused element");
-        else
-            is(e, null, "Not expecting a focused element");
+        let expectedElement;
+        switch (state.focused) {
+            case "button0":
+                expectedElement = ui.button0;
+                break;
+            case "button1":
+                expectedElement = ui.button1;
+                break;
+            case "button2":
+                expectedElement = ui.button2;
+                break;
+            case "textField":
+                expectedElement = ui.loginTextbox.inputField;
+                break;
+            case "passField":
+                expectedElement = ui.password1Textbox.inputField;
+                break;
+            case "infoBody":
+                expectedElement = ui.infoBody;
+                break;
+            default:
+                ok(false, "Test listed an unknown element as expecting to be focused!");
+                break;
+        }
+        ok(SpecialPowers.compare(expectedElement, e), "Checking focused element");
     }
 
 
     /* Actions */
 
 
     if (action.setCheckbox) {
         // Annoyingly, the prompt code is driven by oncommand.
@@ -161,18 +180,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "alert-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 2:
@@ -183,18 +202,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "alert-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 3:
@@ -205,18 +224,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "alert-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
             setCheckbox: true,
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -228,18 +247,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 5:
@@ -250,18 +269,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "cancel",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 6:
@@ -272,18 +291,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 7:
@@ -294,18 +313,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "cancel",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 8:
@@ -316,18 +335,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
             setCheckbox: true,
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -339,18 +358,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "cancel",
             setCheckbox: true,
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -362,18 +381,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : false,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "ok",
             textField   : "bacon",
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -385,18 +404,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : false,
             passHidden  : true,
             checkHidden : true,
             textValue   : "kittens",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 12:
@@ -407,18 +426,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : false,
             passHidden  : true,
             checkHidden : true,
             textValue   : "puppies",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "cancel",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 13:
@@ -429,18 +448,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : false,
             passHidden  : true,
             checkHidden : true,
             textValue   : "puppies",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "cancel",
             textField   : "bacon",
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -452,18 +471,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : false,
             passHidden  : true,
             checkHidden : false,
             textValue   : "tribbles",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
             setCheckbox: true,
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -475,18 +494,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : false,
             passHidden  : true,
             checkHidden : false,
             textValue   : "tribbles",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "cancel",
             setCheckbox: true,
         };
         checkExpectedState(ui, state, action);
         break;
 
@@ -498,18 +517,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "authentication-icon question-icon",
             textHidden  : false,
             passHidden  : false,
             checkHidden : false,
             textValue   : "usr",
             passValue   : "ssh",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
             setCheckbox: true,
             textField: "newusr",
             passField: "newssh",
         };
         checkExpectedState(ui, state, action);
@@ -523,18 +542,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "authentication-icon question-icon",
             textHidden  : false,
             passHidden  : false,
             checkHidden : false,
             textValue   : "usr",
             passValue   : "ssh",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "cancel",
             setCheckbox : true,
             textField   : "newusr",
             passField   : "newssh",
         };
         checkExpectedState(ui, state, action);
@@ -548,18 +567,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "authentication-icon question-icon",
             textHidden  : true,
             passHidden  : false,
             checkHidden : false,
             textValue   : "",
             passValue   : "ssh",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.password1Textbox.inputField,
-            defButton   : ui.button0,
+            focused     : "passField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "ok",
             setCheckbox : true,
             passField   : "newssh",
         };
         checkExpectedState(ui, state, action);
         break;
@@ -572,18 +591,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "authentication-icon question-icon",
             textHidden  : true,
             passHidden  : false,
             checkHidden : false,
             textValue   : "",
             passValue   : "ssh",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.password1Textbox.inputField,
-            defButton   : ui.button0,
+            focused     : "passField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "cancel",
             setCheckbox : true,
             passField   : "newssh",
         };
         checkExpectedState(ui, state, action);
         break;
@@ -596,18 +615,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
             butt0Label  : "OK",
             butt1Label  : "Cancel",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
@@ -620,18 +639,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
             butt0Label  : "Yes",
             butt1Label  : "No",
         };
         action = {
             buttonClick: "cancel",
         };
         checkExpectedState(ui, state, action);
         break;
@@ -644,18 +663,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
             butt0Label  : "butt0",
             butt1Label  : "butt1",
             butt2Label  : "butt2",
         };
         action = {
             buttonClick: "ok",
             setCheckbox: true,
         };
@@ -670,18 +689,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.button1, // Default changed!
-            defButton   : ui.button1,
+            focused     : "button1", // Default changed!
+            defButton   : "button1",
             butt0Label  : "butt0",
             butt1Label  : "butt1",
             butt2Label  : "butt2",
         };
         action = {
             buttonClick: "cancel",
             setCheckbox: true,
         };
@@ -697,18 +716,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "question-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.button2, // Default changed!
-            defButton   : ui.button2,
+            focused     : "button2", // Default changed!
+            defButton   : "button2",
             butt0Label  : "butt0",
             butt1Label  : "butt1",
             butt2Label  : "butt2",
         };
         action = {
             buttonClick: 2,
             setCheckbox: true,
         };
@@ -724,18 +743,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "alert-icon",
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
-            focused     : ui.button0,
-            defButton   : ui.button0,
+            focused     : "button0",
+            defButton   : "button0",
         };
         action = {
             buttonClick: "ok",
         };
         checkExpectedState(ui, state, action);
         break;
 
       case 26:
@@ -747,25 +766,25 @@ function handleDialog(ui, testNum) {
             textHidden  : true,
             passHidden  : true,
             checkHidden : true,
             textValue   : "",
             passValue   : "",
             checkMsg    : "",
             checked     : false,
             focused     : null, // nothing focused until after delay fires
-            defButton   : ui.button0,
+            defButton   : "button0",
             butt0Label  : "OK",
             butt1Label  : "Cancel",
         };
 
         // OS X doesn't initially focus the button, but rather the infoBody.
         // The focus stays there even after the button-enable delay has fired.
         if (isOSX)
-            state.focused = ui.infoBody;
+            state.focused = "infoBody";
 
         action = {
             buttonClick: "pollOK",
         };
         checkExpectedState(ui, state, action);
         break;
 
 
@@ -777,18 +796,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "authentication-icon question-icon",
             textHidden  : false,
             passHidden  : false,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "ok",
             setCheckbox : true,
             textField   : "username",
             passField   : "password",
         };
         checkExpectedState(ui, state, action);
@@ -805,18 +824,18 @@ function handleDialog(ui, testNum) {
             iconClass   : "authentication-icon question-icon",
             textHidden  : false,
             passHidden  : false,
             checkHidden : false,
             textValue   : "",
             passValue   : "",
             checkMsg    : "Check me out!",
             checked     : false,
-            focused     : ui.loginTextbox.inputField,
-            defButton   : ui.button0,
+            focused     : "textField",
+            defButton   : "button0",
         };
         action = {
             buttonClick : "ok",
             setCheckbox : true,
             textField   : "username",
             passField   : "password",
         };
         checkExpectedState(ui, state, action);