Bug 487797 - Don't rely on button names in <passwordmgr/test/*>. r=dolske
authorMatt Noorenberghe <mnoorenberghe@mozilla.com>
Wed, 06 May 2009 12:55:25 -0700
changeset 28039 cb5640022a6fe82433cad7cf8144566f018893ae
parent 28038 c501c343457d1b0209865fead103b7742bdb4e75
child 28040 0ba276249f0329a6309360ed05aced828fb4950c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs487797
milestone1.9.2a1pre
Bug 487797 - Don't rely on button names in <passwordmgr/test/*>. r=dolske
toolkit/components/passwordmgr/test/notification_common.js
toolkit/components/passwordmgr/test/test_notifications.html
toolkit/components/passwordmgr/test/test_prompt.html
--- a/toolkit/components/passwordmgr/test/notification_common.js
+++ b/toolkit/components/passwordmgr/test/notification_common.js
@@ -31,24 +31,23 @@ function getNotificationBar(aBox, aKind)
 }
 
 
 /*
  * clickNotificationButton
  *
  * Clicks the specified notification button.
  */
-function clickNotificationButton(aBar, aButtonName) {
+function clickNotificationButton(aBar, aButtonIndex) {
     // This is a bit of a hack. The notification doesn't have an API to
     // trigger buttons, so we dive down into the implementation and twiddle
     // the buttons directly.
-    var buttons = aBar.getElementsByTagName("button");
-    var clicked = false;
-    for (var i = 0; i < buttons.length; i++) {
-        if (buttons[i].label == aButtonName) {
-            buttons[i].click();
-            clicked = true;
-            break;
-        }
-    }
+    var button = aBar.getElementsByTagName("button").item(aButtonIndex);
+    ok(button, "Got button " + aButtonIndex);
+    button.doCommand();
+}
 
-    ok(clicked, "Clicked \"" + aButtonName + "\" button"); 
-}
+const kRememberButton = 0;
+const kNeverButton = 1;
+const kNotNowButton = 2;
+
+const kChangeButton = 0;
+const kDontChangeButton = 1;
--- a/toolkit/components/passwordmgr/test/test_notifications.html
+++ b/toolkit/components/passwordmgr/test/test_notifications.html
@@ -98,28 +98,28 @@ function checkTest() {
 
       /* Basic Yes/No/Never tests... */
 
       case 1:
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         break;
 
       case 2:
         // Same subtest, this time click Never
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
         is(true, pwmgr.getLoginSavingEnabled("http://localhost:8888"),
            "Checking for login saving enabled");
-        clickNotificationButton(bar, "Never for This Site");
+        clickNotificationButton(bar, kNeverButton);
         break;
 
       case 3:
         // Same subtest, make sure Never took effect
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(!bar, "checking for no notification bar");
@@ -130,17 +130,17 @@ function checkTest() {
         break;
 
       case 4:
         // Same subtest, this time click Remember
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Remember");
+        clickNotificationButton(bar, kRememberButton);
         break;
 
       case 5:
         // Same subtest, make sure we didn't prompt for an existing login.
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(!bar, "checking for no notification bar");
@@ -151,17 +151,17 @@ function checkTest() {
       /* signons.rememberSignons pref tests... */
 
       case 6:
         // Same subtest, make sure we're getting the bar again.
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         // Change prefs to no longer remember signons
         prefs.setBoolPref("rememberSignons", false);
         break;
 
       case 7:
         // Same subtest, make sure we're not prompting.
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
@@ -172,17 +172,17 @@ function checkTest() {
         break;
 
       case 8:
         // Same subtest, make sure we're getting the bar again.
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         break;
 
       /* autocomplete=off tests... */
 
       case 9:
         // Check for no notification bar when autocomplete=off present
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
@@ -244,52 +244,52 @@ function checkTest() {
         break;
 
       case 15:
         // Check for notification bar when existing pw-only login doesn't match form.
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         pwmgr.removeLogin(login2B);
 
         // Add login for the next test
         pwmgr.addLogin(login1B);
         break;
 
       case 16:
         // Check for notification bar when pw-only form doesn't match existing login.
         is(gotUser, "null",     "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         pwmgr.removeLogin(login1B);
 
         // Add login for the next tests
         pwmgr.addLogin(login1);
         break;
 
       case 17:
         // Check for change-password bar, u+p login on u+p form. (not changed)
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "pass2",    "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-change");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Don't Change");
+        clickNotificationButton(bar, kDontChangeButton);
         break;
 
       case 18:
         // Check for change-password bar, u+p login on u+p form.
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "pass2",    "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-change");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Change");
+        clickNotificationButton(bar, kChangeButton);
 
         // cleanup
         login1.password = "pass2";
         pwmgr.removeLogin(login1);
         login1.password = "notifyp1";
 
         // Add login for the next test
         pwmgr.addLogin(login2);
@@ -300,67 +300,67 @@ function checkTest() {
       case 19:
         // Check for change-password bar, p-only login on u+p form.
         // (needed a different subtest for this because the login created in
         // test_0init was interfering)
         is(gotUser, "",         "Checking submitted username");
         is(gotPass, "pass2",    "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-change");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Change");
+        clickNotificationButton(bar, kChangeButton);
         break;
 
       case 20:
         // Check for change-password bar, p-only login on p-only form.
         is(gotUser, "null",     "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-change");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Change");
+        clickNotificationButton(bar, kChangeButton);
 
         pwmgr.removeLogin(login2);
         break;
 
       case 21:
         // Check text on a user+pass notification bar
         is(gotUser, "notifyu1", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
         // Check the text, which comes from the localized saveLoginText string.
         notificationText = bar.getAttribute("label");
         expectedText = /^Do you want .+ to remember the password for \"notifyu1\" on example.org\?$/;
         ok(expectedText.test(notificationText), "Checking text: " + notificationText);
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         break;
 
       case 22:
         // Check text on a user+pass notification bar, username is really long
         is(gotUser, "nowisthetimeforallgoodmentocometotheaidoftheircountry", "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
         // Check the text, which comes from the localized saveLoginText string.
         notificationText = bar.getAttribute("label");
         expectedText = /^Do you want .+ to remember the password for \"nowisthetimeforallgoodmentocom[^e]\" on example.org\?$/;
         ok(expectedText.test(notificationText), "Checking text: " + notificationText);
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         break;
 
       case 23:
         // Check text on a pass-only notification bar
         is(gotUser, "null",     "Checking submitted username");
         is(gotPass, "notifyp1", "Checking submitted password");
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
         // Check the text, which comes from the localized saveLoginTextNoUser string.
         notificationText = bar.getAttribute("label");
         expectedText = /^Do you want .+ to remember this password on example.org\?$/;
         ok(expectedText.test(notificationText), "Checking text: " + notificationText);
-        clickNotificationButton(bar, "Not Now");
+        clickNotificationButton(bar, kNotNowButton);
         break;
 
       default:
         ok(false, "Unexpected call to checkTest for test #" + testNum);
 
     }
 
     // TODO:
--- a/toolkit/components/passwordmgr/test/test_prompt.html
+++ b/toolkit/components/passwordmgr/test/test_prompt.html
@@ -367,17 +367,17 @@ function handleLoad() {
         testNum++;
         is(authok, "PASS", "Checking for successful authentication");
         is(username, "mochiuser1", "Checking for echoed username");
         is(password, "mochipass1-new", "Checking for echoed password");
 
         // Check for the notification bar, and change the password.
         bar = getNotificationBar(notifyBox, "password-change");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Change");
+        clickNotificationButton(bar, kChangeButton);
 
         // Housekeeping: change it back
         tmpLogin.init("http://localhost:8888", null, "mochitest",
                       "mochiuser1", "mochipass1-new", "", "");
         pwmgr.modifyLogin(tmpLogin, login3A);
 
         // Same as last test, but for a realm we haven't already authenticated
         // to (but have an existing saved login for, so that we'll trigger
@@ -390,17 +390,17 @@ function handleLoad() {
         testNum++;
         is(authok, "PASS", "Checking for successful authentication");
         is(username, "mochiuser3", "Checking for echoed username");
         is(password, "mochipass3-new", "Checking for echoed password");
 
         // Check for the notification bar, and change the password.
         bar = getNotificationBar(notifyBox, "password-change");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Change");
+        clickNotificationButton(bar, kChangeButton);
 
         // Housekeeping: change it back to the original login4. Actually,
         // just delete it and we'll re-add it as the next test.
         tmpLogin.init("http://localhost:8888", null, "mochitest3",
                       "mochiuser3", "mochipass3-new", "", "");
         pwmgr.removeLogin(tmpLogin);
         // Clear cached auth from this subtest, and avoid leaking due to bug 459620.
         var authMgr = Cc['@mozilla.org/network/http-auth-manager;1'].
@@ -416,17 +416,17 @@ function handleLoad() {
         testNum++;
         is(authok, "PASS", "Checking for successful authentication");
         is(username, "mochiuser3", "Checking for echoed username");
         is(password, "mochipass3-old", "Checking for echoed password");
 
         // Check for the notification bar, and change the password.
         bar = getNotificationBar(notifyBox, "password-save");
         ok(bar, "got notification bar");
-        clickNotificationButton(bar, "Remember");
+        clickNotificationButton(bar, kRememberButton);
 
         finishTest();
         break;
 
     default:
         ok(false, "Uhh, unhandled switch for testNum #" + testNum);
         break;
   }