dom/indexedDB/test/webapp_clearBrowserData_appFrame.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!--
michael@0 2 Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 -->
michael@0 5 <html>
michael@0 6 <head>
michael@0 7 <title>Indexed Database Clear Browser Data Test</title>
michael@0 8
michael@0 9 <script type="text/javascript;version=1.7">
michael@0 10 "use strict";
michael@0 11
michael@0 12 function ok(cond, message)
michael@0 13 {
michael@0 14 alert(JSON.stringify({ type: "ok",
michael@0 15 args: [!!cond, "appFrame: " + message] }));
michael@0 16 }
michael@0 17
michael@0 18 function info(message)
michael@0 19 {
michael@0 20 alert(JSON.stringify({ type: "info",
michael@0 21 args: ["appFrame: " + message] }));
michael@0 22 }
michael@0 23
michael@0 24 function finish()
michael@0 25 {
michael@0 26 alert(JSON.stringify({ type: "done" }));
michael@0 27 }
michael@0 28
michael@0 29 window.onerror = ok.bind(window, false);
michael@0 30
michael@0 31 function testSteps()
michael@0 32 {
michael@0 33 const objectStoreName = "foo";
michael@0 34 const testKey = 1;
michael@0 35 const testValue = objectStoreName;
michael@0 36 const dbName = location.pathname + location.search;
michael@0 37
michael@0 38 // Determine whether our parent iframe asked us to create a remote
michael@0 39 // browser frame here.
michael@0 40 let remote_browser;
michael@0 41 if (location.search.indexOf("remote_browser=true") != -1) {
michael@0 42 remote_browser = true;
michael@0 43 }
michael@0 44 else if (location.search.indexOf("remote_browser=false") != -1) {
michael@0 45 remote_browser = false;
michael@0 46 }
michael@0 47 else {
michael@0 48 ok(false, "Expected remote_browser={true,false} in query string.");
michael@0 49 return;
michael@0 50 }
michael@0 51
michael@0 52 let request = indexedDB.open(dbName, 1);
michael@0 53 request.onerror = errorHandler;
michael@0 54 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 55 request.onsuccess = unexpectedSuccessHandler;
michael@0 56 let event = yield undefined;
michael@0 57
michael@0 58 let db = event.target.result;
michael@0 59 db.onerror = errorHandler;
michael@0 60 db.onversionchange = function(event) {
michael@0 61 event.target.close();
michael@0 62 }
michael@0 63
michael@0 64 let objectStore = db.createObjectStore(objectStoreName);
michael@0 65 objectStore.add(testValue, testKey);
michael@0 66
michael@0 67 request.onsuccess = grabEventAndContinueHandler;
michael@0 68 event = yield undefined;
michael@0 69
michael@0 70 ok(db === event.target.result, "created database");
michael@0 71
michael@0 72 objectStore =
michael@0 73 db.transaction(objectStoreName).objectStore(objectStoreName);
michael@0 74 objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
michael@0 75 event = yield undefined;
michael@0 76
michael@0 77 ok(testValue == event.target.result, "data exists");
michael@0 78
michael@0 79 let iframe = document.createElement("iframe");
michael@0 80 iframe.setAttribute("mozbrowser", "");
michael@0 81 // Send our querystring to the subframe because
michael@0 82 // webapp_clearBrowserData_browserFrame uses its pathname + querystring to
michael@0 83 // open a database which it assumes hasn't been touched by another test.
michael@0 84 iframe.setAttribute("src", "webapp_clearBrowserData_browserFrame.html" + location.search);
michael@0 85 iframe.setAttribute("remote", remote_browser);
michael@0 86 iframe.addEventListener("mozbrowsershowmodalprompt", function(event) {
michael@0 87 let message = JSON.parse(event.detail.message);
michael@0 88 switch (message.type) {
michael@0 89 case "block":
michael@0 90 info("blocking browserFrame");
michael@0 91 event.preventDefault();
michael@0 92
michael@0 93 let request = navigator.mozApps.getSelf();
michael@0 94 request.onsuccess = function() {
michael@0 95 let app = request.result;
michael@0 96 ok(app, "got app");
michael@0 97
michael@0 98 info("clearing browser data");
michael@0 99 app.clearBrowserData();
michael@0 100
michael@0 101 info("unblocking browserFrame");
michael@0 102 event.detail.unblock();
michael@0 103 }
michael@0 104 break;
michael@0 105 case "done":
michael@0 106 continueToNextStepSync();
michael@0 107 break;
michael@0 108 default:
michael@0 109 alert(event.detail.message);
michael@0 110 }
michael@0 111 });
michael@0 112
michael@0 113 info("loading browser frame");
michael@0 114
michael@0 115 document.body.appendChild(iframe);
michael@0 116 yield undefined;
michael@0 117
michael@0 118 request = indexedDB.open(dbName, 1);
michael@0 119 request.onerror = errorHandler;
michael@0 120 request.onupgradeneeded = unexpectedSuccessHandler;
michael@0 121 request.onsuccess = grabEventAndContinueHandler;
michael@0 122 event = yield undefined;
michael@0 123
michael@0 124 db = event.target.result;
michael@0 125 db.onerror = errorHandler;
michael@0 126
michael@0 127 objectStore =
michael@0 128 db.transaction(objectStoreName).objectStore(objectStoreName);
michael@0 129 objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
michael@0 130 event = yield undefined;
michael@0 131
michael@0 132 ok(testValue == event.target.result, "data still exists");
michael@0 133
michael@0 134 finish();
michael@0 135 yield undefined;
michael@0 136 }
michael@0 137
michael@0 138 </script>
michael@0 139
michael@0 140 <script type="text/javascript;version=1.7" src="helpers.js"></script>
michael@0 141 </head>
michael@0 142
michael@0 143 <body onload="testGenerator.next();"></body>
michael@0 144
michael@0 145 </html>

mercurial