| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/activity_log/activity_log.h" | 5 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 17 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
| 18 #include "chrome/browser/extensions/activity_log/activity_log_task_runner.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/test_extension_system.h" | 20 #include "chrome/browser/extensions/test_extension_system.h" |
| 20 #include "chrome/browser/prerender/prerender_handle.h" | 21 #include "chrome/browser/prerender/prerender_handle.h" |
| 21 #include "chrome/browser/prerender/prerender_manager.h" | 22 #include "chrome/browser/prerender/prerender_manager.h" |
| 22 #include "chrome/browser/prerender/prerender_manager_factory.h" | 23 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 23 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 26 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 | 53 |
| 53 } // namespace | 54 } // namespace |
| 54 | 55 |
| 55 namespace extensions { | 56 namespace extensions { |
| 56 | 57 |
| 57 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 58 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
| 58 protected: | 59 protected: |
| 59 virtual bool enable_activity_logging_switch() const { return true; } | 60 virtual bool enable_activity_logging_switch() const { return true; } |
| 60 void SetUp() override { | 61 void SetUp() override { |
| 61 ChromeRenderViewHostTestHarness::SetUp(); | 62 ChromeRenderViewHostTestHarness::SetUp(); |
| 63 |
| 64 SetActivityLogTaskRunnerForTesting( |
| 65 base::ThreadTaskRunnerHandle::Get().get()); |
| 66 |
| 62 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 67 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 63 if (enable_activity_logging_switch()) { | 68 if (enable_activity_logging_switch()) { |
| 64 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 69 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 65 switches::kEnableExtensionActivityLogging); | 70 switches::kEnableExtensionActivityLogging); |
| 66 } | 71 } |
| 67 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 72 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 68 switches::kEnableExtensionActivityLogTesting); | 73 switches::kEnableExtensionActivityLogTesting); |
| 69 extension_service_ = static_cast<TestExtensionSystem*>( | 74 extension_service_ = static_cast<TestExtensionSystem*>( |
| 70 ExtensionSystem::Get(profile()))->CreateExtensionService | 75 ExtensionSystem::Get(profile()))->CreateExtensionService |
| 71 (&command_line, base::FilePath(), false); | 76 (&command_line, base::FilePath(), false); |
| 72 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void TearDown() override { | 80 void TearDown() override { |
| 76 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
| 82 SetActivityLogTaskRunnerForTesting(nullptr); |
| 77 ChromeRenderViewHostTestHarness::TearDown(); | 83 ChromeRenderViewHostTestHarness::TearDown(); |
| 78 } | 84 } |
| 79 | 85 |
| 80 static void RetrieveActions_LogAndFetchActions0( | 86 static void RetrieveActions_LogAndFetchActions0( |
| 81 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { | 87 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| 82 ASSERT_EQ(0, static_cast<int>(i->size())); | 88 ASSERT_EQ(0, static_cast<int>(i->size())); |
| 83 } | 89 } |
| 84 | 90 |
| 85 static void RetrieveActions_LogAndFetchActions2( | 91 static void RetrieveActions_LogAndFetchActions2( |
| 86 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { | 92 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); | 435 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); |
| 430 // ... but not those of the watchdog app. | 436 // ... but not those of the watchdog app. |
| 431 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); | 437 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); |
| 432 extension_service_->DisableExtension(activity_log_extension->id(), | 438 extension_service_->DisableExtension(activity_log_extension->id(), |
| 433 Extension::DISABLE_USER_ACTION); | 439 Extension::DISABLE_USER_ACTION); |
| 434 // Disabling the watchdog app means that we're back to never logging anything. | 440 // Disabling the watchdog app means that we're back to never logging anything. |
| 435 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); | 441 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); |
| 436 } | 442 } |
| 437 | 443 |
| 438 } // namespace extensions | 444 } // namespace extensions |
| OLD | NEW |