From 3ce993ddc02e229411413613eada082c4e088831 Mon Sep 17 00:00:00 2001 From: Neil Rashbrook Date: Tue, 31 Mar 2009 17:35:55 +0100 Subject: [PATCH] Bug 485175 Make geolocation tests more reliable r=dougt --- .../geolocation/geolocation_common.js | 34 ++++++------------- .../geolocation/test_allowCurrent.html | 2 +- .../geolocation/test_allowWatch.html | 2 +- .../geolocation/test_cancelCurrent.html | 2 +- .../geolocation/test_cancelWatch.html | 2 +- .../geolocation/test_clearWatch.html | 2 +- .../geolocation/test_timeoutWatch.html | 2 +- 7 files changed, 16 insertions(+), 30 deletions(-) diff --git a/dom/tests/mochitest/geolocation/geolocation_common.js b/dom/tests/mochitest/geolocation/geolocation_common.js index 21513186db2..bc7a42ef3ba 100644 --- a/dom/tests/mochitest/geolocation/geolocation_common.js +++ b/dom/tests/mochitest/geolocation/geolocation_common.js @@ -38,8 +38,6 @@ function check_geolocation(location) { function getNotificationBox() { - netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); - const Ci = Components.interfaces; function getChromeWindow(aWindow) { @@ -64,32 +62,20 @@ function getNotificationBox() } -function clickNotificationButton(aBar, aButtonName) { +function clickNotificationButton(aButtonIndex) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); // 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; - } - } - - ok(clicked, "Clicked \"" + aButtonName + "\" button"); + var box = getNotificationBox(); + ok(box, "Got notification box"); + var bar = box.getNotificationWithValue("geolocation"); + ok(bar, "Got geolocation notification"); + var button = bar.getElementsByTagName("button").item(aButtonIndex); + ok(button, "Got button"); + button.doCommand(); } - -function clickAccept() -{ - clickNotificationButton(getNotificationBox().currentNotification, "Tell them"); -} - -function clickDeny() -{ - clickNotificationButton(getNotificationBox().currentNotification, "Don't tell them"); -} +const kAcceptButton = 0; +const kDenyButton = 1; diff --git a/dom/tests/mochitest/geolocation/test_allowCurrent.html b/dom/tests/mochitest/geolocation/test_allowCurrent.html index 98a1a4c4f10..c1244411a0c 100644 --- a/dom/tests/mochitest/geolocation/test_allowCurrent.html +++ b/dom/tests/mochitest/geolocation/test_allowCurrent.html @@ -30,7 +30,7 @@ function successCallback(position) { function accept() { hasAccepted = true; - clickAccept(); + clickNotificationButton(kAcceptButton); } SimpleTest.waitForExplicitFinish(); diff --git a/dom/tests/mochitest/geolocation/test_allowWatch.html b/dom/tests/mochitest/geolocation/test_allowWatch.html index d0ce518f20d..57db429a835 100644 --- a/dom/tests/mochitest/geolocation/test_allowWatch.html +++ b/dom/tests/mochitest/geolocation/test_allowWatch.html @@ -34,7 +34,7 @@ function successCallback(position) { function accept() { hasAccepted = true; - clickAccept(); + clickNotificationButton(kAcceptButton); } /** Test for Bug **/ diff --git a/dom/tests/mochitest/geolocation/test_cancelCurrent.html b/dom/tests/mochitest/geolocation/test_cancelCurrent.html index 798c39feb22..9c53d625e7f 100644 --- a/dom/tests/mochitest/geolocation/test_cancelCurrent.html +++ b/dom/tests/mochitest/geolocation/test_cancelCurrent.html @@ -37,7 +37,7 @@ SimpleTest.waitForExplicitFinish(); navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null); // click deny -setTimeout(clickDeny, 50); +setTimeout(clickNotificationButton, 50, kDenyButton); diff --git a/dom/tests/mochitest/geolocation/test_cancelWatch.html b/dom/tests/mochitest/geolocation/test_cancelWatch.html index c11d93b72a0..74f2dd0170b 100644 --- a/dom/tests/mochitest/geolocation/test_cancelWatch.html +++ b/dom/tests/mochitest/geolocation/test_cancelWatch.html @@ -39,7 +39,7 @@ SimpleTest.waitForExplicitFinish(); watchID = navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null); // click deny -setTimeout(clickDeny, 50); +setTimeout(clickNotificationButton, 50, kDenyButton); diff --git a/dom/tests/mochitest/geolocation/test_clearWatch.html b/dom/tests/mochitest/geolocation/test_clearWatch.html index d065c24156b..a8d4a2242f3 100644 --- a/dom/tests/mochitest/geolocation/test_clearWatch.html +++ b/dom/tests/mochitest/geolocation/test_clearWatch.html @@ -50,7 +50,7 @@ SimpleTest.waitForExplicitFinish(); watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null); -setTimeout(clickAccept, 10); +setTimeout(clickNotificationButton, 10, kAcceptButton); setTimeout(clearWatch, 50); diff --git a/dom/tests/mochitest/geolocation/test_timeoutWatch.html b/dom/tests/mochitest/geolocation/test_timeoutWatch.html index 7d8f100541e..4b51462f0e5 100644 --- a/dom/tests/mochitest/geolocation/test_timeoutWatch.html +++ b/dom/tests/mochitest/geolocation/test_timeoutWatch.html @@ -56,7 +56,7 @@ navigator.geolocation.watchPosition(successCallback, errorCallback, options); -setTimeout(clickAccept, 0); +setTimeout(clickNotificationButton, 10, kAcceptButton);