|
1 /** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Make sure this is a unique origin or the tests will randomly fail! |
|
7 const testPageURL = "http://bug704464-2.example.com/browser/" + |
|
8 "dom/indexedDB/test/browser_quotaPrompt.html"; |
|
9 const notificationID = "indexedDB-quota-prompt"; |
|
10 |
|
11 function test() |
|
12 { |
|
13 waitForExplicitFinish(); |
|
14 requestLongerTimeout(10); |
|
15 PopupNotifications.transitionsEnabled = false; |
|
16 removePermission(testPageURL, "indexedDB-unlimited"); |
|
17 Services.prefs.setIntPref("dom.indexedDB.warningQuota", 2); |
|
18 executeSoon(test1); |
|
19 } |
|
20 |
|
21 let addMoreTest1Count = 0; |
|
22 |
|
23 function test1() |
|
24 { |
|
25 gBrowser.selectedTab = gBrowser.addTab(); |
|
26 |
|
27 gBrowser.selectedBrowser.addEventListener("load", function () { |
|
28 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
|
29 |
|
30 let seenPopupCount; |
|
31 |
|
32 setFinishedCallback(function(result) { |
|
33 is(result, "ready", "Got 'ready' result"); |
|
34 |
|
35 setFinishedCallback(function(result) { |
|
36 if (!seenPopupCount) { |
|
37 is(result, "complete", "Got 'complete' result"); |
|
38 } |
|
39 else { |
|
40 is(result, "abort QuotaExceededError", "Got 'abort' result"); |
|
41 } |
|
42 |
|
43 if (addMoreTest1Count >= seenPopupCount + 5) { |
|
44 setFinishedCallback(function(result) { |
|
45 is(result, "finished", "Got 'finished' result"); |
|
46 is(getPermission(testPageURL, "indexedDB-unlimited"), |
|
47 Components.interfaces.nsIPermissionManager.DENY_ACTION, |
|
48 "Correct permission set"); |
|
49 gBrowser.removeCurrentTab(); |
|
50 unregisterAllPopupEventHandlers(); |
|
51 addMoreTest1Count = seenPopupCount; |
|
52 PopupNotifications.transitionsEnabled = true; |
|
53 executeSoon(test2); |
|
54 }); |
|
55 executeSoon(function() { dispatchEvent("indexedDB-done"); }); |
|
56 } |
|
57 else { |
|
58 ++addMoreTest1Count; |
|
59 executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); |
|
60 } |
|
61 }); |
|
62 ++addMoreTest1Count; |
|
63 executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); |
|
64 }); |
|
65 |
|
66 registerPopupEventHandler("popupshowing", function () { |
|
67 ok(true, "prompt showing"); |
|
68 seenPopupCount = addMoreTest1Count - 1; |
|
69 }); |
|
70 registerPopupEventHandler("popupshown", function () { |
|
71 ok(true, "prompt shown"); |
|
72 triggerSecondaryCommand(this, 0); |
|
73 }); |
|
74 registerPopupEventHandler("popuphidden", function () { |
|
75 ok(true, "prompt hidden"); |
|
76 }); |
|
77 |
|
78 }, true); |
|
79 |
|
80 info("loading test page: " + testPageURL); |
|
81 content.location = testPageURL + "?v=5"; |
|
82 } |
|
83 |
|
84 function test2() |
|
85 { |
|
86 gBrowser.selectedTab = gBrowser.addTab(); |
|
87 |
|
88 gBrowser.selectedBrowser.addEventListener("load", function () { |
|
89 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
|
90 |
|
91 let seenPopup; |
|
92 let addMoreCount = 0; |
|
93 let lastResult; |
|
94 |
|
95 setFinishedCallback(function(result) { |
|
96 is(result, "ready", "Got 'ready' result"); |
|
97 is(getPermission(testPageURL, "indexedDB-unlimited"), |
|
98 Components.interfaces.nsIPermissionManager.DENY_ACTION, |
|
99 "Correct permission set"); |
|
100 |
|
101 setFinishedCallback(function(result) { |
|
102 info("Got '" + result + "' result"); |
|
103 lastResult = result; |
|
104 ok(!seenPopup, "No popup"); |
|
105 is(getPermission(testPageURL, "indexedDB-unlimited"), |
|
106 Components.interfaces.nsIPermissionManager.DENY_ACTION, |
|
107 "Correct permission set"); |
|
108 |
|
109 if (addMoreCount > addMoreTest1Count + 5) { |
|
110 setFinishedCallback(function(result) { |
|
111 is(result, "finished", "Got 'finished' result"); |
|
112 is(lastResult, "abort QuotaExceededError", "Aborted as expected"); |
|
113 ok(!seenPopup, "No popup"); |
|
114 is(getPermission(testPageURL, "indexedDB-unlimited"), |
|
115 Components.interfaces.nsIPermissionManager.DENY_ACTION, |
|
116 "Correct permission set"); |
|
117 |
|
118 gBrowser.removeCurrentTab(); |
|
119 unregisterAllPopupEventHandlers(); |
|
120 removePermission(testPageURL, "indexedDB"); |
|
121 Services.prefs.clearUserPref("dom.indexedDB.warningQuota"); |
|
122 executeSoon(finish); |
|
123 }); |
|
124 executeSoon(function() { dispatchEvent("indexedDB-done"); }); |
|
125 } |
|
126 else { |
|
127 ++addMoreCount; |
|
128 executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); |
|
129 } |
|
130 }); |
|
131 ++addMoreCount; |
|
132 executeSoon(function() { dispatchEvent("indexedDB-addMore"); }); |
|
133 }); |
|
134 |
|
135 registerPopupEventHandler("popupshowing", function () { |
|
136 ok(false, "Shouldn't show a popup this time"); |
|
137 seenPopup = true; |
|
138 }); |
|
139 registerPopupEventHandler("popupshown", function () { |
|
140 ok(false, "Shouldn't show a popup this time"); |
|
141 }); |
|
142 registerPopupEventHandler("popuphidden", function () { |
|
143 ok(false, "Shouldn't show a popup this time"); |
|
144 }); |
|
145 |
|
146 }, true); |
|
147 |
|
148 info("loading test page: " + testPageURL); |
|
149 content.location = testPageURL + "?v=7"; |
|
150 } |