Index: chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js |
diff --git a/chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js b/chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ee6925f4aa49084dbca121c37d835c1053295e1 |
--- /dev/null |
+++ b/chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js |
@@ -0,0 +1,34 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Test that injecting an ad via tabs.executeScript doesn't circumvent |
+// detection. This is a very simple test, since the methods are tested much |
+// more extensively in the |
+// chrome/test/data/extensions/activity_log/ad_injection. |
+// If this test grows, it could use the same setup as that test, but there's no |
+// need for that at the time. |
+ |
+var didInject = false; |
+var code = |
+ "document.body.appendChild(document.createElement('iframe')).src = " + |
+ "'http://www.known-ads.adnetwork';"; |
+ |
+/** |
+ * Injects an ad into the tab using chrome.tabs.executeScript(). |
+ * @param {number} tabId The id of the tab to inject into. |
+ */ |
+function injectScript(tabId) { |
+ console.log('injectScript'); |
+ if (!didInject) { |
+ console.log('injecting'); |
+ didInject = true; |
+ chrome.tabs.executeScript(tabId, {code: code}, function() { |
+ console.log('injected'); |
+ chrome.test.sendMessage('Done'); |
+ }); |
+ } |
+} |
+ |
+// Inject the script when the tab is updated. |
+chrome.tabs.onUpdated.addListener(injectScript); |