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

Unified Diff: chrome/browser/extensions/activity_log/ad_injection_browsertest.cc

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
« no previous file with comments | « no previous file | chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/activity_log/ad_injection_browsertest.cc
diff --git a/chrome/browser/extensions/activity_log/ad_injection_browsertest.cc b/chrome/browser/extensions/activity_log/ad_injection_browsertest.cc
index a0a23eb23f41a755da7c47ec51b271cb9efdd3c8..22e6d6cdecc1e3f545fd64532d157438eb4bf972 100644
--- a/chrome/browser/extensions/activity_log/ad_injection_browsertest.cc
+++ b/chrome/browser/extensions/activity_log/ad_injection_browsertest.cc
@@ -382,6 +382,58 @@ IN_PROC_BROWSER_TEST_F(AdInjectionBrowserTest, DetectAdInjections) {
}
}
+// If this test grows, we should consolidate it and AdInjectionBrowserTest.
+class ExecuteScriptAdInjectionBrowserTest : public ExtensionBrowserTest {
+ protected:
+ virtual void SetUpOnMainThread() override;
+ virtual void TearDownOnMainThread() override;
+};
+
+void ExecuteScriptAdInjectionBrowserTest::SetUpOnMainThread() {
+ ExtensionBrowserTest::SetUpOnMainThread();
+
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+ embedded_test_server()->RegisterRequestHandler(base::Bind(&HandleRequest));
+
+ // Enable the activity log for this test.
+ ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(true);
+
+ // Set the ad network database.
+ AdNetworkDatabase::SetForTesting(
+ scoped_ptr<AdNetworkDatabase>(new TestAdNetworkDatabase));
+}
+
+void ExecuteScriptAdInjectionBrowserTest::TearDownOnMainThread() {
+ ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(false);
+ ExtensionBrowserTest::TearDownOnMainThread();
+}
+
+// Test that using chrome.tabs.executeScript doesn't circumvent our detection.
+// Since each type of injection is tested more thoroughly in the test above,
+// this test just needs to make sure that we detect anything from executeScript.
+IN_PROC_BROWSER_TEST_F(ExecuteScriptAdInjectionBrowserTest,
+ ExecuteScriptAdInjection) {
+ const Extension* extension =
+ LoadExtension(test_data_dir_.AppendASCII("activity_log")
+ .AppendASCII("execute_script_ad_injection"));
+ ASSERT_TRUE(extension);
+
+ ExtensionTestMessageListener listener(false); // Won't reply.
+ listener.set_extension_id(extension->id());
+ ActivityLogObserver observer(profile());
+ observer.enable();
+
+ ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL("/"));
+
+ // The extension sends a "Done" message when the script has executed.
+ listener.WaitUntilSatisfied();
+ EXPECT_EQ("Done", listener.message());
+
+ // We should have injected an ad.
+ EXPECT_EQ(Action::INJECTION_NEW_AD, observer.injection_type());
+ EXPECT_FALSE(observer.found_multiple_injections());
+}
+
// TODO(rdevlin.cronin): We test a good amount of ways of injecting ads with
// the above test, but more is better in testing.
// See crbug.com/357204.
« no previous file with comments | « no previous file | chrome/test/data/extensions/activity_log/execute_script_ad_injection/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698