Attachment #8854808: Bug 1286717 - Part 2: Add mochitests for persist/persisted functions (v3) for bug #1286717

View | Details | Raw Unified | Return to bug 1286717
Collapse All | Expand All

(-)a/dom/quota/moz.build (+4 lines)
Line     Link Here 
 Lines 2-17    Link Here 
2
# vim: set filetype=python:
2
# vim: set filetype=python:
3
# This Source Code Form is subject to the terms of the Mozilla Public
3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
7
with Files("**"):
7
with Files("**"):
8
    BUG_COMPONENT = ("Core", "DOM: Quota Manager")
8
    BUG_COMPONENT = ("Core", "DOM: Quota Manager")
9
9
10
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
11
12
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
13
10
XPCSHELL_TESTS_MANIFESTS += [
14
XPCSHELL_TESTS_MANIFESTS += [
11
    'test/unit/xpcshell.ini'
15
    'test/unit/xpcshell.ini'
12
]
16
]
13
17
14
XPIDL_SOURCES += [
18
XPIDL_SOURCES += [
15
    'nsIQuotaCallbacks.idl',
19
    'nsIQuotaCallbacks.idl',
16
    'nsIQuotaManagerService.idl',
20
    'nsIQuotaManagerService.idl',
17
    'nsIQuotaRequests.idl',
21
    'nsIQuotaRequests.idl',
(-)a/dom/quota/test/browser.ini (+9 lines)
Line     Link Here 
Line 0    Link Here 
1
[DEFAULT]
2
skip-if = (buildapp != "browser")
3
support-files =
4
  head.js
5
  browserHelpers.js
6
  browser_permissionsPrompt.html
7
8
[browser_permissionsPromptAllow.js]
9
[browser_permissionsPromptDeny.js]
(-)a/dom/quota/test/browserHelpers.js (+46 lines)
Line     Link Here 
Line 0    Link Here 
1
/**
2
 * Any copyright is dedicated to the Public Domain.
3
 * http://creativecommons.org/publicdomain/zero/1.0/
4
 */
5
6
var testGenerator = testSteps();
7
8
var testResult;
9
var testException;
10
11
function clearAllDatabases(callback)
12
{
13
  let qms = SpecialPowers.Services.qms;
14
  let principal = SpecialPowers.wrap(document).nodePrincipal;
15
  let request = qms.clearStoragesForPrincipal(principal);
16
  let cb = SpecialPowers.wrapCallback(callback);
17
  request.callback = cb;
18
}
19
20
function runTest()
21
{
22
  testGenerator.next();
23
}
24
25
function continueToNextStep()
26
{
27
  SimpleTest.executeSoon(function() {
28
    testGenerator.next();
29
  });
30
}
31
32
function finishTestNow()
33
{
34
  if (testGenerator) {
35
    testGenerator.return();
36
    testGenerator = undefined;
37
  }
38
}
39
40
function finishTest()
41
{
42
  setTimeout(finishTestNow, 0);
43
  setTimeout(() => {
44
    window.parent.postMessage(testResult, "*");
45
  }, 0);
46
}
(-)a/dom/quota/test/browser_permissionsPrompt.html (+48 lines)
Line     Link Here 
Line 0    Link Here 
1
<!--
2
  Any copyright is dedicated to the Public Domain.
3
  http://creativecommons.org/publicdomain/zero/1.0/
4
-->
5
<html>
6
  <head>
7
    <meta charset=UTF-8>
8
    <title>Persistent-Storage Permission Prompt Test</title>
9
    <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10
11
    <script type="text/javascript;version=1.7">
12
      function* testSteps()
13
      {
14
        SpecialPowers.pushPrefEnv({
15
          "set": [["dom.storageManager.enabled", true],
16
                  ["dom.storageManager.prompt.testing", false],
17
                  ["dom.storageManager.prompt.testing.allow", false]]
18
        }, continueToNextStep);
19
        yield undefined;
20
21
        clearAllDatabases(continueToNextStep);
22
        yield undefined;
23
24
        navigator.storage.persist().then(result => {
25
          testGenerator.next(result);
26
        });
27
        testResult = yield undefined;
28
29
        info("Persist() result: " + testResult);
30
31
        navigator.storage.persisted().then(result => {
32
          testGenerator.next(result);
33
        });
34
        let persistedResult = yield undefined;
35
36
        info("Persisted() result: " + persistedResult);
37
38
        is(testResult, persistedResult, "Persist/persisted results are consistent");
39
40
        finishTest();
41
      }
42
    </script>
43
44
    <script type="text/javascript;version=1.7" src="browserHelpers.js"></script>
45
  </head>
46
47
  <body onload="runTest();" onunload="finishTestNow();"></body>
48
</html>
(-)a/dom/quota/test/browser_permissionsPromptAllow.js (+102 lines)
Line     Link Here 
Line 0    Link Here 
1
/**
2
 * Any copyright is dedicated to the Public Domain.
3
 * http://creativecommons.org/publicdomain/zero/1.0/
4
 */
5
6
const testPageURL =
7
  "https://example.com/browser/dom/quota/test/browser_permissionsPrompt.html";
8
9
add_task(function* testPermissionAllow() {
10
  info("Creating tab");
11
  gBrowser.selectedTab = gBrowser.addTab();
12
13
  info("Loading test page: " + testPageURL);
14
  gBrowser.selectedBrowser.loadURI(testPageURL);
15
  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
16
17
  registerPopupEventHandler("popupshowing", function () {
18
    ok(true, "prompt showing");
19
  });
20
  registerPopupEventHandler("popupshown", function () {
21
    ok(true, "prompt shown");
22
    triggerMainCommand(this);
23
  });
24
  registerPopupEventHandler("popuphidden", function () {
25
    ok(true, "prompt hidden");
26
  });
27
28
  yield promiseMessage(true, gBrowser);
29
30
  is(getPermission(testPageURL, "persistent-storage"),
31
     Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
32
     "Correct permission set");
33
  gBrowser.removeCurrentTab();
34
35
  // Keep persistent-storage permission for the next test.
36
  unregisterAllPopupEventHandlers();
37
});
38
39
add_task(function* testPermissionAllowInPrivateWindow() {
40
  info("Creating private window");
41
  let win = yield BrowserTestUtils.openNewBrowserWindow({ private : true });
42
43
  info("Creating private tab");
44
  win.gBrowser.selectedTab = win.gBrowser.addTab();
45
46
  info("Loading test page: " + testPageURL);
47
  win.gBrowser.selectedBrowser.loadURI(testPageURL);
48
  yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
49
50
  // PermissionManager is not supposed to have any knowledge of private browsing,
51
  // Prompt shall not be displayed.
52
  registerPopupEventHandler("popupshowing", function () {
53
    ok(false, "Shouldn't show a popup this time");
54
  });
55
  registerPopupEventHandler("popupshown", function () {
56
    ok(false, "Shouldn't show a popup this time");
57
  });
58
  registerPopupEventHandler("popuphidden", function () {
59
    ok(false, "Shouldn't show a popup this time");
60
  });
61
62
  yield promiseMessage(true, win.gBrowser);
63
64
  is(getPermission(testPageURL, "persistent-storage"),
65
     Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
66
     "Correct permission set");
67
68
  unregisterAllPopupEventHandlers();
69
  removePermission(testPageURL, "persistent-storage");
70
  win.gBrowser.removeCurrentTab();
71
  win.close();
72
});
73
74
add_task(function* testPermissionAllow() {
75
  info("Creating tab");
76
  gBrowser.selectedTab = gBrowser.addTab();
77
78
  info("Loading test page: " + testPageURL);
79
  gBrowser.selectedBrowser.loadURI(testPageURL);
80
  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
81
82
  registerPopupEventHandler("popupshowing", function () {
83
    ok(true, "prompt showing");
84
  });
85
  registerPopupEventHandler("popupshown", function () {
86
    ok(true, "prompt shown");
87
    triggerMainCommand(this);
88
  });
89
  registerPopupEventHandler("popuphidden", function () {
90
    ok(true, "prompt hidden");
91
  });
92
93
  yield promiseMessage(true, gBrowser);
94
95
  is(getPermission(testPageURL, "persistent-storage"),
96
     Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
97
     "Correct permission set");
98
99
  gBrowser.removeCurrentTab();
100
  unregisterAllPopupEventHandlers();
101
  removePermission(testPageURL, "persistent-storage");
102
});
(-)a/dom/quota/test/browser_permissionsPromptDeny.js (+97 lines)
Line     Link Here 
Line 0    Link Here 
1
/**
2
 * Any copyright is dedicated to the Public Domain.
3
 * http://creativecommons.org/publicdomain/zero/1.0/
4
 */
5
6
const testPageURL =
7
  "https://example.com/browser/dom/quota/test/browser_permissionsPrompt.html";
8
9
add_task(function* testPermissionDenied() {
10
  info("Creating tab");
11
  gBrowser.selectedTab = gBrowser.addTab();
12
13
  info("Loading test page: " + testPageURL);
14
  gBrowser.selectedBrowser.loadURI(testPageURL);
15
  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
16
17
  registerPopupEventHandler("popupshowing", function () {
18
    ok(true, "prompt showing");
19
  });
20
  registerPopupEventHandler("popupshown", function () {
21
    ok(true, "prompt shown");
22
    triggerSecondaryCommand(this);
23
  });
24
  registerPopupEventHandler("popuphidden", function () {
25
    ok(true, "prompt hidden");
26
  });
27
28
  yield promiseMessage(false, gBrowser);
29
30
  is(getPermission(testPageURL, "persistent-storage"),
31
     Components.interfaces.nsIPermissionManager.DENY_ACTION,
32
     "Correct permission set");
33
  gBrowser.removeCurrentTab();
34
  unregisterAllPopupEventHandlers();
35
});
36
37
add_task(function* testPermissionDeniedInPrivateWindow() {
38
  info("Creating private window");
39
  let win = yield BrowserTestUtils.openNewBrowserWindow({ private : true });
40
41
  info("Creating private tab");
42
  win.gBrowser.selectedTab = win.gBrowser.addTab();
43
44
  info("Loading test page: " + testPageURL);
45
  win.gBrowser.selectedBrowser.loadURI(testPageURL);
46
  yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
47
48
  // PermissionManager is not supposed to have any knowledge of private browsing,
49
  // Prompt shall not be displayed.
50
  registerPopupEventHandler("popupshowing", function () {
51
    ok(false, "Shouldn't show a popup this time");
52
  });
53
  registerPopupEventHandler("popupshown", function () {
54
    ok(false, "Shouldn't show a popup this time");
55
  });
56
  registerPopupEventHandler("popuphidden", function () {
57
    ok(false, "Shouldn't show a popup this time");
58
  });
59
  yield promiseMessage(false, win.gBrowser);
60
61
  is(getPermission(testPageURL, "persistent-storage"),
62
     Components.interfaces.nsIPermissionManager.DENY_ACTION,
63
     "Correct permission set");
64
  unregisterAllPopupEventHandlers();
65
  win.gBrowser.removeCurrentTab();
66
  win.close();
67
});
68
69
add_task(function* testPermissionDeniedDismiss() {
70
  info("Creating tab");
71
  gBrowser.selectedTab = gBrowser.addTab();
72
73
  info("Loading test page: " + testPageURL);
74
  gBrowser.selectedBrowser.loadURI(testPageURL);
75
  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
76
77
  registerPopupEventHandler("popupshowing", function () {
78
    ok(true, "prompt showing");
79
  });
80
  registerPopupEventHandler("popupshown", function () {
81
    ok(true, "prompt shown");
82
    // Dismiss permission prompt.
83
    dismissNotification(this);
84
  });
85
  registerPopupEventHandler("popuphidden", function () {
86
    ok(true, "prompt hidden");
87
  });
88
89
  yield promiseMessage(false, gBrowser);
90
91
  is(getPermission(testPageURL, "persistent-storage"),
92
     Components.interfaces.nsIPermissionManager.DENY_ACTION,
93
     "Correct permission set");
94
  gBrowser.removeCurrentTab();
95
  unregisterAllPopupEventHandlers();
96
  removePermission(testPageURL, "persistent-storage");
97
});
(-)a/dom/quota/test/head.js (+126 lines)
Line     Link Here 
Line 0    Link Here 
1
/**
2
 * Any copyright is dedicated to the Public Domain.
3
 * http://creativecommons.org/publicdomain/zero/1.0/
4
 */
5
6
var gActiveListeners = {};
7
8
function registerPopupEventHandler(eventName, callback)
9
{
10
  gActiveListeners[eventName] = function (event) {
11
    if (event.target != PopupNotifications.panel)
12
      return;
13
    PopupNotifications.panel.removeEventListener(eventName,
14
                                                 gActiveListeners[eventName]);
15
    delete gActiveListeners[eventName];
16
17
    callback.call(PopupNotifications.panel);
18
  }
19
  PopupNotifications.panel.addEventListener(eventName,
20
                                            gActiveListeners[eventName]);
21
}
22
23
function unregisterPopupEventHandler(eventName)
24
{
25
  PopupNotifications.panel.removeEventListener(eventName,
26
                                               gActiveListeners[eventName]);
27
  delete gActiveListeners[eventName];
28
}
29
30
function unregisterAllPopupEventHandlers()
31
{
32
  for (let eventName in gActiveListeners) {
33
    PopupNotifications.panel.removeEventListener(eventName,
34
                                                 gActiveListeners[eventName]);
35
  }
36
  gActiveListeners = {};
37
}
38
39
function triggerMainCommand(popup)
40
{
41
  info("triggering main command");
42
  let notifications = popup.childNodes;
43
  ok(notifications.length > 0, "at least one notification displayed");
44
  let notification = notifications[0];
45
  info("triggering command: " + notification.getAttribute("buttonlabel"));
46
47
  EventUtils.synthesizeMouseAtCenter(notification.button, {});
48
}
49
50
function triggerSecondaryCommand(popup)
51
{
52
  info("triggering secondary command");
53
  let notifications = popup.childNodes;
54
  ok(notifications.length > 0, "at least one notification displayed");
55
  let notification = notifications[0];
56
  EventUtils.synthesizeMouseAtCenter(notification.secondaryButton, {});
57
}
58
59
function dismissNotification(popup)
60
{
61
  info("dismissing notification");
62
  executeSoon(function () {
63
    EventUtils.synthesizeKey("VK_ESCAPE", {});
64
  });
65
}
66
67
function setPermission(url, permission)
68
{
69
  const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
70
71
  let uri = Components.classes["@mozilla.org/network/io-service;1"]
72
                      .getService(Components.interfaces.nsIIOService)
73
                      .newURI(url);
74
  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
75
                      .getService(Ci.nsIScriptSecurityManager);
76
  let principal = ssm.createCodebasePrincipal(uri, {});
77
78
  Components.classes["@mozilla.org/permissionmanager;1"]
79
            .getService(nsIPermissionManager)
80
            .addFromPrincipal(principal, permission,
81
                              nsIPermissionManager.ALLOW_ACTION);
82
}
83
84
function removePermission(url, permission)
85
{
86
  let uri = Components.classes["@mozilla.org/network/io-service;1"]
87
                      .getService(Components.interfaces.nsIIOService)
88
                      .newURI(url);
89
  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
90
                      .getService(Ci.nsIScriptSecurityManager);
91
  let principal = ssm.createCodebasePrincipal(uri, {});
92
93
  Components.classes["@mozilla.org/permissionmanager;1"]
94
            .getService(Components.interfaces.nsIPermissionManager)
95
            .removeFromPrincipal(principal, permission);
96
}
97
98
function getPermission(url, permission)
99
{
100
  let uri = Components.classes["@mozilla.org/network/io-service;1"]
101
                      .getService(Components.interfaces.nsIIOService)
102
                      .newURI(url);
103
  let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
104
                      .getService(Ci.nsIScriptSecurityManager);
105
  let principal = ssm.createCodebasePrincipal(uri, {});
106
107
  return Components.classes["@mozilla.org/permissionmanager;1"]
108
                   .getService(Components.interfaces.nsIPermissionManager)
109
                   .testPermissionFromPrincipal(principal, permission);
110
}
111
112
function promiseMessage(aMessage, browser)
113
{
114
  return ContentTask.spawn(browser.selectedBrowser, aMessage, function* (aMessage) {
115
    yield new Promise((resolve, reject) => {
116
      content.addEventListener("message", function messageListener(event) {
117
        content.removeEventListener("message", messageListener);
118
        is(event.data, aMessage, "received " + aMessage);
119
        if (event.data == aMessage)
120
          resolve();
121
        else
122
          reject();
123
      });
124
    });
125
  });
126
}
(-)a/dom/quota/test/helpers.js (+289 lines)
Line     Link Here 
Line 0    Link Here 
1
/**
2
 * Any copyright is dedicated to the Public Domain.
3
 * http://creativecommons.org/publicdomain/zero/1.0/
4
 */
5
6
var testGenerator = testSteps();
7
8
function clearAllDatabases(callback)
9
{
10
  let qms = SpecialPowers.Services.qms;
11
  let principal = SpecialPowers.wrap(document).nodePrincipal;
12
  let request = qms.clearStoragesForPrincipal(principal);
13
  let cb = SpecialPowers.wrapCallback(callback);
14
  request.callback = cb;
15
}
16
17
var testHarnessGenerator = testHarnessSteps();
18
testHarnessGenerator.next();
19
20
function testHarnessSteps()
21
{
22
  function nextTestHarnessStep(val)
23
  {
24
    testHarnessGenerator.next(val);
25
  }
26
27
  let testScriptPath;
28
  let testScriptFilename;
29
30
  let scripts = document.getElementsByTagName("script");
31
  for (let i = 0; i < scripts.length; i++) {
32
    let src = scripts[i].src;
33
    let match = src.match(/quota\/test\/unit\/(test_[^\/]+\.js)$/);
34
    if (match && match.length == 2) {
35
      testScriptPath = src;
36
      testScriptFilename = match[1];
37
      break;
38
    }
39
  }
40
41
  yield undefined;
42
43
  info("Clearing old databases");
44
45
  clearAllDatabases(nextTestHarnessStep);
46
  yield undefined;
47
48
  info("Running" +
49
       (testScriptFilename ? " '" + testScriptFilename + "'" : ""));
50
51
  if (testScriptFilename && !window.disableWorkerTest) {
52
    info("Running test in a worker");
53
54
    let workerScriptBlob =
55
      new Blob([ "(" + workerScript.toString() + ")();" ],
56
               { type: "text/javascript;version=1.7" });
57
    let workerScriptURL = URL.createObjectURL(workerScriptBlob);
58
59
    let worker = new Worker(workerScriptURL);
60
61
    worker.onerror = function(event) {
62
      ok(false, "Worker had an error: " + event.message);
63
      worker.terminate();
64
      nextTestHarnessStep();
65
    };
66
67
    worker.onmessage = function(event) {
68
      let message = event.data;
69
      switch (message.op) {
70
        case "ok":
71
          ok(message.condition, message.name, message.diag);
72
          break;
73
74
        case "todo":
75
          todo(message.condition, message.name, message.diag);
76
          break;
77
78
        case "info":
79
          info(message.msg);
80
          break;
81
82
        case "ready":
83
          worker.postMessage({ op: "load", files: [ testScriptPath ] });
84
          break;
85
86
        case "loaded":
87
          worker.postMessage({ op: "start" });
88
          break;
89
90
        case "done":
91
          ok(true, "Worker finished");
92
          nextTestHarnessStep();
93
          break;
94
95
        case "clearAllDatabases":
96
          clearAllDatabases(function(){
97
            worker.postMessage({ op: "clearAllDatabasesDone" });
98
          });
99
          break;
100
101
        default:
102
          ok(false,
103
             "Received a bad message from worker: " + JSON.stringify(message));
104
          nextTestHarnessStep();
105
      }
106
    };
107
108
    URL.revokeObjectURL(workerScriptURL);
109
110
    yield undefined;
111
112
    worker.terminate();
113
    worker = null;
114
115
    clearAllDatabases(nextTestHarnessStep);
116
    yield undefined;
117
  } else if (testScriptFilename) {
118
    todo(false,
119
         "Skipping test in a worker because it is explicitly disabled: " +
120
         disableWorkerTest);
121
  } else {
122
    todo(false,
123
         "Skipping test in a worker because it's not structured properly");
124
  }
125
126
  info("Running test in main thread");
127
128
  // Now run the test script in the main thread.
129
  testGenerator.next();
130
131
  yield undefined;
132
}
133
134
if (!window.runTest) {
135
  window.runTest = function()
136
  {
137
    SimpleTest.waitForExplicitFinish();
138
    testHarnessGenerator.next();
139
  }
140
}
141
142
function finishTest()
143
{
144
  SimpleTest.executeSoon(function() {
145
    clearAllDatabases(function() { SimpleTest.finish(); });
146
  });
147
}
148
149
function grabArgAndContinueHandler(arg)
150
{
151
  testGenerator.next(arg);
152
}
153
154
function continueToNextStep()
155
{
156
  SimpleTest.executeSoon(function() {
157
    testGenerator.next();
158
  });
159
}
160
161
function continueToNextStepSync()
162
{
163
  testGenerator.next();
164
}
165
166
function workerScript()
167
{
168
  "use strict";
169
170
  self.repr = function(_thing_) {
171
    if (typeof(_thing_) == "undefined") {
172
      return "undefined";
173
    }
174
175
    let str;
176
177
    try {
178
      str = _thing_ + "";
179
    } catch (e) {
180
      return "[" + typeof(_thing_) + "]";
181
    }
182
183
    if (typeof(_thing_) == "function") {
184
      str = str.replace(/^\s+/, "");
185
      let idx = str.indexOf("{");
186
      if (idx != -1) {
187
        str = str.substr(0, idx) + "{...}";
188
      }
189
    }
190
191
    return str;
192
  };
193
194
  self.ok = function(_condition_, _name_, _diag_) {
195
    self.postMessage({ op: "ok",
196
                       condition: !!_condition_,
197
                       name: _name_,
198
                       diag: _diag_ });
199
  };
200
201
  self.is = function(_a_, _b_, _name_) {
202
    let pass = (_a_ == _b_);
203
    let diag = pass ? "" : "got " + repr(_a_) + ", expected " + repr(_b_);
204
    ok(pass, _name_, diag);
205
  };
206
207
  self.isnot = function(_a_, _b_, _name_) {
208
    let pass = (_a_ != _b_);
209
    let diag = pass ? "" : "didn't expect " + repr(_a_) + ", but got it";
210
    ok(pass, _name_, diag);
211
  };
212
213
  self.todo = function(_condition_, _name_, _diag_) {
214
    self.postMessage({ op: "todo",
215
                       condition: !!_condition_,
216
                       name: _name_,
217
                       diag: _diag_ });
218
  };
219
220
  self.info = function(_msg_) {
221
    self.postMessage({ op: "info", msg: _msg_ });
222
  };
223
224
  self.executeSoon = function(_fun_) {
225
    var channel = new MessageChannel();
226
    channel.port1.postMessage("");
227
    channel.port2.onmessage = function(event) { _fun_(); };
228
  };
229
230
  self.finishTest = function() {
231
    self.postMessage({ op: "done" });
232
  };
233
234
  self.continueToNextStep = function() {
235
    executeSoon(function() {
236
      testGenerator.next();
237
    });
238
  };
239
240
  self.continueToNextStepSync = function() {
241
    testGenerator.next();
242
  };
243
244
  self._clearAllDatabasesCallback = undefined;
245
  self.clearAllDatabases = function(_callback_) {
246
    self._clearAllDatabasesCallback = _callback_;
247
    self.postMessage({ op: "clearAllDatabases" });
248
  }
249
250
  self.onerror = function(_message_, _file_, _line_) {
251
    ok(false,
252
       "Worker: uncaught exception [" + _file_ + ":" + _line_ + "]: '" +
253
         _message_ + "'");
254
    self.finishTest();
255
    self.close();
256
    return true;
257
  };
258
259
  self.onmessage = function(_event_) {
260
    let message = _event_.data;
261
    switch (message.op) {
262
      case "load":
263
        info("Worker: loading " + JSON.stringify(message.files));
264
        self.importScripts(message.files);
265
        self.postMessage({ op: "loaded" });
266
        break;
267
268
      case "start":
269
        executeSoon(function() {
270
          info("Worker: starting tests");
271
          testGenerator.next();
272
        });
273
        break;
274
275
      case "clearAllDatabasesDone":
276
        info("Worker: all databases are cleared");
277
        if (self._clearAllDatabasesCallback) {
278
          self._clearAllDatabasesCallback();
279
        }
280
        break;
281
282
      default:
283
        throw new Error("Received a bad message from parent: " +
284
                        JSON.stringify(message));
285
    }
286
  };
287
288
  self.postMessage({ op: "ready" });
289
}
(-)a/dom/quota/test/mochitest.ini (+17 lines)
Line     Link Here 
Line 0    Link Here 
1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5
[DEFAULT]
6
support-files =
7
  helpers.js
8
  unit/test_storage_manager_persist_allow.js
9
  unit/test_storage_manager_persist_deny.js
10
  unit/test_storage_manager_persisted.js
11
12
[test_storage_manager_persist_allow.html]
13
scheme=https
14
[test_storage_manager_persist_deny.html]
15
scheme=https
16
[test_storage_manager_persisted.html]
17
scheme=https
(-)a/dom/quota/test/test_storage_manager_persist_allow.html (+19 lines)
Line     Link Here 
Line 0    Link Here 
1
<!--
2
  Any copyright is dedicated to the Public Domain.
3
  http://creativecommons.org/publicdomain/zero/1.0/
4
-->
5
<html>
6
<head>
7
  <title>Allow Persist Prompt for StorageManager</title>
8
9
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11
12
  <script type="text/javascript;version=1.7" src="unit/test_storage_manager_persist_allow.js"></script>
13
  <script type="text/javascript;version=1.7" src="helpers.js"></script>
14
15
</head>
16
17
<body onload="runTest();"></body>
18
19
</html>
(-)a/dom/quota/test/test_storage_manager_persist_deny.html (+19 lines)
Line     Link Here 
Line 0    Link Here 
1
<!--
2
  Any copyright is dedicated to the Public Domain.
3
  http://creativecommons.org/publicdomain/zero/1.0/
4
-->
5
<html>
6
<head>
7
  <title>Deny Persist Prompt for StorageManager</title>
8
9
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11
12
  <script type="text/javascript;version=1.7" src="unit/test_storage_manager_persist_deny.js"></script>
13
  <script type="text/javascript;version=1.7" src="helpers.js"></script>
14
15
</head>
16
17
<body onload="runTest();"></body>
18
19
</html>
(-)a/modules/libpref/init/all.js (+3 lines)
Line     Link Here 
 Lines 5633-5648   pref ("security.data_uri.inherit_securit Link Here 
5633
5633
5634
// Disable Storage api in release builds.
5634
// Disable Storage api in release builds.
5635
#if defined(NIGHTLY_BUILD) && !defined(MOZ_WIDGET_ANDROID)
5635
#if defined(NIGHTLY_BUILD) && !defined(MOZ_WIDGET_ANDROID)
5636
pref("dom.storageManager.enabled", true);
5636
pref("dom.storageManager.enabled", true);
5637
#else
5637
#else
5638
pref("dom.storageManager.enabled", false);
5638
pref("dom.storageManager.enabled", false);
5639
#endif
5639
#endif
5640
5640
5641
pref("dom.storageManager.prompt.testing", false);
5642
pref("dom.storageManager.prompt.testing.allow", false);
5643
5641
// When a user cancels this number of authentication dialogs coming from
5644
// When a user cancels this number of authentication dialogs coming from
5642
// a single web page in a row, all following authentication dialogs will
5645
// a single web page in a row, all following authentication dialogs will
5643
// be blocked (automatically canceled) for that page. The counter resets
5646
// be blocked (automatically canceled) for that page. The counter resets
5644
// when the page is reloaded. To turn this feature off, just set the limit to 0.
5647
// when the page is reloaded. To turn this feature off, just set the limit to 0.
5645
pref("prompts.authentication_dialog_abuse_limit", 3);
5648
pref("prompts.authentication_dialog_abuse_limit", 3);
5646
5649
5647
// Enable the Storage management in about:preferences and persistent-storage permission request
5650
// Enable the Storage management in about:preferences and persistent-storage permission request
5648
// To enable the DOM implementation, turn on "dom.storageManager.enabled"
5651
// To enable the DOM implementation, turn on "dom.storageManager.enabled"

Return to bug 1286717