OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 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. |
| 11 |
| 12 var didInject = false; |
| 13 var code = |
| 14 "document.body.appendChild(document.createElement('iframe')).src = " + |
| 15 "'http://www.known-ads.adnetwork';"; |
| 16 |
| 17 /** |
| 18 * Injects an ad into the tab using chrome.tabs.executeScript(). |
| 19 * @param {number} tabId The id of the tab to inject into. |
| 20 */ |
| 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 }); |
| 30 } |
| 31 } |
| 32 |
| 33 // Inject the script when the tab is updated. |
| 34 chrome.tabs.onUpdated.addListener(injectScript); |
OLD | NEW |