Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 // Test offline quota warnings - must be run as a mochitest-browser test or
7 // else the test runner gets in the way of notifications due to bug 857897.
9 const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/offlineQuotaNotification.html";
11 registerCleanupFunction(function() {
12 // Clean up after ourself
13 let uri = Services.io.newURI(URL, null, null);
14 var principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
15 Services.perms.removeFromPrincipal(principal, "offline-app");
16 Services.prefs.clearUserPref("offline-apps.quota.warn");
17 Services.prefs.clearUserPref("offline-apps.allow_by_default");
18 });
20 // Check that the "preferences" UI is opened and showing which websites have
21 // offline storage permissions - currently this is the "network" tab in the
22 // "advanced" pane.
23 function checkPreferences(prefsWin) {
24 // We expect a 'paneload' event for the 'advanced' pane, then
25 // a 'select' event on the 'network' tab inside that pane.
26 prefsWin.addEventListener("paneload", function paneload(evt) {
27 prefsWin.removeEventListener("paneload", paneload);
28 is(evt.target.id, "paneAdvanced", "advanced pane loaded");
29 let tabPanels = evt.target.getElementsByTagName("tabpanels")[0];
30 tabPanels.addEventListener("select", function tabselect() {
31 tabPanels.removeEventListener("select", tabselect);
32 is(tabPanels.selectedPanel.id, "networkPanel", "networkPanel is selected");
33 // all good, we are done.
34 prefsWin.close();
35 finish();
36 });
37 });
38 }
40 function test() {
41 waitForExplicitFinish();
42 gBrowser.selectedBrowser.addEventListener("load", function onload() {
43 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
44 gBrowser.selectedBrowser.contentWindow.applicationCache.oncached = function() {
45 executeSoon(function() {
46 // We got cached - now we should have provoked the quota warning.
47 let notification = PopupNotifications.getNotification('offline-app-usage');
48 ok(notification, "have offline-app-usage notification");
49 // select the default action - this should cause the preferences
50 // window to open - which we track either via a window watcher (for
51 // the window-based prefs) or via an "Initialized" event (for
52 // in-content prefs.)
53 if (Services.prefs.getBoolPref("browser.preferences.inContent")) {
54 // Bug 881576 - ensure this works with inContent prefs.
55 todo(false, "Bug 881576 - this test needs to be updated for inContent prefs");
56 } else {
57 Services.ww.registerNotification(function wwobserver(aSubject, aTopic, aData) {
58 if (aTopic != "domwindowopened")
59 return;
60 Services.ww.unregisterNotification(wwobserver);
61 checkPreferences(aSubject);
62 });
63 PopupNotifications.panel.firstElementChild.button.click();
64 }
65 });
66 };
67 Services.prefs.setIntPref("offline-apps.quota.warn", 1);
69 // Click the notification panel's "Allow" button. This should kick
70 // off updates which will call our oncached handler above.
71 PopupNotifications.panel.firstElementChild.button.click();
72 }, true);
74 Services.prefs.setBoolPref("offline-apps.allow_by_default", false);
75 gBrowser.contentWindow.location = URL;
76 }