Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1712)

Side by Side Diff: chrome/test/data/extensions/platform_apps/web_view/shim/main.js

Issue 12224094: Browser Plugin: Navigating to the same URL after crash should load a new guest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits + Merged with ToT Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var util = {}; 5 var util = {};
6 6
7 // Creates a <webview> tag in document.body and returns the reference to it. 7 // Creates a <webview> tag in document.body and returns the reference to it.
8 // It also sets a dummy src. The dummy src is significant because this makes 8 // It also sets a dummy src. The dummy src is significant because this makes
9 // sure that the <object> shim is created (asynchronously at this point) for the 9 // sure that the <object> shim is created (asynchronously at this point) for the
10 // <webview> tag. This makes the <webview> tag ready for add/removeEventListener 10 // <webview> tag. This makes the <webview> tag ready for add/removeEventListener
11 // calls. 11 // calls.
12 util.createWebViewTagInDOM = function() { 12 util.createWebViewTagInDOM = function(partitionName) {
13 var webview = document.createElement('webview'); 13 var webview = document.createElement('webview');
14 webview.style.width = '300px'; 14 webview.style.width = '300px';
15 webview.style.height = '200px'; 15 webview.style.height = '200px';
16 document.body.appendChild(webview);
17 var urlDummy = 'data:text/html,<body>Initial dummy guest</body>'; 16 var urlDummy = 'data:text/html,<body>Initial dummy guest</body>';
18 webview.setAttribute('src', urlDummy); 17 webview.setAttribute('src', urlDummy);
18 webview.setAttribute('partition', partitionName);
19 document.body.appendChild(webview);
19 return webview; 20 return webview;
20 }; 21 };
21 22
22 onload = function() { 23 onload = function() {
23 chrome.test.runTests([ 24 chrome.test.runTests([
24 function webView() { 25 function webView() {
25 var webview = document.querySelector('webview'); 26 var webview = document.querySelector('webview');
26 // Since we can't currently inspect the page loaded inside the <webview>, 27 // Since we can't currently inspect the page loaded inside the <webview>,
27 // the only way we can check that the shim is working is by changing the 28 // the only way we can check that the shim is working is by changing the
28 // size and seeing if the shim updates the size of the DOM. 29 // size and seeing if the shim updates the size of the DOM.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 'canGoBack', 63 'canGoBack',
63 'canGoForward', 64 'canGoForward',
64 'forward', 65 'forward',
65 'getProcessId', 66 'getProcessId',
66 'go', 67 'go',
67 'reload', 68 'reload',
68 'stop', 69 'stop',
69 'terminate' 70 'terminate'
70 ]; 71 ];
71 var webview = document.createElement('webview'); 72 var webview = document.createElement('webview');
73 webview.setAttribute('partition', arguments.callee.name);
72 webview.addEventListener('loadstop', function(e) { 74 webview.addEventListener('loadstop', function(e) {
73 for (var i = 0; i < apiMethodsToCheck.length; ++i) { 75 for (var i = 0; i < apiMethodsToCheck.length; ++i) {
74 chrome.test.assertEq('function', 76 chrome.test.assertEq('function',
75 typeof webview[apiMethodsToCheck[i]]); 77 typeof webview[apiMethodsToCheck[i]]);
76 } 78 }
77 79
78 // Check contentWindow. 80 // Check contentWindow.
79 chrome.test.assertEq('object', typeof webview.contentWindow); 81 chrome.test.assertEq('object', typeof webview.contentWindow);
80 chrome.test.assertEq('function', 82 chrome.test.assertEq('function',
81 typeof webview.contentWindow.postMessage); 83 typeof webview.contentWindow.postMessage);
82
83 chrome.test.succeed(); 84 chrome.test.succeed();
84 }); 85 });
85 webview.setAttribute('src', 'data:text/html,webview check api'); 86 webview.setAttribute('src', 'data:text/html,webview check api');
86 document.body.appendChild(webview); 87 document.body.appendChild(webview);
87 }, 88 },
88 89
89 function webViewEventName() { 90 function webViewEventName() {
90 var webview = document.createElement('webview'); 91 var webview = document.createElement('webview');
91 webview.setAttribute('src', 'data:text/html,webview check api'); 92 webview.setAttribute('partition', arguments.callee.name);
92 document.body.appendChild(webview);
93 93
94 webview.addEventListener('loadstart', function(evt) { 94 webview.addEventListener('loadstart', function(evt) {
95 chrome.test.assertEq('loadstart', evt.type); 95 chrome.test.assertEq('loadstart', evt.type);
96 }); 96 });
97 97
98 webview.addEventListener('loadstop', function(evt) { 98 webview.addEventListener('loadstop', function(evt) {
99 chrome.test.assertEq('loadstop', evt.type); 99 chrome.test.assertEq('loadstop', evt.type);
100 webview.terminate(); 100 webview.terminate();
101 }); 101 });
102 102
103 webview.addEventListener('exit', function(evt) { 103 webview.addEventListener('exit', function(evt) {
104 chrome.test.assertEq('exit', evt.type); 104 chrome.test.assertEq('exit', evt.type);
105 chrome.test.succeed(); 105 chrome.test.succeed();
106 }); 106 });
107 107
108 webview.setAttribute('src', 'data:text/html,trigger navigation'); 108 webview.setAttribute('src', 'data:text/html,trigger navigation');
109 document.body.appendChild(webview);
109 }, 110 },
110 111
111 // This test registers two listeners on an event (loadcommit) and removes 112 // This test registers two listeners on an event (loadcommit) and removes
112 // the <webview> tag when the first listener fires. 113 // the <webview> tag when the first listener fires.
113 // Current expected behavior is that the second event listener will still 114 // Current expected behavior is that the second event listener will still
114 // fire without crashing. 115 // fire without crashing.
115 function webviewDestroyOnEventListener() { 116 function webviewDestroyOnEventListener() {
116 var webview = util.createWebViewTagInDOM(); 117 var webview = util.createWebViewTagInDOM(arguments.callee.name);
117 var url = 'data:text/html,<body>Destroy test</body>'; 118 var url = 'data:text/html,<body>Destroy test</body>';
118 119
119 var loadCommitCount = 0; 120 var loadCommitCount = 0;
120 function loadCommitCommon(e) { 121 function loadCommitCommon(e) {
121 chrome.test.assertEq('loadcommit', e.type); 122 chrome.test.assertEq('loadcommit', e.type);
122 if (url != e.url) 123 if (url != e.url)
123 return; 124 return;
124 ++loadCommitCount; 125 ++loadCommitCount;
125 if (loadCommitCount == 1) { 126 if (loadCommitCount == 1) {
126 webview.parentNode.removeChild(webview);
127 webview = null;
128 setTimeout(function() { 127 setTimeout(function() {
129 chrome.test.succeed(); 128 chrome.test.succeed();
130 }, 0); 129 }, 0);
131 } else if (loadCommitCount > 2) { 130 } else if (loadCommitCount > 2) {
132 chrome.test.fail(); 131 chrome.test.fail();
133 } 132 }
134 }; 133 };
135 134
136 // The test starts from here, by setting the src to |url|. 135 // The test starts from here, by setting the src to |url|.
137 webview.addEventListener('loadcommit', function(e) { 136 webview.addEventListener('loadcommit', function(e) {
137 webview.parentNode.removeChild(webview);
138 loadCommitCommon(e); 138 loadCommitCommon(e);
139 }); 139 });
140 webview.addEventListener('loadcommit', function(e) { 140 webview.addEventListener('loadcommit', function(e) {
141 loadCommitCommon(e); 141 loadCommitCommon(e);
142 }); 142 });
143 webview.setAttribute('src', url); 143 webview.setAttribute('src', url);
144 }, 144 },
145 145
146 // This test registers two event listeners on a same event (loadcommit). 146 // This test registers two event listeners on a same event (loadcommit).
147 // Each of the listener tries to change some properties on the event param, 147 // Each of the listener tries to change some properties on the event param,
148 // which should not be possible. 148 // which should not be possible.
149 function cannotMutateEventName() { 149 function cannotMutateEventName() {
150 var webview = util.createWebViewTagInDOM(); 150 var webview = util.createWebViewTagInDOM(arguments.callee.name);
151 var url = 'data:text/html,<body>Two</body>'; 151 var url = 'data:text/html,<body>Two</body>';
152 152
153 var loadCommitACalled = false; 153 var loadCommitACalled = false;
154 var loadCommitBCalled = false; 154 var loadCommitBCalled = false;
155 155
156 var maybeFinishTest = function(e) { 156 var maybeFinishTest = function(e) {
157 if (loadCommitACalled && loadCommitBCalled) { 157 if (loadCommitACalled && loadCommitBCalled) {
158 chrome.test.assertEq('loadcommit', e.type); 158 chrome.test.assertEq('loadcommit', e.type);
159 chrome.test.succeed(); 159 chrome.test.succeed();
160 } 160 }
(...skipping 27 matching lines...) Expand all
188 // on the <webview> tag. 188 // on the <webview> tag.
189 webview.addEventListener('loadcommit', onLoadCommitA); 189 webview.addEventListener('loadcommit', onLoadCommitA);
190 webview.addEventListener('loadcommit', onLoadCommitB); 190 webview.addEventListener('loadcommit', onLoadCommitB);
191 webview.setAttribute('src', url); 191 webview.setAttribute('src', url);
192 }, 192 },
193 193
194 // This test verifies that setting the partition attribute after the src has 194 // This test verifies that setting the partition attribute after the src has
195 // been set raises an exception. 195 // been set raises an exception.
196 function partitionRaisesException() { 196 function partitionRaisesException() {
197 var webview = document.createElement('webview'); 197 var webview = document.createElement('webview');
198 webview.setAttribute('partition', arguments.callee.name);
198 webview.setAttribute('src', 'data:text/html,trigger navigation'); 199 webview.setAttribute('src', 'data:text/html,trigger navigation');
199 document.body.appendChild(webview); 200 document.body.appendChild(webview);
200 setTimeout(function() { 201 setTimeout(function() {
201 try { 202 try {
202 webview.partition = 'illegal'; 203 webview.partition = 'illegal';
203 chrome.test.fail(); 204 chrome.test.fail();
204 } catch (e) { 205 } catch (e) {
205 chrome.test.succeed(); 206 chrome.test.succeed();
206 } 207 }
207 }, 0); 208 }, 0);
208 }, 209 },
209 210
210 function webViewExecuteScript() { 211 function webViewExecuteScript() {
211 var webview = document.createElement('webview'); 212 var webview = document.createElement('webview');
213 webview.setAttribute('partition', arguments.callee.name);
212 webview.addEventListener('loadstop', function() { 214 webview.addEventListener('loadstop', function() {
213 webview.executeScript( 215 webview.executeScript(
214 {code:'document.body.style.backgroundColor = "red";'}, 216 {code:'document.body.style.backgroundColor = "red";'},
215 function(results) { 217 function(results) {
216 chrome.test.assertEq(1, results.length); 218 chrome.test.assertEq(1, results.length);
217 chrome.test.assertEq('red', results[0]); 219 chrome.test.assertEq('red', results[0]);
218 chrome.test.succeed(); 220 chrome.test.succeed();
219 }); 221 });
220 }); 222 });
221 webview.setAttribute('src', 'data:text/html,trigger navigation'); 223 webview.setAttribute('src', 'data:text/html,trigger navigation');
222 document.body.appendChild(webview); 224 document.body.appendChild(webview);
223 }, 225 },
224 226
225 // This test calls terminate() on guest after it has already been 227 // This test calls terminate() on guest after it has already been
226 // terminated. This makes sure we ignore the call gracefully. 228 // terminated. This makes sure we ignore the call gracefully.
227 function webViewTerminateAfterExitDoesntCrash() { 229 function webViewTerminateAfterExitDoesntCrash() {
228 var webview = document.querySelector('webview'); 230 var webview = document.createElement('webview');
229 webview.addEventListener('loadstart', function(evt) { 231 webview.setAttribute('partition', arguments.callee.name);
230 chrome.test.assertEq('loadstart', evt.type);
231 });
232
233 var loadstopSucceedsTest = false; 232 var loadstopSucceedsTest = false;
234 webview.addEventListener('loadstop', function(evt) { 233 webview.addEventListener('loadstop', function(evt) {
235 chrome.test.assertEq('loadstop', evt.type); 234 chrome.test.assertEq('loadstop', evt.type);
236 if (loadstopSucceedsTest) { 235 if (loadstopSucceedsTest) {
237 chrome.test.succeed(); 236 chrome.test.succeed();
238 return; 237 return;
239 } 238 }
240 239
241 webview.terminate(); 240 webview.terminate();
242 }); 241 });
243 242
244 webview.addEventListener('exit', function(evt) { 243 webview.addEventListener('exit', function(evt) {
245 chrome.test.assertEq('exit', evt.type); 244 chrome.test.assertEq('exit', evt.type);
246 // Call terminate again. 245 // Call terminate again.
247 webview.terminate(); 246 webview.terminate();
248 // Load another page. The test would pass when loadstop is called on 247 // Load another page. The test would pass when loadstop is called on
249 // this second page. This would hopefully catch if call to 248 // this second page. This would hopefully catch if call to
250 // webview.terminate() caused a browser crash. 249 // webview.terminate() caused a browser crash.
251 setTimeout(function() { 250 setTimeout(function() {
252 loadstopSucceedsTest = true; 251 loadstopSucceedsTest = true;
253 webview.setAttribute('src', 'data:text/html,test second page'); 252 webview.setAttribute('src', 'data:text/html,test second page');
254 }, 0); 253 }, 0);
255 }); 254 });
256 255
257 webview.setAttribute('src', 'data:text/html,test terminate() crash.'); 256 webview.setAttribute('src', 'data:text/html,test terminate() crash.');
257 document.body.appendChild(webview);
258 },
259
260 // This test verifies that assigning the src attribute the same value it had
261 // prior to a crash spawns off a new guest process.
262 function webViewAssignSrcAfterCrash() {
263 var webview = document.createElement('webview');
264 webview.setAttribute('partition', arguments.callee.name);
265 var terminated = false;
266 webview.addEventListener('loadstop', function(evt) {
267 if (!terminated) {
268 webview.terminate();
269 return;
270 }
271 // The guest has recovered after being terminated.
272 chrome.test.succeed();
273 });
274 webview.addEventListener('exit', function(evt) {
275 terminated = true;
276 webview.setAttribute('src', 'data:text/html,test page');
277 });
278 webview.setAttribute('src', 'data:text/html,test page');
279 document.body.appendChild(webview);
280 },
281
282 // This test verifies that <webview> restores the src attribute if it is
283 // removed after navigation.
284 function webViewRemoveSrcAttribute() {
285 var dataUrl = 'data:text/html,test page';
286 var webview = document.createElement('webview');
287 webview.setAttribute('partition', arguments.callee.name);
288 var terminated = false;
289 webview.addEventListener('loadstop', function(evt) {
290 webview.removeAttribute('src');
291 setTimeout(function() {
292 chrome.test.assertEq(dataUrl, webview.getAttribute('src'));
293 chrome.test.succeed();
294 }, 0);
295 });
296 webview.setAttribute('src', dataUrl);
297 document.body.appendChild(webview);
258 } 298 }
259 ]); 299 ]);
260 }; 300 };
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/web_view.js ('k') | content/renderer/browser_plugin/browser_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698