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

Side by Side Diff: chrome/test/data/extensions/platform_apps/web_view/newwindow/embedder.js

Issue 558813002: <webview>: Fix an issue with destroying an opener that has unattached guests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix setTimeout call Created 6 years, 3 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
« no previous file with comments | « chrome/renderer/resources/extensions/web_view_events.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 embedder = {}; 5 var embedder = {};
6 embedder.test = {}; 6 embedder.test = {};
7 embedder.baseGuestURL = ''; 7 embedder.baseGuestURL = '';
8 embedder.guestURL = ''; 8 embedder.guestURL = '';
9 embedder.guestWithLinkURL = ''; 9 embedder.guestWithLinkURL = '';
10 embedder.newWindowURL = ''; 10 embedder.newWindowURL = '';
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Loads a guest which requests a new window. 193 // Loads a guest which requests a new window.
194 function testNewWindowNameTakesPrecedence() { 194 function testNewWindowNameTakesPrecedence() {
195 var webViewName = 'foo'; 195 var webViewName = 'foo';
196 var guestName = 'bar'; 196 var guestName = 'bar';
197 var partitionName = 'foobar'; 197 var partitionName = 'foobar';
198 var expectedName = guestName; 198 var expectedName = guestName;
199 testNewWindowName('testNewWindowNameTakesPrecedence', 199 testNewWindowName('testNewWindowNameTakesPrecedence',
200 webViewName, guestName, partitionName, expectedName); 200 webViewName, guestName, partitionName, expectedName);
201 } 201 }
202 202
203 function testWebViewNameTakesPrecedence() { 203 function testNewWindowWebViewNameTakesPrecedence() {
204 var webViewName = 'foo'; 204 var webViewName = 'foo';
205 var guestName = ''; 205 var guestName = '';
206 var partitionName = 'persist:foobar'; 206 var partitionName = 'persist:foobar';
207 var expectedName = webViewName; 207 var expectedName = webViewName;
208 testNewWindowName('testWebViewNameTakesPrecedence', 208 testNewWindowName('testNewWindowWebViewNameTakesPrecedence',
209 webViewName, guestName, partitionName, expectedName); 209 webViewName, guestName, partitionName, expectedName);
210 } 210 }
211 211
212 function testNoName() { 212 function testNewWindowNoName() {
213 var webViewName = ''; 213 var webViewName = '';
214 var guestName = ''; 214 var guestName = '';
215 var partitionName = ''; 215 var partitionName = '';
216 var expectedName = ''; 216 var expectedName = '';
217 testNewWindowName('testNoName', 217 testNewWindowName('testNewWindowNoName',
218 webViewName, guestName, partitionName, expectedName); 218 webViewName, guestName, partitionName, expectedName);
219 } 219 }
220 220
221 // This test exercises the need for queuing events that occur prior to 221 // This test exercises the need for queuing events that occur prior to
222 // attachment. In this test a new window is opened that initially navigates to 222 // attachment. In this test a new window is opened that initially navigates to
223 // about:blank and then subsequently redirects to its final destination. This 223 // about:blank and then subsequently redirects to its final destination. This
224 // test responds to loadstop in the new <webview>. Since "about:blank" does not 224 // test responds to loadstop in the new <webview>. Since "about:blank" does not
225 // have any external resources, it loads immediately prior to attachment, and 225 // have any external resources, it loads immediately prior to attachment, and
226 // the <webview> that is eventually attached never gets a chance to see the 226 // the <webview> that is eventually attached never gets a chance to see the
227 // event. GuestView solves this problem by queuing events that occur prior to 227 // event. GuestView solves this problem by queuing events that occur prior to
228 // attachment and firing them immediately after attachment. 228 // attachment and firing them immediately after attachment.
229 function testNewWindowRedirect() { 229 function testNewWindowRedirect() {
230 var webViewName = 'foo'; 230 var webViewName = 'foo';
231 var guestName = ''; 231 var guestName = '';
232 var partitionName = 'persist:foobar'; 232 var partitionName = 'persist:foobar';
233 var expectedName = webViewName; 233 var expectedName = webViewName;
234 testNewWindowName('testNewWindowRedirect_blank', 234 testNewWindowName('testNewWindowRedirect_blank',
235 webViewName, guestName, partitionName, expectedName); 235 webViewName, guestName, partitionName, expectedName);
236 } 236 }
237 237
238 // Tests that we fail gracefully if we try to attach() a <webview> on a
239 // newwindow event after the opener has been destroyed.
240 function testNewWindowAttachAfterOpenerDestroyed() {
241 var testName = 'testNewWindowAttachAfterOpenerDestroyed';
242 var webview = embedder.setUpGuest_('foobar');
243
244 var onNewWindow = function(e) {
245 embedder.assertCorrectEvent_(e, '');
246
247 // Remove the opener.
248 webview.parentNode.removeChild(webview);
249 // Pass in a timeout so we ensure the newwindow disposal codepath
250 // works properly.
251 window.setTimeout(function() {
252 // At this point the opener <webview> is gone.
253 // Trying to discard() will fail silently.
254 e.window.attach(document.createElement('webview'));
255 window.setTimeout(function() { embedder.test.succeed(); }, 0);
256 }, 0);
257
258 e.preventDefault();
259 };
260 webview.addEventListener('newwindow', onNewWindow);
261
262 // Load a new window with the given name.
263 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
264 }
265
238 function testNewWindowClose() { 266 function testNewWindowClose() {
239 var testName = 'testNewWindowClose'; 267 var testName = 'testNewWindowClose';
240 var webview = embedder.setUpGuest_('foobar'); 268 var webview = embedder.setUpGuest_('foobar');
241 269
242 var onNewWindow = function(e) { 270 var onNewWindow = function(e) {
243 chrome.test.log('Embedder notified on newwindow'); 271 chrome.test.log('Embedder notified on newwindow');
244 embedder.assertCorrectEvent_(e, ''); 272 embedder.assertCorrectEvent_(e, '');
245 273
246 var newwebview = document.createElement('webview'); 274 var newwebview = document.createElement('webview');
247 document.querySelector('#webview-tag-container').appendChild(newwebview); 275 document.querySelector('#webview-tag-container').appendChild(newwebview);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 312
285 // Append the <webview> in DOM later. 313 // Append the <webview> in DOM later.
286 window.setTimeout(function() { 314 window.setTimeout(function() {
287 document.querySelector('#webview-tag-container').appendChild(newwebview); 315 document.querySelector('#webview-tag-container').appendChild(newwebview);
288 }, 0); 316 }, 0);
289 }; 317 };
290 webview.addEventListener('newwindow', onNewWindow); 318 webview.addEventListener('newwindow', onNewWindow);
291 319
292 // Load a new window with the given name. 320 // Load a new window with the given name.
293 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName); 321 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
294 }; 322 }
323
324 // Tests that we fail gracefully if we try to discard() a <webview> on a
325 // newwindow event after the opener has been destroyed.
326 function testNewWindowDiscardAfterOpenerDestroyed() {
327 var testName = 'testNewWindowDiscardAfterOpenerDestroyed';
328 var webview = embedder.setUpGuest_('foobar');
329
330 var onNewWindow = function(e) {
331 embedder.assertCorrectEvent_(e, '');
332
333 // Remove the opener.
334 webview.parentNode.removeChild(webview);
335 // Pass in a timeout so we ensure the newwindow disposal codepath
336 // works properly.
337 window.setTimeout(function() {
338 // At this point the opener <webview> is gone.
339 // Trying to discard() will fail silently.
340 e.window.discard();
341 window.setTimeout(function() { embedder.test.succeed(); }, 0);
342 }, 0);
343
344 e.preventDefault();
345 };
346 webview.addEventListener('newwindow', onNewWindow);
347
348 // Load a new window with the given name.
349 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
350 }
295 351
296 function testNewWindowExecuteScript() { 352 function testNewWindowExecuteScript() {
297 var testName = 'testNewWindowExecuteScript'; 353 var testName = 'testNewWindowExecuteScript';
298 var webview = embedder.setUpGuest_('foobar'); 354 var webview = embedder.setUpGuest_('foobar');
299 355
300 var onNewWindow = function(e) { 356 var onNewWindow = function(e) {
301 chrome.test.log('Embedder notified on newwindow'); 357 chrome.test.log('Embedder notified on newwindow');
302 embedder.assertCorrectEvent_(e, ''); 358 embedder.assertCorrectEvent_(e, '');
303 359
304 var newwebview = document.createElement('webview'); 360 var newwebview = document.createElement('webview');
(...skipping 21 matching lines...) Expand all
326 webview.addEventListener('loadstop', function(e) { 382 webview.addEventListener('loadstop', function(e) {
327 webview.focus(); 383 webview.focus();
328 chrome.test.sendMessage('Loaded'); 384 chrome.test.sendMessage('Loaded');
329 }); 385 });
330 webview.addEventListener('newwindow', function(e) { 386 webview.addEventListener('newwindow', function(e) {
331 embedder.test.succeed(); 387 embedder.test.succeed();
332 }); 388 });
333 webview.src = embedder.guestWithLinkURL; 389 webview.src = embedder.guestWithLinkURL;
334 } 390 }
335 391
392 // Tests that if opener <webview> is gone with unattached guest, we
393 // don't see any error.
394 // This test also makes sure we destroy the unattached guests properly.
395 function testNewWindowOpenerDestroyedWhileUnattached() {
396 var testName = 'testNewWindowOpenerDestroyedBeforeAttach';
397 var webview = embedder.setUpGuest_('foobar');
398
399 var onNewWindow = function(e) {
400 embedder.assertCorrectEvent_(e, '');
401
402 // Remove the opener.
403 webview.parentNode.removeChild(webview);
404 // Pass in a timeout so we ensure the newwindow disposal codepath
405 // works properly.
406 window.setTimeout(function() { embedder.test.succeed(); }, 0);
407
408 e.preventDefault();
409 };
410 webview.addEventListener('newwindow', onNewWindow);
411
412 // Load a new window with the given name.
413 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
414 }
415
336 function testNewWindowWebRequest() { 416 function testNewWindowWebRequest() {
337 var testName = 'testNewWindowWebRequest'; 417 var testName = 'testNewWindowWebRequest';
338 var webview = embedder.setUpGuest_('foobar'); 418 var webview = embedder.setUpGuest_('foobar');
339 419
340 var onNewWindow = function(e) { 420 var onNewWindow = function(e) {
341 chrome.test.log('Embedder notified on newwindow'); 421 chrome.test.log('Embedder notified on newwindow');
342 embedder.assertCorrectEvent_(e, ''); 422 embedder.assertCorrectEvent_(e, '');
343 423
344 var newwebview = new WebView(); 424 var newwebview = new WebView();
345 var calledWebRequestEvent = false; 425 var calledWebRequestEvent = false;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 }; 564 };
485 }); 565 });
486 }; 566 };
487 webview.addEventListener('newwindow', onNewWindow); 567 webview.addEventListener('newwindow', onNewWindow);
488 568
489 // Load a new window with the given name. 569 // Load a new window with the given name.
490 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName); 570 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
491 } 571 }
492 572
493 embedder.test.testList = { 573 embedder.test.testList = {
574 'testNewWindowAttachAfterOpenerDestroyed':
575 testNewWindowAttachAfterOpenerDestroyed,
576 'testNewWindowClose': testNewWindowClose,
577 'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
578 'testNewWindowDeferredAttachment': testNewWindowDeferredAttachment,
579 'testNewWindowDiscardAfterOpenerDestroyed':
580 testNewWindowDiscardAfterOpenerDestroyed,
581 'testNewWindowExecuteScript': testNewWindowExecuteScript,
494 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence, 582 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence,
495 'testWebViewNameTakesPrecedence': testWebViewNameTakesPrecedence, 583 'testNewWindowNoName': testNewWindowNoName,
496 'testNoName': testNoName, 584 'testNewWindowOpenInNewTab': testNewWindowOpenInNewTab,
585 'testNewWindowOpenerDestroyedWhileUnattached':
586 testNewWindowOpenerDestroyedWhileUnattached,
497 'testNewWindowRedirect': testNewWindowRedirect, 587 'testNewWindowRedirect': testNewWindowRedirect,
498 'testNewWindowClose': testNewWindowClose,
499 'testNewWindowDeferredAttachment': testNewWindowDeferredAttachment,
500 'testNewWindowExecuteScript': testNewWindowExecuteScript,
501 'testNewWindowOpenInNewTab': testNewWindowOpenInNewTab,
502 'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
503 'testNewWindowWebRequest': testNewWindowWebRequest, 588 'testNewWindowWebRequest': testNewWindowWebRequest,
504 'testNewWindowWebRequestCloseWindow': testNewWindowWebRequestCloseWindow, 589 'testNewWindowWebRequestCloseWindow': testNewWindowWebRequestCloseWindow,
505 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement 590 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement,
591 'testNewWindowWebViewNameTakesPrecedence':
592 testNewWindowWebViewNameTakesPrecedence
506 }; 593 };
507 594
508 onload = function() { 595 onload = function() {
509 chrome.test.getConfig(function(config) { 596 chrome.test.getConfig(function(config) {
510 embedder.setUp_(config); 597 embedder.setUp_(config);
511 chrome.test.sendMessage('Launched'); 598 chrome.test.sendMessage('Launched');
512 }); 599 });
513 }; 600 };
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/web_view_events.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698