michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: const appDomain = "example.org"; michael@0: const manifestURL = michael@0: location.protocol + "//" + appDomain + "/manifest.webapp"; michael@0: michael@0: function testSteps() michael@0: { michael@0: const objectStoreName = "foo"; michael@0: const testKey = 1; michael@0: const testValue = objectStoreName; michael@0: michael@0: // Determine whether the app and browser frames should be in or michael@0: // out-of-process. michael@0: let remote_app, remote_browser; michael@0: if (window.location.href.indexOf("inproc_oop") != -1) { michael@0: remote_app = false; michael@0: remote_browser = true; michael@0: } michael@0: else if (window.location.href.indexOf("oop_inproc") != -1) { michael@0: remote_app = true; michael@0: remote_browser = false; michael@0: } michael@0: else if (window.location.href.indexOf("inproc_inproc") != -1) { michael@0: remote_app = false; michael@0: remote_browser = false; michael@0: } michael@0: else { michael@0: ok(false, "Bad test filename!"); michael@0: return; michael@0: } michael@0: michael@0: let request = indexedDB.open(window.location.pathname, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: db.onerror = errorHandler; michael@0: db.onversionchange = function(event) { michael@0: event.target.close(); michael@0: } michael@0: michael@0: let objectStore = db.createObjectStore(objectStoreName); michael@0: objectStore.add(testValue, testKey); michael@0: michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: // We need to send both remote_browser and remote_app in the querystring michael@0: // because webapp_clearBrowserData_appFrame uses the path + querystring to michael@0: // create and open a database which it checks no other test has touched. If michael@0: // we sent only remote_browser, then we wouldn't be able to test both michael@0: // (remote_app==false, remote_browser==false) and (remote_app==true, michael@0: // remote_browser==false). michael@0: let srcURL = location.protocol + "//" + appDomain + michael@0: location.pathname.substring(0, location.pathname.lastIndexOf('/')) + michael@0: "/webapp_clearBrowserData_appFrame.html?" + michael@0: "remote_browser=" + remote_browser + "&" + michael@0: "remote_app=" + remote_app; michael@0: michael@0: let iframe = document.createElement("iframe"); michael@0: iframe.setAttribute("mozbrowser", ""); michael@0: iframe.setAttribute("mozapp", manifestURL); michael@0: iframe.setAttribute("src", srcURL); michael@0: iframe.setAttribute("remote", remote_app); michael@0: iframe.addEventListener("mozbrowsershowmodalprompt", function(event) { michael@0: let message = JSON.parse(event.detail.message); michael@0: switch (message.type) { michael@0: case "info": michael@0: case "ok": michael@0: window[message.type].apply(window, message.args); michael@0: break; michael@0: case "done": michael@0: continueToNextStepSync(); michael@0: break; michael@0: default: michael@0: throw "unknown message"; michael@0: } michael@0: }); michael@0: michael@0: info("loading app frame"); michael@0: michael@0: document.body.appendChild(iframe); michael@0: yield undefined; michael@0: michael@0: request = indexedDB.open(window.location.pathname, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = unexpectedSuccessHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: db = event.target.result; michael@0: db.onerror = errorHandler; michael@0: michael@0: objectStore = michael@0: db.transaction(objectStoreName).objectStore(objectStoreName); michael@0: objectStore.get(testKey).onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: ok(testValue == event.target.result, "data still exists"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: } michael@0: michael@0: function start() michael@0: { michael@0: if (!SpecialPowers.isMainProcess()) { michael@0: todo(false, "Test disabled in child processes, for now"); michael@0: SimpleTest.finish(); michael@0: return; michael@0: } michael@0: michael@0: SpecialPowers.addPermission("browser", true, document); michael@0: SpecialPowers.addPermission("browser", true, { manifestURL: manifestURL, michael@0: isInBrowserElement: false }); michael@0: SpecialPowers.addPermission("embed-apps", true, document); michael@0: michael@0: SpecialPowers.setAllAppsLaunchable(true); michael@0: michael@0: window.addEventListener("unload", function cleanup(event) { michael@0: if (event.target == document) { michael@0: window.removeEventListener("unload", cleanup, false); michael@0: michael@0: SpecialPowers.removePermission("browser", location.href); michael@0: SpecialPowers.removePermission("browser", michael@0: location.protocol + "//" + appDomain); michael@0: SpecialPowers.removePermission("embed-apps", location.href); michael@0: } michael@0: }, false); michael@0: michael@0: SpecialPowers.pushPrefEnv({ michael@0: "set": [["dom.mozBrowserFramesEnabled", true]] michael@0: }, runTest); michael@0: }