dom/indexedDB/test/file_app_isolation.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 SimpleTest.waitForExplicitFinish();
michael@0 2
michael@0 3 var fileTestOnCurrentOrigin = (location.protocol + '//' + location.host + location.pathname)
michael@0 4 .replace('test_', 'file_')
michael@0 5 .replace('_inproc', '').replace('_oop', '');
michael@0 6
michael@0 7 var previousPrefs = {
michael@0 8 mozBrowserFramesEnabled: undefined,
michael@0 9 oop_by_default: undefined,
michael@0 10 };
michael@0 11
michael@0 12 try {
michael@0 13 previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
michael@0 14 } catch(e)
michael@0 15 {
michael@0 16 }
michael@0 17
michael@0 18 try {
michael@0 19 previousPrefs.oop_by_default = SpecialPowers.getBoolPref('dom.ipc.browser_frames.oop_by_default');
michael@0 20 } catch(e) {
michael@0 21 }
michael@0 22
michael@0 23 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
michael@0 24 SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", location.pathname.indexOf('_inproc') == -1);
michael@0 25
michael@0 26 SpecialPowers.addPermission("browser", true, window.document);
michael@0 27
michael@0 28 var gData = [
michael@0 29 // APP 1
michael@0 30 {
michael@0 31 app: 'http://example.org/manifest.webapp',
michael@0 32 action: 'read-no',
michael@0 33 src: fileTestOnCurrentOrigin,
michael@0 34 },
michael@0 35 {
michael@0 36 app: 'http://example.org/manifest.webapp',
michael@0 37 action: 'write',
michael@0 38 src: fileTestOnCurrentOrigin,
michael@0 39 },
michael@0 40 {
michael@0 41 app: 'http://example.org/manifest.webapp',
michael@0 42 action: 'read-yes',
michael@0 43 src: fileTestOnCurrentOrigin,
michael@0 44 },
michael@0 45 // APP 2
michael@0 46 {
michael@0 47 app: 'https://example.com/manifest.webapp',
michael@0 48 action: 'read-no',
michael@0 49 src: fileTestOnCurrentOrigin,
michael@0 50 },
michael@0 51 {
michael@0 52 app: 'https://example.com/manifest.webapp',
michael@0 53 action: 'write',
michael@0 54 src: fileTestOnCurrentOrigin,
michael@0 55 },
michael@0 56 {
michael@0 57 app: 'https://example.com/manifest.webapp',
michael@0 58 action: 'read-yes',
michael@0 59 src: fileTestOnCurrentOrigin,
michael@0 60 },
michael@0 61 // Browser
michael@0 62 {
michael@0 63 browser: true,
michael@0 64 action: 'read-no',
michael@0 65 src: fileTestOnCurrentOrigin,
michael@0 66 },
michael@0 67 {
michael@0 68 browser: true,
michael@0 69 action: 'write',
michael@0 70 src: fileTestOnCurrentOrigin,
michael@0 71 },
michael@0 72 {
michael@0 73 browser: true,
michael@0 74 action: 'read-yes',
michael@0 75 src: fileTestOnCurrentOrigin,
michael@0 76 },
michael@0 77 ];
michael@0 78
michael@0 79 function runTest() {
michael@0 80 for (var i in gData) {
michael@0 81 var iframe = document.createElement('iframe');
michael@0 82 var data = gData[i];
michael@0 83
michael@0 84 if (data.app) {
michael@0 85 iframe.setAttribute('mozbrowser', '');
michael@0 86 iframe.setAttribute('mozapp', data.app);
michael@0 87 } else if (data.browser) {
michael@0 88 iframe.setAttribute('mozbrowser', '');
michael@0 89 }
michael@0 90
michael@0 91 if (data.app || data.browser) {
michael@0 92 iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
michael@0 93 is(e.detail.message, 'success', 'test number ' + i);
michael@0 94
michael@0 95 // document.getElementById('content').removeChild(iframe);
michael@0 96
michael@0 97 i++;
michael@0 98 if (i >= gData.length) {
michael@0 99 if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
michael@0 100 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
michael@0 101 }
michael@0 102 if (previousPrefs.oop_by_default !== undefined) {
michael@0 103 SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", previousPrefs.oop_by_default);
michael@0 104 }
michael@0 105
michael@0 106 SpecialPowers.removePermission("browser", window.document);
michael@0 107
michael@0 108 indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
michael@0 109 SimpleTest.finish();
michael@0 110 };
michael@0 111 } else {
michael@0 112 gTestRunner.next();
michael@0 113 }
michael@0 114 });
michael@0 115 }
michael@0 116
michael@0 117 iframe.src = data.src + '?' + data.action;
michael@0 118
michael@0 119 document.getElementById('content').appendChild(iframe);
michael@0 120
michael@0 121 yield undefined;
michael@0 122 }
michael@0 123 }
michael@0 124
michael@0 125 var gTestRunner = runTest();
michael@0 126
michael@0 127 function startTest() {
michael@0 128 var request = window.indexedDB.open('AppIsolationTest');
michael@0 129 var created = false;
michael@0 130
michael@0 131 request.onupgradeneeded = function(event) {
michael@0 132 created = true;
michael@0 133 var db = event.target.result;
michael@0 134 var data = [
michael@0 135 { id: "0", name: "foo" },
michael@0 136 ];
michael@0 137 var objectStore = db.createObjectStore("test", { keyPath: "id" });
michael@0 138 for (var i in data) {
michael@0 139 objectStore.add(data[i]);
michael@0 140 }
michael@0 141 }
michael@0 142
michael@0 143 request.onsuccess = function(event) {
michael@0 144 var db = event.target.result;
michael@0 145 is(created, true, "we should have created the db");
michael@0 146
michael@0 147 db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
michael@0 148 is(event.target.result.name, 'foo', 'data have been written');
michael@0 149 db.close();
michael@0 150
michael@0 151 gTestRunner.next();
michael@0 152 };
michael@0 153 }
michael@0 154 }
michael@0 155
michael@0 156 // test_ipc.html executes all the tests in this directory in content process.
michael@0 157 // It will fail on this one for the moment.
michael@0 158 if (!SpecialPowers.isMainProcess()) {
michael@0 159 todo(false, "We should make this work on content process");
michael@0 160 SimpleTest.finish();
michael@0 161 } else {
michael@0 162 // TODO: remove unsetting network.disable.ipc.security as part of bug 820712
michael@0 163 SpecialPowers.pushPrefEnv({
michael@0 164 "set": [
michael@0 165 ["network.disable.ipc.security", true],
michael@0 166 ]
michael@0 167 }, startTest);
michael@0 168 }

mercurial