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