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
3 // found in the LICENSE file.
5 var pass
= chrome
.test
.callbackPass
;
6 var fail
= chrome
.test
.callbackFail
;
7 var assertEq
= chrome
.test
.assertEq
;
8 var assertTrue
= chrome
.test
.assertTrue
;
10 '/extensions/api_test/executescript/in_frame/test_executescript.html';
11 var testUrl
= 'http://a.com:PORT' + relativePath
;
13 chrome
.tabs
.onUpdated
.addListener(function(tabId
, changeInfo
, tab
) {
14 if (changeInfo
.status
!= 'complete')
17 chrome
.test
.runTests([
18 function executeJavaScriptCodeInAllFramesShouldSucceed() {
20 script_file
.code
= "var extensionPort = chrome.runtime.connect();";
21 script_file
.code
= script_file
.code
+
22 "extensionPort.postMessage({message: document.title});";
23 script_file
.allFrames
= true;
26 function eventListener(port
) {
27 port
.onMessage
.addListener(function(data
) {
29 totalTitles
+= data
.message
;
32 chrome
.runtime
.onConnect
.addListener(eventListener
);
33 chrome
.tabs
.executeScript(tabId
, script_file
, pass(function() {
35 assertEq(totalTitles
, 'frametest0test1test2test3');
36 chrome
.runtime
.onConnect
.removeListener(eventListener
);
40 function insertCSSTextInAllFramesShouldSucceed() {
42 css_file
.code
= "p {display:none;}";
43 css_file
.allFrames
= true;
46 function eventListener(port
) {
47 port
.onMessage
.addListener(function(data
) {
49 newStyle
+= data
.message
;
52 chrome
.runtime
.onConnect
.addListener(eventListener
);
53 chrome
.tabs
.insertCSS(tabId
, css_file
, function() {
55 script_file
.file
= 'script.js';
56 script_file
.allFrames
= true;
57 chrome
.tabs
.executeScript(tabId
, script_file
,
59 assertEq(newStyle
, 'nonenonenonenone');
61 chrome
.runtime
.onConnect
.removeListener(eventListener
);
68 chrome
.test
.getConfig(function(config
) {
69 testUrl
= testUrl
.replace(/PORT/, config
.testServer
.port
);
70 chrome
.tabs
.create({ url
: testUrl
});