dom/indexedDB/test/browser_quotaPromptAllow.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/browser_quotaPromptAllow.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     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-1.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 +        is(result, "complete", "Got 'complete' result");
    1.40 +
    1.41 +        if (addMoreTest1Count > seenPopupCount + 5) {
    1.42 +          setFinishedCallback(function(result) {
    1.43 +            is(result, "finished", "Got 'finished' result");
    1.44 +            is(getPermission(testPageURL, "indexedDB-unlimited"),
    1.45 +               Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
    1.46 +               "Correct permission set");
    1.47 +            gBrowser.removeCurrentTab();
    1.48 +            unregisterAllPopupEventHandlers();
    1.49 +            executeSoon(finish);
    1.50 +          });
    1.51 +          executeSoon(function() { dispatchEvent("indexedDB-done"); });
    1.52 +        }
    1.53 +        else {
    1.54 +          ++addMoreTest1Count;
    1.55 +          executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
    1.56 +        }
    1.57 +      });
    1.58 +      ++addMoreTest1Count;
    1.59 +      executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
    1.60 +    });
    1.61 +
    1.62 +    registerPopupEventHandler("popupshowing", function () {
    1.63 +      ok(true, "prompt showing");
    1.64 +      seenPopupCount = addMoreTest1Count;
    1.65 +    });
    1.66 +    registerPopupEventHandler("popupshown", function () {
    1.67 +      ok(true, "prompt shown");
    1.68 +      triggerMainCommand(this);
    1.69 +    });
    1.70 +    registerPopupEventHandler("popuphidden", function () {
    1.71 +      ok(true, "prompt hidden");
    1.72 +    });
    1.73 +
    1.74 +  }, true);
    1.75 +
    1.76 +  info("loading test page: " + testPageURL);
    1.77 +  content.location = testPageURL + "?v=1";
    1.78 +}
    1.79 +
    1.80 +function test2()
    1.81 +{
    1.82 +  gBrowser.selectedTab = gBrowser.addTab();
    1.83 +
    1.84 +  gBrowser.selectedBrowser.addEventListener("load", function () {
    1.85 +    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
    1.86 +
    1.87 +    let seenPopup;
    1.88 +    let addMoreCount = 0;
    1.89 +
    1.90 +    setFinishedCallback(function(result) {
    1.91 +      is(result, "ready", "Got 'ready' result");
    1.92 +      is(getPermission(testPageURL, "indexedDB-unlimited"),
    1.93 +         Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
    1.94 +         "Correct permission set");
    1.95 +
    1.96 +      setFinishedCallback(function(result) {
    1.97 +        is(result, "complete", "Got 'complete' result");
    1.98 +        ok(!seenPopup, "No popup");
    1.99 +        is(getPermission(testPageURL, "indexedDB-unlimited"),
   1.100 +           Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
   1.101 +           "Correct permission set");
   1.102 +
   1.103 +        if (addMoreCount > addMoreTest1Count + 5) {
   1.104 +          setFinishedCallback(function(result) {
   1.105 +            is(result, "finished", "Got 'finished' result");
   1.106 +            ok(!seenPopup, "No popup");
   1.107 +            is(getPermission(testPageURL, "indexedDB-unlimited"),
   1.108 +               Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
   1.109 +               "Correct permission set");
   1.110 +
   1.111 +            gBrowser.removeCurrentTab();
   1.112 +            unregisterAllPopupEventHandlers();
   1.113 +            removePermission(testPageURL, "indexedDB");
   1.114 +            Services.prefs.clearUserPref("dom.indexedDB.warningQuota");
   1.115 +            PopupNotifications.transitionsEnabled = true;
   1.116 +            executeSoon(finish);
   1.117 +          });
   1.118 +          executeSoon(function() { dispatchEvent("indexedDB-done"); });
   1.119 +        }
   1.120 +        else {
   1.121 +          ++addMoreCount;
   1.122 +          executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
   1.123 +        }
   1.124 +      });
   1.125 +      ++addMoreCount;
   1.126 +      executeSoon(function() { dispatchEvent("indexedDB-addMore"); });
   1.127 +    });
   1.128 +
   1.129 +    registerPopupEventHandler("popupshowing", function () {
   1.130 +      ok(false, "Shouldn't show a popup this time");
   1.131 +      seenPopup = true;
   1.132 +    });
   1.133 +    registerPopupEventHandler("popupshown", function () {
   1.134 +      ok(false, "Shouldn't show a popup this time");
   1.135 +    });
   1.136 +    registerPopupEventHandler("popuphidden", function () {
   1.137 +      ok(false, "Shouldn't show a popup this time");
   1.138 +    });
   1.139 +
   1.140 +  }, true);
   1.141 +
   1.142 +  info("loading test page: " + testPageURL);
   1.143 +  content.location = testPageURL + "?v=3";
   1.144 +}

mercurial