1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/test/browser_quotaPromptDelete.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 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://bug702292.example.com/browser/" + 1.11 + "dom/indexedDB/test/browser_quotaPromptDelete.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 +let haveReset = false; 1.26 +let secondTimeCount = 0; 1.27 + 1.28 +function test1() 1.29 +{ 1.30 + gBrowser.selectedTab = gBrowser.addTab(); 1.31 + 1.32 + gBrowser.selectedBrowser.addEventListener("load", function () { 1.33 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.34 + 1.35 + let seenPopupCount; 1.36 + 1.37 + setFinishedCallback(function(result) { 1.38 + is(result, "ready", "Got 'ready' result"); 1.39 + 1.40 + setFinishedCallback(function(result) { 1.41 + if (result == "abort") { 1.42 + setFinishedCallback(function(result) { 1.43 + is(result, "resetDone", "Got 'resetDone' result"); 1.44 + 1.45 + function secondTimeThroughCallback(result) { 1.46 + is(result, "complete", "Got 'complete' result"); 1.47 + 1.48 + // If we hit the quota on the Nth iteration last time, we should 1.49 + // be able to go N-1 iterations without hitting it after 1.50 + // obliterating the db. 1.51 + if (++secondTimeCount < addMoreTest1Count - 1) { 1.52 + secondTimeThroughAddMore(); 1.53 + } else { 1.54 + setFinishedCallback(function(result) { 1.55 + is(result, "finished", "Got 'finished' result"); 1.56 + is(getPermission(testPageURL, "indexedDB-unlimited"), 1.57 + Components.interfaces.nsIPermissionManager.DENY_ACTION, 1.58 + "Correct permission set"); 1.59 + gBrowser.removeCurrentTab(); 1.60 + unregisterAllPopupEventHandlers(); 1.61 + PopupNotifications.transitionsEnabled = true; 1.62 + executeSoon(finish); 1.63 + }); 1.64 + executeSoon(function() { dispatchEvent("indexedDB-done"); }); 1.65 + } 1.66 + } 1.67 + 1.68 + function secondTimeThroughAddMore() { 1.69 + setFinishedCallback(secondTimeThroughCallback); 1.70 + executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); 1.71 + } 1.72 + 1.73 + haveReset = true; 1.74 + secondTimeThroughAddMore(); 1.75 + }); 1.76 + executeSoon(function() { dispatchEvent("indexedDB-reset"); }); 1.77 + } 1.78 + else { 1.79 + ++addMoreTest1Count; 1.80 + executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); 1.81 + } 1.82 + }); 1.83 + ++addMoreTest1Count; 1.84 + executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); 1.85 + }); 1.86 + 1.87 + registerPopupEventHandler("popupshowing", function () { 1.88 + ok(true, "prompt showing"); 1.89 + seenPopupCount = addMoreTest1Count - 1; 1.90 + }); 1.91 + registerPopupEventHandler("popupshown", function () { 1.92 + ok(true, "prompt shown"); 1.93 + ok(!haveReset, "Shouldn't get here twice!"); 1.94 + triggerSecondaryCommand(this, 0); 1.95 + }); 1.96 + registerPopupEventHandler("popuphidden", function () { 1.97 + ok(true, "prompt hidden"); 1.98 + }); 1.99 + 1.100 + }, true); 1.101 + 1.102 + info("loading test page: " + testPageURL); 1.103 + content.location = testPageURL; 1.104 +}