browser/base/content/test/general/browser_offlineQuotaNotification.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial