Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5068)

Unified Diff: chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js

Issue 641043003: Add ActivityLog tests for chrome.tabs.executeScript() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698