Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / executescript / in_frame / test.js
blob1c3ca0bd364067e606f2816b0973b58af97dce59
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;
9 var relativePath =
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')
15 return;
17 chrome.test.runTests([
18 function executeJavaScriptCodeInAllFramesShouldSucceed() {
19 var script_file = {};
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;
24 var counter = 0;
25 var totalTitles = '';
26 function eventListener(port) {
27 port.onMessage.addListener(function(data) {
28 counter++;
29 totalTitles += data.message;
30 });
32 chrome.runtime.onConnect.addListener(eventListener);
33 chrome.tabs.executeScript(tabId, script_file, pass(function() {
34 assertEq(counter, 5);
35 assertEq(totalTitles, 'frametest0test1test2test3');
36 chrome.runtime.onConnect.removeListener(eventListener);
37 }));
40 function insertCSSTextInAllFramesShouldSucceed() {
41 var css_file = {};
42 css_file.code = "p {display:none;}";
43 css_file.allFrames = true;
44 var newStyle = '';
45 var counter = 0;
46 function eventListener(port) {
47 port.onMessage.addListener(function(data) {
48 counter++;
49 newStyle += data.message;
50 });
52 chrome.runtime.onConnect.addListener(eventListener);
53 chrome.tabs.insertCSS(tabId, css_file, function() {
54 var script_file = {};
55 script_file.file = 'script.js';
56 script_file.allFrames = true;
57 chrome.tabs.executeScript(tabId, script_file,
58 pass(function() {
59 assertEq(newStyle, 'nonenonenonenone');
60 assertEq(counter, 4);
61 chrome.runtime.onConnect.removeListener(eventListener);
62 }));
63 });
65 ]);
66 });
68 chrome.test.getConfig(function(config) {
69 testUrl = testUrl.replace(/PORT/, config.testServer.port);
70 chrome.tabs.create({ url: testUrl });
71 });