OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/scoped_observer.h" | 6 #include "base/scoped_observer.h" |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 10 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 EXPECT_TRUE(HandleTestingStage(message)); | 375 EXPECT_TRUE(HandleTestingStage(message)); |
376 } | 376 } |
377 | 377 |
378 // In all cases (except for "Test Complete", in which case we already | 378 // In all cases (except for "Test Complete", in which case we already |
379 // break'ed), we reply with a continue message. | 379 // break'ed), we reply with a continue message. |
380 listener()->Reply("Continue"); | 380 listener()->Reply("Continue"); |
381 listener()->Reset(); | 381 listener()->Reset(); |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
| 385 // If this test grows, we should consolidate it and AdInjectionBrowserTest. |
| 386 class ExecuteScriptAdInjectionBrowserTest : public ExtensionBrowserTest { |
| 387 protected: |
| 388 virtual void SetUpOnMainThread() override; |
| 389 virtual void TearDownOnMainThread() override; |
| 390 }; |
| 391 |
| 392 void ExecuteScriptAdInjectionBrowserTest::SetUpOnMainThread() { |
| 393 ExtensionBrowserTest::SetUpOnMainThread(); |
| 394 |
| 395 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 396 embedded_test_server()->RegisterRequestHandler(base::Bind(&HandleRequest)); |
| 397 |
| 398 // Enable the activity log for this test. |
| 399 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(true); |
| 400 |
| 401 // Set the ad network database. |
| 402 AdNetworkDatabase::SetForTesting( |
| 403 scoped_ptr<AdNetworkDatabase>(new TestAdNetworkDatabase)); |
| 404 } |
| 405 |
| 406 void ExecuteScriptAdInjectionBrowserTest::TearDownOnMainThread() { |
| 407 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(false); |
| 408 ExtensionBrowserTest::TearDownOnMainThread(); |
| 409 } |
| 410 |
| 411 // Test that using chrome.tabs.executeScript doesn't circumvent our detection. |
| 412 // Since each type of injection is tested more thoroughly in the test above, |
| 413 // this test just needs to make sure that we detect anything from executeScript. |
| 414 IN_PROC_BROWSER_TEST_F(ExecuteScriptAdInjectionBrowserTest, |
| 415 ExecuteScriptAdInjection) { |
| 416 const Extension* extension = |
| 417 LoadExtension(test_data_dir_.AppendASCII("activity_log") |
| 418 .AppendASCII("execute_script_ad_injection")); |
| 419 ASSERT_TRUE(extension); |
| 420 |
| 421 ExtensionTestMessageListener listener(false); // Won't reply. |
| 422 listener.set_extension_id(extension->id()); |
| 423 ActivityLogObserver observer(profile()); |
| 424 observer.enable(); |
| 425 |
| 426 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL("/")); |
| 427 |
| 428 // The extension sends a "Done" message when the script has executed. |
| 429 listener.WaitUntilSatisfied(); |
| 430 EXPECT_EQ("Done", listener.message()); |
| 431 |
| 432 // We should have injected an ad. |
| 433 EXPECT_EQ(Action::INJECTION_NEW_AD, observer.injection_type()); |
| 434 EXPECT_FALSE(observer.found_multiple_injections()); |
| 435 } |
| 436 |
385 // TODO(rdevlin.cronin): We test a good amount of ways of injecting ads with | 437 // TODO(rdevlin.cronin): We test a good amount of ways of injecting ads with |
386 // the above test, but more is better in testing. | 438 // the above test, but more is better in testing. |
387 // See crbug.com/357204. | 439 // See crbug.com/357204. |
388 | 440 |
389 } // namespace extensions | 441 } // namespace extensions |
OLD | NEW |