| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // To see chrome.test.log messages execute the test like this: | |
| 6 // $ out/gn/browser_tests --gtest_filter=*PanelTest* --vmodule=test_api=1 | |
| 7 chrome.test.log('executing background.js ...'); | |
| 8 | |
| 9 var oldNumberOfTabs; | |
| 10 var expectedWindowType; | |
| 11 chrome.test.runTests([ | |
| 12 function testPanelBrowsingInstance() { | |
| 13 chrome.test.log('counting all the tabs (before window.open) ...'); | |
| 14 chrome.tabs.query({}, function(tabs) { | |
| 15 oldNumberOfTabs = tabs.length; | |
| 16 chrome.test.log('oldNumberOfTabs = ' + oldNumberOfTabs); | |
| 17 | |
| 18 // Note that the background-subframe has to be navigated to foo.com, | |
| 19 // because otherwise we would get the following error when calling | |
| 20 // window.open from panel-subframe.js: | |
| 21 // Unsafe JavaScript attempt to initiate navigation for frame with URL | |
| 22 // 'about:blank' from frame with URL | |
| 23 // 'http://foo.com:41191/extensions/.../panel-subframe.html'. The frame | |
| 24 // attempting navigation is neither same-origin with the target, nor is | |
| 25 // it the target's parent or opener. | |
| 26 chrome.test.getConfig(function(config) { | |
| 27 expectedWindowType = config.customArg; | |
| 28 | |
| 29 var baseUri = 'http://foo.com:' + config.testServer.port + | |
| 30 '/extensions/api_test/window_open/panel_browsing_instance/'; | |
| 31 | |
| 32 chrome.test.log('navigating background-subframe ...'); | |
| 33 var subframe = document.getElementById('background-subframe-id'); | |
| 34 subframe.src = baseUri + | |
| 35 'background-subframe.html?extensionId=' + chrome.runtime.id; | |
| 36 | |
| 37 // background-subframe.js will send a message back to us - | |
| 38 // backgroundSubframeNavigated - we will continue execution | |
| 39 // in the callback below. | |
| 40 }); | |
| 41 }); | |
| 42 } | |
| 43 ]); | |
| 44 | |
| 45 chrome.runtime.onMessageExternal.addListener( | |
| 46 function(request, sender, sendResponse) { | |
| 47 if (request.backgroundSubframeNavigated) { | |
| 48 chrome.test.log('got callback from background-subframe.js ...'); | |
| 49 chrome.test.log('creating the panel window ...'); | |
| 50 chrome.windows.create( | |
| 51 { 'url': chrome.extension.getURL('panel.html'), 'type': 'panel' }, | |
| 52 function(win) { | |
| 53 chrome.test.assertEq(expectedWindowType, win.type); | |
| 54 }); | |
| 55 | |
| 56 // panel.js will navigate panel-subframe and then panel-subframe.js will | |
| 57 // call window.open and send a message back to us (windowOpened) - we will | |
| 58 // continue execution below. | |
| 59 } else if (request.windowOpened) { | |
| 60 chrome.test.log('got callback from panel-subframe.js ...'); | |
| 61 chrome.test.log('counting all the tabs (after window.open) ...'); | |
| 62 chrome.tabs.query({}, function(tabs) { | |
| 63 var newNumberOfTabs = tabs.length; | |
| 64 chrome.test.log('newNumberOfTabs = ' + newNumberOfTabs); | |
| 65 | |
| 66 switch (expectedWindowType) { | |
| 67 case 'panel': | |
| 68 chrome.test.assertEq(newNumberOfTabs, oldNumberOfTabs); | |
| 69 break; | |
| 70 case 'popup': | |
| 71 chrome.test.assertEq(newNumberOfTabs, oldNumberOfTabs + 1); | |
| 72 break; | |
| 73 default: | |
| 74 // Unexpected expected window type. | |
| 75 chrome.test.fail(); | |
| 76 } | |
| 77 chrome.test.notifyPass(); | |
| 78 }); | |
| 79 } | |
| 80 }); | |
| 81 | |
| 82 | |
| OLD | NEW |