OLD | NEW |
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.newWindowURL = ''; |
9 | 10 |
10 window.runTest = function(testName) { | 11 window.runTest = function(testName) { |
11 if (!embedder.test.testList[testName]) { | 12 if (!embedder.test.testList[testName]) { |
12 console.log('Incorrect testName: ' + testName); | 13 console.log('Incorrect testName: ' + testName); |
13 embedder.test.fail(); | 14 embedder.test.fail(); |
14 return; | 15 return; |
15 } | 16 } |
16 | 17 |
17 // Run the test. | 18 // Run the test. |
18 embedder.test.testList[testName](); | 19 embedder.test.testList[testName](); |
19 }; | 20 }; |
20 // window.* exported functions end. | 21 // window.* exported functions end. |
21 | 22 |
22 /** @private */ | 23 /** @private */ |
23 embedder.setUp_ = function(config) { | 24 embedder.setUp_ = function(config) { |
24 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port; | 25 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port; |
25 embedder.guestURL = embedder.baseGuestURL + | 26 embedder.guestURL = embedder.baseGuestURL + |
26 '/extensions/platform_apps/web_view/newwindow' + | 27 '/extensions/platform_apps/web_view/newwindow' + |
27 '/guest_opener.html'; | 28 '/guest_opener.html'; |
| 29 embedder.newWindowURL = embedder.baseGuestURL + |
| 30 '/extensions/platform_apps/web_view/newwindow' + |
| 31 '/newwindow.html'; |
28 chrome.test.log('Guest url is: ' + embedder.guestURL); | 32 chrome.test.log('Guest url is: ' + embedder.guestURL); |
29 }; | 33 }; |
30 | 34 |
31 /** @private */ | 35 /** @private */ |
32 embedder.setUpGuest_ = function(partitionName) { | 36 embedder.setUpGuest_ = function(partitionName) { |
33 document.querySelector('#webview-tag-container').innerHTML = | 37 document.querySelector('#webview-tag-container').innerHTML = |
34 '<webview style="width: 100px; height: 100px;"></webview>'; | 38 '<webview style="width: 100px; height: 100px;"></webview>'; |
35 var webview = document.querySelector('webview'); | 39 var webview = document.querySelector('webview'); |
36 if (partitionName) { | 40 if (partitionName) { |
37 webview.partition = partitionName; | 41 webview.partition = partitionName; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 } | 351 } |
348 }; | 352 }; |
349 }); | 353 }); |
350 }; | 354 }; |
351 webview.addEventListener('newwindow', onNewWindow); | 355 webview.addEventListener('newwindow', onNewWindow); |
352 | 356 |
353 // Load a new window with the given name. | 357 // Load a new window with the given name. |
354 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName); | 358 embedder.setUpNewWindowRequest_(webview, 'guest.html', '', testName); |
355 }; | 359 }; |
356 | 360 |
| 361 // This test verifies that a WebRequest event listener's lifetime is not |
| 362 // tied to the context in which it was created but instead at least the |
| 363 // lifetime of the embedder window to which it was attached. |
| 364 function testNewWindowWebRequestCloseWindow() { |
| 365 var current = chrome.app.window.current(); |
| 366 var requestCount = 0; |
| 367 var dataUrl = 'data:text/html,<body>foobar</body>'; |
| 368 |
| 369 var webview = new WebView(); |
| 370 webview.request.onBeforeRequest.addListener(function(e) { |
| 371 console.log('url: ' + e.url); |
| 372 ++requestCount; |
| 373 if (requestCount == 1) { |
| 374 // Close the existing window. |
| 375 // TODO(fsamuel): This is currently broken and this test is disabled. |
| 376 // Once we close the first window, the context in which the <webview> was |
| 377 // created is gone and so the <webview> is no longer a custom element. |
| 378 current.close(); |
| 379 // renavigate the webview. |
| 380 webview.src = embedder.newWindowURL; |
| 381 } else if (requestCount == 2) { |
| 382 embedder.test.succeed(); |
| 383 } |
| 384 }, {urls: ['<all_urls>']}); |
| 385 webview.addEventListener('loadcommit', function(e) { |
| 386 console.log('loadcommit: ' + e.url); |
| 387 }); |
| 388 webview.src = embedder.guestURL; |
| 389 |
| 390 chrome.app.window.create('newwindow.html', { |
| 391 width: 640, |
| 392 height: 480 |
| 393 }, function(newwindow) { |
| 394 newwindow.contentWindow.onload = function(evt) { |
| 395 newwindow.contentWindow.document.body.appendChild(webview); |
| 396 }; |
| 397 }); |
| 398 }; |
357 | 399 |
358 embedder.test.testList = { | 400 embedder.test.testList = { |
359 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence, | 401 'testNewWindowNameTakesPrecedence': testNewWindowNameTakesPrecedence, |
360 'testWebViewNameTakesPrecedence': testWebViewNameTakesPrecedence, | 402 'testWebViewNameTakesPrecedence': testWebViewNameTakesPrecedence, |
361 'testNoName': testNoName, | 403 'testNoName': testNoName, |
362 'testNewWindowRedirect': testNewWindowRedirect, | 404 'testNewWindowRedirect': testNewWindowRedirect, |
363 'testNewWindowClose': testNewWindowClose, | 405 'testNewWindowClose': testNewWindowClose, |
364 'testNewWindowExecuteScript': testNewWindowExecuteScript, | 406 'testNewWindowExecuteScript': testNewWindowExecuteScript, |
365 'testNewWindowWebRequest': testNewWindowWebRequest, | 407 'testNewWindowWebRequest': testNewWindowWebRequest, |
366 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement | 408 'testNewWindowWebRequestRemoveElement': testNewWindowWebRequestRemoveElement, |
| 409 'testNewWindowWebRequestCloseWindow': testNewWindowWebRequestCloseWindow |
367 }; | 410 }; |
368 | 411 |
369 onload = function() { | 412 onload = function() { |
370 chrome.test.getConfig(function(config) { | 413 chrome.test.getConfig(function(config) { |
371 embedder.setUp_(config); | 414 embedder.setUp_(config); |
372 chrome.test.sendMessage('Launched'); | 415 chrome.test.sendMessage('Launched'); |
373 }); | 416 }); |
374 }; | 417 }; |
OLD | NEW |