Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / extensions / activity_log / execute_script_ad_injection / background.js
blob9ee6925f4aa49084dbca121c37d835c1053295e1
1 // Copyright 2014 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 // Test that injecting an ad via tabs.executeScript doesn't circumvent
6 // detection. This is a very simple test, since the methods are tested much
7 // more extensively in the
8 // chrome/test/data/extensions/activity_log/ad_injection.
9 // If this test grows, it could use the same setup as that test, but there's no
10 // need for that at the time.
12 var didInject = false;
13 var code =
14 "document.body.appendChild(document.createElement('iframe')).src = " +
15 "'http://www.known-ads.adnetwork';";
17 /**
18 * Injects an ad into the tab using chrome.tabs.executeScript().
19 * @param {number} tabId The id of the tab to inject into.
21 function injectScript(tabId) {
22 console.log('injectScript');
23 if (!didInject) {
24 console.log('injecting');
25 didInject = true;
26 chrome.tabs.executeScript(tabId, {code: code}, function() {
27 console.log('injected');
28 chrome.test.sendMessage('Done');
29 });
33 // Inject the script when the tab is updated.
34 chrome.tabs.onUpdated.addListener(injectScript);