dom/indexedDB/test/webapp_clearBrowserData_browserFrame.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, "browserFrame: " + 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: ["browserFrame: " + message] }));
michael@0 22 }
michael@0 23
michael@0 24 function block()
michael@0 25 {
michael@0 26 info("about to block");
michael@0 27
michael@0 28 // This will block until the parent has cleared our database.
michael@0 29 alert(JSON.stringify({ type: "block" }));
michael@0 30
michael@0 31 info("unblocked");
michael@0 32 }
michael@0 33
michael@0 34 function finish()
michael@0 35 {
michael@0 36 alert(JSON.stringify({ type: "done" }));
michael@0 37 }
michael@0 38
michael@0 39 window.onerror = ok.bind(window, false);
michael@0 40
michael@0 41 function testSteps()
michael@0 42 {
michael@0 43 const objectStoreName = "foo";
michael@0 44 const testKey = 1;
michael@0 45 const testValue = objectStoreName;
michael@0 46 const dbName = window.location.pathname + window.location.search;
michael@0 47
michael@0 48 let request = indexedDB.open(dbName, 1);
michael@0 49 request.onerror = errorHandler;
michael@0 50 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 51 request.onsuccess = unexpectedSuccessHandler;
michael@0 52 let event = yield undefined;
michael@0 53
michael@0 54 let db = event.target.result;
michael@0 55 db.onerror = errorHandler;
michael@0 56 db.onversionchange = function(event) {
michael@0 57 event.target.close();
michael@0 58 }
michael@0 59
michael@0 60 let objectStore = db.createObjectStore(objectStoreName);
michael@0 61 objectStore.add(testValue, testKey);
michael@0 62
michael@0 63 request.onsuccess = grabEventAndContinueHandler;
michael@0 64 event = yield undefined;
michael@0 65
michael@0 66 ok(db === event.target.result, "created database");
michael@0 67
michael@0 68 objectStore =
michael@0 69 db.transaction(objectStoreName).objectStore(objectStoreName);
michael@0 70 objectStore.get(testKey).onsuccess = grabEventAndContinueHandler;
michael@0 71 event = yield undefined;
michael@0 72
michael@0 73 ok(testValue == event.target.result, "data exists");
michael@0 74
michael@0 75 block();
michael@0 76
michael@0 77 request = indexedDB.open(dbName, 1);
michael@0 78 request.onerror = errorHandler;
michael@0 79 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 80 request.onsuccess = unexpectedSuccessHandler;
michael@0 81 event = yield undefined;
michael@0 82
michael@0 83 ok(event.type == "upgradeneeded", "db doesn't exist");
michael@0 84
michael@0 85 request.onsuccess = grabEventAndContinueHandler;
michael@0 86 event = yield undefined;
michael@0 87
michael@0 88 db = event.target.result;
michael@0 89 info(db.objectStoreNames.length);
michael@0 90 ok(!db.objectStoreNames.length, "no object stores");
michael@0 91
michael@0 92 finish();
michael@0 93
michael@0 94 yield undefined;
michael@0 95 }
michael@0 96
michael@0 97 </script>
michael@0 98
michael@0 99 <script type="text/javascript;version=1.7" src="helpers.js"></script>
michael@0 100 </head>
michael@0 101
michael@0 102 <body onload="testGenerator.next();"></body>
michael@0 103
michael@0 104 </html>

mercurial