Bug 1333050 - Test for BrowsingData.removeIndexedDB, r=kmag
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 21 Sep 2017 21:41:52 +0200
changeset 433112 4f0551ee71c892174e9b8ee28d78b4213d6f2615
parent 433111 3ff6b103fa9b73a4263fa85af671959ce54e97aa
child 433113 90be30b5206c2b2724d61f4f6782197bfa768428
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1333050
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1333050 - Test for BrowsingData.removeIndexedDB, r=kmag
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_browsingData_indexedDB.js
browser/components/extensions/test/browser/file_indexedDB.html
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -17,16 +17,17 @@ support-files =
   file_iframe_document.sjs
   file_bypass_cache.sjs
   file_language_fr_en.html
   file_language_ja.html
   file_language_tlh.html
   file_dummy.html
   file_title.html
   file_inspectedwindow_reload_target.sjs
+  file_indexedDB.html
   file_serviceWorker.html
   locale/chrome.manifest
   webNav_createdTarget.html
   webNav_createdTargetSource.html
   webNav_createdTargetSource_subframe.html
   serviceWorker.js
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
@@ -46,16 +47,17 @@ skip-if = debug && (os == 'linux' && bit
 skip-if = (os == 'win' && !debug) # bug 1352668
 [browser_ext_browserAction_popup_resize.js]
 skip-if = os == 'mac' # Bug 1374749 will re-enable this test again.
 [browser_ext_browserAction_simple.js]
 [browser_ext_browserAction_telemetry.js]
 [browser_ext_browserAction_theme_icons.js]
 [browser_ext_browsingData_formData.js]
 [browser_ext_browsingData_history.js]
+[browser_ext_browsingData_indexedDB.js]
 [browser_ext_browsingData_localStorage.js]
 [browser_ext_browsingData_pluginData.js]
 [browser_ext_browsingData_serviceWorkers.js]
 [browser_ext_chrome_settings_overrides_home.js]
 [browser_ext_commands_execute_browser_action.js]
 [browser_ext_commands_execute_page_action.js]
 [browser_ext_commands_execute_sidebar_action.js]
 [browser_ext_commands_getAll.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_browsingData_indexedDB.js
@@ -0,0 +1,81 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+"use strict";
+
+add_task(async function testIndexedDB() {
+  function background() {
+    const PAGE = "/browser/browser/components/extensions/test/browser/file_indexedDB.html";
+
+    browser.test.onMessage.addListener(async (msg) => {
+      await browser.browsingData.remove({}, {indexedDB: true});
+      browser.test.sendMessage("indexedDBRemoved");
+    });
+
+    // Create two tabs.
+    browser.tabs.create({url: `http://mochi.test:8888${PAGE}`});
+    browser.tabs.create({url: `http://example.com${PAGE}`});
+  }
+
+  function contentScript() {
+    window.addEventListener("message", msg => { // eslint-disable-line mozilla/balanced-listeners
+      browser.test.sendMessage("indexedDBCreated");
+    }, true);
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    background,
+    manifest: {
+      permissions: ["browsingData", "tabs"],
+      "content_scripts": [{
+        "matches": [
+          "http://mochi.test/*/file_indexedDB.html",
+          "http://example.com/*/file_indexedDB.html",
+        ],
+        "js": ["script.js"],
+        "run_at": "document_start",
+      }],
+    },
+    files: {
+      "script.js": contentScript,
+    },
+  });
+
+  let win = await BrowserTestUtils.openNewBrowserWindow();
+  await focusWindow(win);
+
+  await extension.startup();
+  await extension.awaitMessage("indexedDBCreated");
+  await extension.awaitMessage("indexedDBCreated");
+
+  let qms = SpecialPowers.Cc["@mozilla.org/dom/quota-manager-service;1"]
+             .getService(Ci.nsIQuotaManagerService);
+
+  function getOrigins() {
+    return new Promise(resolve => {
+      let origins = [];
+      qms.getUsage(request => {
+        for (let i = 0; i < request.result.length; ++i) {
+          if (request.result[i].origin.startsWith("http://mochi.test") ||
+              request.result[i].origin.startsWith("http://example.com")) {
+            origins.push(request.result[i].origin);
+          }
+        }
+        resolve(origins);
+      });
+    });
+  }
+
+  let origins = await getOrigins();
+  is(origins.length, 2, "IndexedDB databases have been populated.");
+
+  extension.sendMessage();
+
+  await extension.awaitMessage("indexedDBRemoved");
+
+  origins = await getOrigins();
+  is(origins.length, 0, "IndexedDB data has been removed.");
+
+  await extension.unload();
+  await BrowserTestUtils.closeWindow(win);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/file_indexedDB.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <script>
+"use strict";
+
+const objectStoreName = "Objects";
+
+let test = {key: 0, value: "test"};
+
+let request = indexedDB.open("WebExtensionTest", 1);
+request.onupgradeneeded = event => {
+  let db = event.target.result;
+  let objectStore = db.createObjectStore(objectStoreName,
+                                         {autoIncrement: 0});
+  request = objectStore.add(test.value, test.key);
+  request.onsuccess = event => {
+    db.close();
+    window.postMessage("indexedDBCreated", "*");
+  };
+};
+    </script>
+  </head>
+  <body>
+    This is a test page.
+  </body>
+<html>