dom/indexedDB/test/browser_quotaPromptDeny.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/browser_quotaPromptDeny.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     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 +// Make sure this is a unique origin or the tests will randomly fail!
    1.10 +const testPageURL = "http://bug704464-2.example.com/browser/" +
    1.11 +  "dom/indexedDB/test/browser_quotaPrompt.html";
    1.12 +const notificationID = "indexedDB-quota-prompt";
    1.13 +
    1.14 +function test()
    1.15 +{
    1.16 +  waitForExplicitFinish();
    1.17 +  requestLongerTimeout(10);
    1.18 +  PopupNotifications.transitionsEnabled = false;
    1.19 +  removePermission(testPageURL, "indexedDB-unlimited");
    1.20 +  Services.prefs.setIntPref("dom.indexedDB.warningQuota", 2);
    1.21 +  executeSoon(test1);
    1.22 +}
    1.23 +
    1.24 +let addMoreTest1Count = 0;
    1.25 +
    1.26 +function test1()
    1.27 +{
    1.28 +  gBrowser.selectedTab = gBrowser.addTab();
    1.29 +
    1.30 +  gBrowser.selectedBrowser.addEventListener("load", function () {
    1.31 +    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
    1.32 +
    1.33 +    let seenPopupCount;
    1.34 +
    1.35 +    setFinishedCallback(function(result) {
    1.36 +      is(result, "ready", "Got 'ready' result");
    1.37 +
    1.38 +      setFinishedCallback(function(result) {
    1.39 +        if (!seenPopupCount) {
    1.40 +          is(result, "complete", "Got 'complete' result");
    1.41 +        }
    1.42 +        else {
    1.43 +          is(result, "abort QuotaExceededError", "Got 'abort' result");
    1.44 +        }
    1.45 +
    1.46 +        if (addMoreTest1Count >= seenPopupCount + 5) {
    1.47 +          setFinishedCallback(function(result) {
    1.48 +            is(result, "finished", "Got 'finished' result");
    1.49 +            is(getPermission(testPageURL, "indexedDB-unlimited"),
    1.50 +               Components.interfaces.nsIPermissionManager.DENY_ACTION,
    1.51 +               "Correct permission set");
    1.52 +            gBrowser.removeCurrentTab();
    1.53 +            unregisterAllPopupEventHandlers();
    1.54 +            addMoreTest1Count = seenPopupCount;
    1.55 +            PopupNotifications.transitionsEnabled = true;
    1.56 +            executeSoon(test2);
    1.57 +          });
    1.58 +          executeSoon(function() { dispatchEvent("indexedDB-done"); });
    1.59 +        }
    1.60 +        else {
    1.61 +          ++addMoreTest1Count;
    1.62 +          executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
    1.63 +        }
    1.64 +      });
    1.65 +      ++addMoreTest1Count;
    1.66 +      executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
    1.67 +    });
    1.68 +
    1.69 +    registerPopupEventHandler("popupshowing", function () {
    1.70 +      ok(true, "prompt showing");
    1.71 +      seenPopupCount = addMoreTest1Count - 1;
    1.72 +    });
    1.73 +    registerPopupEventHandler("popupshown", function () {
    1.74 +      ok(true, "prompt shown");
    1.75 +      triggerSecondaryCommand(this, 0);
    1.76 +    });
    1.77 +    registerPopupEventHandler("popuphidden", function () {
    1.78 +      ok(true, "prompt hidden");
    1.79 +    });
    1.80 +
    1.81 +  }, true);
    1.82 +
    1.83 +  info("loading test page: " + testPageURL);
    1.84 +  content.location = testPageURL + "?v=5";
    1.85 +}
    1.86 +
    1.87 +function test2()
    1.88 +{
    1.89 +  gBrowser.selectedTab = gBrowser.addTab();
    1.90 +
    1.91 +  gBrowser.selectedBrowser.addEventListener("load", function () {
    1.92 +    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
    1.93 +
    1.94 +    let seenPopup;
    1.95 +    let addMoreCount = 0;
    1.96 +    let lastResult;
    1.97 +
    1.98 +    setFinishedCallback(function(result) {
    1.99 +      is(result, "ready", "Got 'ready' result");
   1.100 +      is(getPermission(testPageURL, "indexedDB-unlimited"),
   1.101 +         Components.interfaces.nsIPermissionManager.DENY_ACTION,
   1.102 +         "Correct permission set");
   1.103 +
   1.104 +      setFinishedCallback(function(result) {
   1.105 +        info("Got '" + result + "' result");
   1.106 +        lastResult = result;
   1.107 +        ok(!seenPopup, "No popup");
   1.108 +        is(getPermission(testPageURL, "indexedDB-unlimited"),
   1.109 +           Components.interfaces.nsIPermissionManager.DENY_ACTION,
   1.110 +           "Correct permission set");
   1.111 +
   1.112 +        if (addMoreCount > addMoreTest1Count + 5) {
   1.113 +          setFinishedCallback(function(result) {
   1.114 +            is(result, "finished", "Got 'finished' result");
   1.115 +            is(lastResult, "abort QuotaExceededError", "Aborted as expected");
   1.116 +            ok(!seenPopup, "No popup");
   1.117 +            is(getPermission(testPageURL, "indexedDB-unlimited"),
   1.118 +               Components.interfaces.nsIPermissionManager.DENY_ACTION,
   1.119 +               "Correct permission set");
   1.120 +
   1.121 +            gBrowser.removeCurrentTab();
   1.122 +            unregisterAllPopupEventHandlers();
   1.123 +            removePermission(testPageURL, "indexedDB");
   1.124 +            Services.prefs.clearUserPref("dom.indexedDB.warningQuota");
   1.125 +            executeSoon(finish);
   1.126 +          });
   1.127 +          executeSoon(function() { dispatchEvent("indexedDB-done"); });
   1.128 +        }
   1.129 +        else {
   1.130 +          ++addMoreCount;
   1.131 +          executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
   1.132 +        }
   1.133 +      });
   1.134 +      ++addMoreCount;
   1.135 +      executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
   1.136 +    });
   1.137 +
   1.138 +    registerPopupEventHandler("popupshowing", function () {
   1.139 +      ok(false, "Shouldn't show a popup this time");
   1.140 +      seenPopup = true;
   1.141 +    });
   1.142 +    registerPopupEventHandler("popupshown", function () {
   1.143 +      ok(false, "Shouldn't show a popup this time");
   1.144 +    });
   1.145 +    registerPopupEventHandler("popuphidden", function () {
   1.146 +      ok(false, "Shouldn't show a popup this time");
   1.147 +    });
   1.148 +
   1.149 +  }, true);
   1.150 +
   1.151 +  info("loading test page: " + testPageURL);
   1.152 +  content.location = testPageURL + "?v=7";
   1.153 +}

mercurial