michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Test offline quota warnings - must be run as a mochitest-browser test or michael@0: // else the test runner gets in the way of notifications due to bug 857897. michael@0: michael@0: const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/offlineQuotaNotification.html"; michael@0: michael@0: registerCleanupFunction(function() { michael@0: // Clean up after ourself michael@0: let uri = Services.io.newURI(URL, null, null); michael@0: var principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri); michael@0: Services.perms.removeFromPrincipal(principal, "offline-app"); michael@0: Services.prefs.clearUserPref("offline-apps.quota.warn"); michael@0: Services.prefs.clearUserPref("offline-apps.allow_by_default"); michael@0: }); michael@0: michael@0: // Check that the "preferences" UI is opened and showing which websites have michael@0: // offline storage permissions - currently this is the "network" tab in the michael@0: // "advanced" pane. michael@0: function checkPreferences(prefsWin) { michael@0: // We expect a 'paneload' event for the 'advanced' pane, then michael@0: // a 'select' event on the 'network' tab inside that pane. michael@0: prefsWin.addEventListener("paneload", function paneload(evt) { michael@0: prefsWin.removeEventListener("paneload", paneload); michael@0: is(evt.target.id, "paneAdvanced", "advanced pane loaded"); michael@0: let tabPanels = evt.target.getElementsByTagName("tabpanels")[0]; michael@0: tabPanels.addEventListener("select", function tabselect() { michael@0: tabPanels.removeEventListener("select", tabselect); michael@0: is(tabPanels.selectedPanel.id, "networkPanel", "networkPanel is selected"); michael@0: // all good, we are done. michael@0: prefsWin.close(); michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true); michael@0: gBrowser.selectedBrowser.contentWindow.applicationCache.oncached = function() { michael@0: executeSoon(function() { michael@0: // We got cached - now we should have provoked the quota warning. michael@0: let notification = PopupNotifications.getNotification('offline-app-usage'); michael@0: ok(notification, "have offline-app-usage notification"); michael@0: // select the default action - this should cause the preferences michael@0: // window to open - which we track either via a window watcher (for michael@0: // the window-based prefs) or via an "Initialized" event (for michael@0: // in-content prefs.) michael@0: if (Services.prefs.getBoolPref("browser.preferences.inContent")) { michael@0: // Bug 881576 - ensure this works with inContent prefs. michael@0: todo(false, "Bug 881576 - this test needs to be updated for inContent prefs"); michael@0: } else { michael@0: Services.ww.registerNotification(function wwobserver(aSubject, aTopic, aData) { michael@0: if (aTopic != "domwindowopened") michael@0: return; michael@0: Services.ww.unregisterNotification(wwobserver); michael@0: checkPreferences(aSubject); michael@0: }); michael@0: PopupNotifications.panel.firstElementChild.button.click(); michael@0: } michael@0: }); michael@0: }; michael@0: Services.prefs.setIntPref("offline-apps.quota.warn", 1); michael@0: michael@0: // Click the notification panel's "Allow" button. This should kick michael@0: // off updates which will call our oncached handler above. michael@0: PopupNotifications.panel.firstElementChild.button.click(); michael@0: }, true); michael@0: michael@0: Services.prefs.setBoolPref("offline-apps.allow_by_default", false); michael@0: gBrowser.contentWindow.location = URL; michael@0: }