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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_offlineQuotaNotification.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +// Test offline quota warnings - must be run as a mochitest-browser test or
    1.10 +// else the test runner gets in the way of notifications due to bug 857897.
    1.11 +
    1.12 +const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/offlineQuotaNotification.html";
    1.13 +
    1.14 +registerCleanupFunction(function() {
    1.15 +  // Clean up after ourself
    1.16 +  let uri = Services.io.newURI(URL, null, null);
    1.17 +  var principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
    1.18 +  Services.perms.removeFromPrincipal(principal, "offline-app");
    1.19 +  Services.prefs.clearUserPref("offline-apps.quota.warn");
    1.20 +  Services.prefs.clearUserPref("offline-apps.allow_by_default");
    1.21 +});
    1.22 +
    1.23 +// Check that the "preferences" UI is opened and showing which websites have
    1.24 +// offline storage permissions - currently this is the "network" tab in the
    1.25 +// "advanced" pane.
    1.26 +function checkPreferences(prefsWin) {
    1.27 +  // We expect a 'paneload' event for the 'advanced' pane, then
    1.28 +  // a 'select' event on the 'network' tab inside that pane.
    1.29 +  prefsWin.addEventListener("paneload", function paneload(evt) {
    1.30 +    prefsWin.removeEventListener("paneload", paneload);
    1.31 +    is(evt.target.id, "paneAdvanced", "advanced pane loaded");
    1.32 +    let tabPanels = evt.target.getElementsByTagName("tabpanels")[0];
    1.33 +    tabPanels.addEventListener("select", function tabselect() {
    1.34 +      tabPanels.removeEventListener("select", tabselect);
    1.35 +      is(tabPanels.selectedPanel.id, "networkPanel", "networkPanel is selected");
    1.36 +      // all good, we are done.
    1.37 +      prefsWin.close();
    1.38 +      finish();
    1.39 +    });
    1.40 +  });
    1.41 +}
    1.42 +
    1.43 +function test() {
    1.44 +  waitForExplicitFinish();
    1.45 +  gBrowser.selectedBrowser.addEventListener("load", function onload() {
    1.46 +    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    1.47 +    gBrowser.selectedBrowser.contentWindow.applicationCache.oncached = function() {
    1.48 +      executeSoon(function() {
    1.49 +        // We got cached - now we should have provoked the quota warning.
    1.50 +        let notification = PopupNotifications.getNotification('offline-app-usage');
    1.51 +        ok(notification, "have offline-app-usage notification");
    1.52 +        // select the default action - this should cause the preferences
    1.53 +        // window to open - which we track either via a window watcher (for
    1.54 +        // the window-based prefs) or via an "Initialized" event (for
    1.55 +        // in-content prefs.)
    1.56 +        if (Services.prefs.getBoolPref("browser.preferences.inContent")) {
    1.57 +          // Bug 881576 - ensure this works with inContent prefs.
    1.58 +          todo(false, "Bug 881576 - this test needs to be updated for inContent prefs");
    1.59 +        } else {
    1.60 +          Services.ww.registerNotification(function wwobserver(aSubject, aTopic, aData) {
    1.61 +            if (aTopic != "domwindowopened")
    1.62 +              return;
    1.63 +            Services.ww.unregisterNotification(wwobserver);
    1.64 +            checkPreferences(aSubject);
    1.65 +          });
    1.66 +          PopupNotifications.panel.firstElementChild.button.click();
    1.67 +        }
    1.68 +      });
    1.69 +    };
    1.70 +    Services.prefs.setIntPref("offline-apps.quota.warn", 1);
    1.71 +
    1.72 +    // Click the notification panel's "Allow" button.  This should kick
    1.73 +    // off updates which will call our oncached handler above.
    1.74 +    PopupNotifications.panel.firstElementChild.button.click();
    1.75 +  }, true);
    1.76 +
    1.77 +  Services.prefs.setBoolPref("offline-apps.allow_by_default", false);
    1.78 +  gBrowser.contentWindow.location = URL;
    1.79 +}

mercurial