dom/indexedDB/test/webapp_clearBrowserData.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 const appDomain = "example.org";
michael@0 7 const manifestURL =
michael@0 8 location.protocol + "//" + appDomain + "/manifest.webapp";
michael@0 9
michael@0 10 function testSteps()
michael@0 11 {
michael@0 12 const objectStoreName = "foo";
michael@0 13 const testKey = 1;
michael@0 14 const testValue = objectStoreName;
michael@0 15
michael@0 16 // Determine whether the app and browser frames should be in or
michael@0 17 // out-of-process.
michael@0 18 let remote_app, remote_browser;
michael@0 19 if (window.location.href.indexOf("inproc_oop") != -1) {
michael@0 20 remote_app = false;
michael@0 21 remote_browser = true;
michael@0 22 }
michael@0 23 else if (window.location.href.indexOf("oop_inproc") != -1) {
michael@0 24 remote_app = true;
michael@0 25 remote_browser = false;
michael@0 26 }
michael@0 27 else if (window.location.href.indexOf("inproc_inproc") != -1) {
michael@0 28 remote_app = false;
michael@0 29 remote_browser = false;
michael@0 30 }
michael@0 31 else {
michael@0 32 ok(false, "Bad test filename!");
michael@0 33 return;
michael@0 34 }
michael@0 35
michael@0 36 let request = indexedDB.open(window.location.pathname, 1);
michael@0 37 request.onerror = errorHandler;
michael@0 38 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 39 request.onsuccess = unexpectedSuccessHandler;
michael@0 40 let event = yield undefined;
michael@0 41
michael@0 42 let db = event.target.result;
michael@0 43 db.onerror = errorHandler;
michael@0 44 db.onversionchange = function(event) {
michael@0 45 event.target.close();
michael@0 46 }
michael@0 47
michael@0 48 let objectStore = db.createObjectStore(objectStoreName);
michael@0 49 objectStore.add(testValue, testKey);
michael@0 50
michael@0 51 request.onsuccess = grabEventAndContinueHandler;
michael@0 52 event = yield undefined;
michael@0 53
michael@0 54 // We need to send both remote_browser and remote_app in the querystring
michael@0 55 // because webapp_clearBrowserData_appFrame uses the path + querystring to
michael@0 56 // create and open a database which it checks no other test has touched. If
michael@0 57 // we sent only remote_browser, then we wouldn't be able to test both
michael@0 58 // (remote_app==false, remote_browser==false) and (remote_app==true,
michael@0 59 // remote_browser==false).
michael@0 60 let srcURL = location.protocol + "//" + appDomain +
michael@0 61 location.pathname.substring(0, location.pathname.lastIndexOf('/')) +
michael@0 62 "/webapp_clearBrowserData_appFrame.html?" +
michael@0 63 "remote_browser=" + remote_browser + "&" +
michael@0 64 "remote_app=" + remote_app;
michael@0 65
michael@0 66 let iframe = document.createElement("iframe");
michael@0 67 iframe.setAttribute("mozbrowser", "");
michael@0 68 iframe.setAttribute("mozapp", manifestURL);
michael@0 69 iframe.setAttribute("src", srcURL);
michael@0 70 iframe.setAttribute("remote", remote_app);
michael@0 71 iframe.addEventListener("mozbrowsershowmodalprompt", function(event) {
michael@0 72 let message = JSON.parse(event.detail.message);
michael@0 73 switch (message.type) {
michael@0 74 case "info":
michael@0 75 case "ok":
michael@0 76 window[message.type].apply(window, message.args);
michael@0 77 break;
michael@0 78 case "done":
michael@0 79 continueToNextStepSync();
michael@0 80 break;
michael@0 81 default:
michael@0 82 throw "unknown message";
michael@0 83 }
michael@0 84 });
michael@0 85
michael@0 86 info("loading app frame");
michael@0 87
michael@0 88 document.body.appendChild(iframe);
michael@0 89 yield undefined;
michael@0 90
michael@0 91 request = indexedDB.open(window.location.pathname, 1);
michael@0 92 request.onerror = errorHandler;
michael@0 93 request.onupgradeneeded = unexpectedSuccessHandler;
michael@0 94 request.onsuccess = grabEventAndContinueHandler;
michael@0 95 event = yield undefined;
michael@0 96
michael@0 97 db = event.target.result;
michael@0 98 db.onerror = errorHandler;
michael@0 99
michael@0 100 objectStore =
michael@0 101 db.transaction(objectStoreName).objectStore(objectStoreName);
michael@0 102 objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
michael@0 103 event = yield undefined;
michael@0 104
michael@0 105 ok(testValue == event.target.result, "data still exists");
michael@0 106
michael@0 107 finishTest();
michael@0 108 yield undefined;
michael@0 109 }
michael@0 110
michael@0 111 function start()
michael@0 112 {
michael@0 113 if (!SpecialPowers.isMainProcess()) {
michael@0 114 todo(false, "Test disabled in child processes, for now");
michael@0 115 SimpleTest.finish();
michael@0 116 return;
michael@0 117 }
michael@0 118
michael@0 119 SpecialPowers.addPermission("browser", true, document);
michael@0 120 SpecialPowers.addPermission("browser", true, { manifestURL: manifestURL,
michael@0 121 isInBrowserElement: false });
michael@0 122 SpecialPowers.addPermission("embed-apps", true, document);
michael@0 123
michael@0 124 SpecialPowers.setAllAppsLaunchable(true);
michael@0 125
michael@0 126 window.addEventListener("unload", function cleanup(event) {
michael@0 127 if (event.target == document) {
michael@0 128 window.removeEventListener("unload", cleanup, false);
michael@0 129
michael@0 130 SpecialPowers.removePermission("browser", location.href);
michael@0 131 SpecialPowers.removePermission("browser",
michael@0 132 location.protocol + "//" + appDomain);
michael@0 133 SpecialPowers.removePermission("embed-apps", location.href);
michael@0 134 }
michael@0 135 }, false);
michael@0 136
michael@0 137 SpecialPowers.pushPrefEnv({
michael@0 138 "set": [["dom.mozBrowserFramesEnabled", true]]
michael@0 139 }, runTest);
michael@0 140 }

mercurial