Bug 1008941 - Add test to verify dismissing the geolocation sharing hanger. r=jdm

This commit is contained in:
Mihaela Velimiroviciu 2014-07-15 10:26:33 +03:00
parent 1945ba246d
commit 7b0c9ddcd3
3 changed files with 92 additions and 0 deletions

View File

@ -5,10 +5,12 @@ support-files =
browser_geolocation_privatebrowsing_page.html
network_geolocation.sjs
page_privatestorageevent.html
position.html
test-console-api.html
test_bug1004814.html
worker_bug1004814.js
[browser_bug1008941_dismissGeolocationHanger.js]
[browser_test__content.js]
[browser_ConsoleAPITests.js]
[browser_ConsoleStorageAPITests.js]

View File

@ -0,0 +1,61 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
const TEST_URI = "http://example.com/" +
"browser/dom/tests/browser/position.html";
add_task(function testDismissHanger() {
info("Check that location is not shared when dismissing the geolocation hanger");
let promisePanelShown = waitForPanelShow();
gBrowser.selectedTab = gBrowser.addTab(TEST_URI);
yield waitForPageLoad(gBrowser.selectedTab);
info("Page was loaded");
yield promisePanelShown;
info("Panel is shown");
// click outside the Geolocation hanger to dismiss it
window.document.getElementById("nav-bar").click();
info("Clicked outside the Geolocation panel to dismiss it");
let result = gBrowser.getBrowserForTab(gBrowser.selectedTab)
.contentDocument.body.innerHTML;
ok(result.contains("location..."), "Location is not shared");
});
add_task(function asyncCleanup() {
// close the tab
gBrowser.removeTab(gBrowser.selectedTab);
info("Cleanup: Closed the tab");
});
function waitForPageLoad(aTab) {
let deferred = Promise.defer();
function onTabLoad(event) {
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
info("Load tab event received");
deferred.resolve();
}
aTab.linkedBrowser.addEventListener("load", onTabLoad, true, true);
return deferred.promise;
}
function waitForPanelShow(aPanel) {
let deferred = Promise.defer();
function onPopupShown(event) {
PopupNotifications.panel.removeEventListener("popupshown", onPopupShown, true);
info("Popup shown event received");
deferred.resolve();
}
PopupNotifications.panel.addEventListener("popupshown", onPopupShown, true, true);
return deferred.promise;
}

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<script type="text/javascript">
var result = null;
function handlePosition(position) {
result.innerHTML = position.coords.latitude + " " + position.coords.longitude;
}
function handleError(error) {
result.innerHTML = error.message;
}
function init() {
result = document.getElementById("result");
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(handlePosition, handleError);
else
result.innerHTML = "not available";
}
</script>
</head>
<body onload="init()">
<p id="result">location...</p>
</body>
</html>