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

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: add tests for attach/discard call after opener destruction 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() { embedder.test.succeed(); }, 0);
Fady Samuel 2014/09/09 23:01:34 Delete this line?
lazyboy 2014/09/09 23:18:36 Done.
252 window.setTimeout(function() {
253 // At this point the opener <webview> is gone.
254 // Trying to discard() will fail silencly.
Fady Samuel 2014/09/09 23:01:33 s/discard/attach s/silencly/silently.
lazyboy 2014/09/09 23:18:36 Done.
255 e.window.attach(document.createElement('webview'));
256 window.setTimeout(function() { embedder.test.succeed(); });
257 }, 0);
258
259 e.preventDefault();
260 };
261 webview.addEventListener('newwindow', onNewWindow);
262
263 // Load a new window with the given name.
264 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
265 }
266
238 function testNewWindowClose() { 267 function testNewWindowClose() {
239 var testName = 'testNewWindowClose'; 268 var testName = 'testNewWindowClose';
240 var webview = embedder.setUpGuest_('foobar'); 269 var webview = embedder.setUpGuest_('foobar');
241 270
242 var onNewWindow = function(e) { 271 var onNewWindow = function(e) {
243 chrome.test.log('Embedder notified on newwindow'); 272 chrome.test.log('Embedder notified on newwindow');
244 embedder.assertCorrectEvent_(e, ''); 273 embedder.assertCorrectEvent_(e, '');
245 274
246 var newwebview = document.createElement('webview'); 275 var newwebview = document.createElement('webview');
247 document.querySelector('#webview-tag-container').appendChild(newwebview); 276 document.querySelector('#webview-tag-container').appendChild(newwebview);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 313
285 // Append the <webview> in DOM later. 314 // Append the <webview> in DOM later.
286 window.setTimeout(function() { 315 window.setTimeout(function() {
287 document.querySelector('#webview-tag-container').appendChild(newwebview); 316 document.querySelector('#webview-tag-container').appendChild(newwebview);
288 }, 0); 317 }, 0);
289 }; 318 };
290 webview.addEventListener('newwindow', onNewWindow); 319 webview.addEventListener('newwindow', onNewWindow);
291 320
292 // Load a new window with the given name. 321 // Load a new window with the given name.
293 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName); 322 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
294 }; 323 }
324
325 // Tests that we fail gracefully if we try to discard() a <webview> on a
326 // newwindow event after the opener has been destroyed.
327 function testNewWindowDiscardAfterOpenerDestroyed() {
328 var testName = 'testNewWindowDiscardAfterOpenerDestroyed';
329 var webview = embedder.setUpGuest_('foobar');
330
331 var onNewWindow = function(e) {
332 embedder.assertCorrectEvent_(e, '');
333
334 // Remove the opener.
335 webview.parentNode.removeChild(webview);
336 // Pass in a timeout so we ensure the newwindow disposal codepath
337 // works properly.
338 //window.setTimeout(function() { embedder.test.succeed(); }, 0);
Fady Samuel 2014/09/09 23:01:33 Remove this line?
lazyboy 2014/09/09 23:18:36 Done.
339 window.setTimeout(function() {
340 // At this point the opener <webview> is gone.
341 // Trying to discard() will fail silencly.
Fady Samuel 2014/09/09 23:01:34 s/silency/silently
342 e.window.discard();
343 window.setTimeout(function() { embedder.test.succeed(); });
344 }, 0);
345
346 e.preventDefault();
347 };
348 webview.addEventListener('newwindow', onNewWindow);
349
350 // Load a new window with the given name.
351 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
352 }
295 353
296 function testNewWindowExecuteScript() { 354 function testNewWindowExecuteScript() {
297 var testName = 'testNewWindowExecuteScript'; 355 var testName = 'testNewWindowExecuteScript';
298 var webview = embedder.setUpGuest_('foobar'); 356 var webview = embedder.setUpGuest_('foobar');
299 357
300 var onNewWindow = function(e) { 358 var onNewWindow = function(e) {
301 chrome.test.log('Embedder notified on newwindow'); 359 chrome.test.log('Embedder notified on newwindow');
302 embedder.assertCorrectEvent_(e, ''); 360 embedder.assertCorrectEvent_(e, '');
303 361
304 var newwebview = document.createElement('webview'); 362 var newwebview = document.createElement('webview');
(...skipping 21 matching lines...) Expand all
326 webview.addEventListener('loadstop', function(e) { 384 webview.addEventListener('loadstop', function(e) {
327 webview.focus(); 385 webview.focus();
328 chrome.test.sendMessage('Loaded'); 386 chrome.test.sendMessage('Loaded');
329 }); 387 });
330 webview.addEventListener('newwindow', function(e) { 388 webview.addEventListener('newwindow', function(e) {
331 embedder.test.succeed(); 389 embedder.test.succeed();
332 }); 390 });
333 webview.src = embedder.guestWithLinkURL; 391 webview.src = embedder.guestWithLinkURL;
334 } 392 }
335 393
394 // Tests that if opener <webview> is gone with unattached guest, we
395 // don't see any error.
396 // This test also makes sure we destroy the unattached guests properly.
397 function testNewWindowOpenerDestroyedWhileUnattached() {
398 var testName = 'testNewWindowOpenerDestroyedBeforeAttach';
399 var webview = embedder.setUpGuest_('foobar');
400
401 var onNewWindow = function(e) {
402 embedder.assertCorrectEvent_(e, '');
403
404 // Remove the opener.
405 webview.parentNode.removeChild(webview);
406 // Pass in a timeout so we ensure the newwindow disposal codepath
407 // works properly.
408 window.setTimeout(function() { embedder.test.succeed(); }, 0);
409
410 e.preventDefault();
411 };
412 webview.addEventListener('newwindow', onNewWindow);
413
414 // Load a new window with the given name.
415 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
416 }
417
336 function testNewWindowWebRequest() { 418 function testNewWindowWebRequest() {
337 var testName = 'testNewWindowWebRequest'; 419 var testName = 'testNewWindowWebRequest';
338 var webview = embedder.setUpGuest_('foobar'); 420 var webview = embedder.setUpGuest_('foobar');
339 421
340 var onNewWindow = function(e) { 422 var onNewWindow = function(e) {
341 chrome.test.log('Embedder notified on newwindow'); 423 chrome.test.log('Embedder notified on newwindow');
342 embedder.assertCorrectEvent_(e, ''); 424 embedder.assertCorrectEvent_(e, '');
343 425
344 var newwebview = new WebView(); 426 var newwebview = new WebView();
345 var calledWebRequestEvent = false; 427 var calledWebRequestEvent = false;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 }; 566 };
485 }); 567 });
486 }; 568 };
487 webview.addEventListener('newwindow', onNewWindow); 569 webview.addEventListener('newwindow', onNewWindow);
488 570
489 // Load a new window with the given name. 571 // Load a new window with the given name.
490 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName); 572 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName);
491 } 573 }
492 574
493 embedder.test.testList = { 575 embedder.test.testList = {
576 'testNewWindowAttachAfterOpenerDestroyed':
577 testNewWindowAttachAfterOpenerDestroyed,
578 'testNewWindowClose': testNewWindowClose,
579 'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
580 'testNewWindowDeferredAttachment': testNewWindowDeferredAttachment,
581 'testNewWindowDiscardAfterOpenerDestroyed':
582 testNewWindowDiscardAfterOpenerDestroyed,
583 'testNewWindowExecuteScript': testNewWindowExecuteScript,
494 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence, 584 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence,
495 'testWebViewNameTakesPrecedence': testWebViewNameTakesPrecedence, 585 'testNewWindowNoName': testNewWindowNoName,
496 'testNoName': testNoName, 586 'testNewWindowOpenInNewTab': testNewWindowOpenInNewTab,
587 'testNewWindowOpenerDestroyedWhileUnattached':
588 testNewWindowOpenerDestroyedWhileUnattached,
497 'testNewWindowRedirect': testNewWindowRedirect, 589 'testNewWindowRedirect': testNewWindowRedirect,
498 'testNewWindowClose': testNewWindowClose,
499 'testNewWindowDeferredAttachment': testNewWindowDeferredAttachment,
500 'testNewWindowExecuteScript': testNewWindowExecuteScript,
501 'testNewWindowOpenInNewTab': testNewWindowOpenInNewTab,
502 'testNewWindowDeclarativeWebRequest': testNewWindowDeclarativeWebRequest,
503 'testNewWindowWebRequest': testNewWindowWebRequest, 590 'testNewWindowWebRequest': testNewWindowWebRequest,
504 'testNewWindowWebRequestCloseWindow': testNewWindowWebRequestCloseWindow, 591 'testNewWindowWebRequestCloseWindow': testNewWindowWebRequestCloseWindow,
505 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement 592 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement,
593 'testNewWindowWebViewNameTakesPrecedence':
594 testNewWindowWebViewNameTakesPrecedence
506 }; 595 };
507 596
508 onload = function() { 597 onload = function() {
509 chrome.test.getConfig(function(config) { 598 chrome.test.getConfig(function(config) {
510 embedder.setUp_(config); 599 embedder.setUp_(config);
511 chrome.test.sendMessage('Launched'); 600 chrome.test.sendMessage('Launched');
512 }); 601 });
513 }; 602 };
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