| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/fullstream_ui_policy.h" | 5 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/test/command_line_test_util.h" |
| 20 #include "base/test/simple_test_clock.h" | 21 #include "base/test/simple_test_clock.h" |
| 21 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
| 22 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 24 #include "chrome/browser/extensions/activity_log/activity_log.h" | 25 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 25 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
| 26 #include "chrome/browser/extensions/test_extension_system.h" | 27 #include "chrome/browser/extensions/test_extension_system.h" |
| 27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "extensions/common/extension_builder.h" | 33 #include "extensions/common/extension_builder.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 35 |
| 35 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 37 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
| 37 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 38 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 39 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 using content::BrowserThread; | 42 using content::BrowserThread; |
| 42 | 43 |
| 43 namespace extensions { | 44 namespace extensions { |
| 44 | 45 |
| 45 class FullStreamUIPolicyTest : public testing::Test { | 46 class FullStreamUIPolicyTest : public testing::Test { |
| 46 public: | 47 public: |
| 47 FullStreamUIPolicyTest() | 48 FullStreamUIPolicyTest() |
| 48 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 49 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 49 saved_cmdline_(base::CommandLine::NO_PROGRAM) { | |
| 50 #if defined OS_CHROMEOS | 50 #if defined OS_CHROMEOS |
| 51 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 51 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 52 #endif | 52 #endif |
| 53 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 53 base::CommandLine no_program_command_line(base::CommandLine::NO_PROGRAM); |
| 54 saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | |
| 55 profile_.reset(new TestingProfile()); | 54 profile_.reset(new TestingProfile()); |
| 56 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 55 base::CommandLine* command_line = |
| 57 switches::kEnableExtensionActivityLogging); | 56 scoped_command_line_.GetProcessCommandLine(); |
| 58 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 57 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); |
| 59 switches::kEnableExtensionActivityLogTesting); | 58 command_line->AppendSwitch(switches::kEnableExtensionActivityLogTesting); |
| 60 extension_service_ = static_cast<TestExtensionSystem*>( | 59 extension_service_ = static_cast<TestExtensionSystem*>( |
| 61 ExtensionSystem::Get(profile_.get()))->CreateExtensionService | 60 ExtensionSystem::Get(profile_.get()))->CreateExtensionService |
| 62 (&command_line, base::FilePath(), false); | 61 (&no_program_command_line, base::FilePath(), false); |
| 63 } | 62 } |
| 64 | 63 |
| 65 ~FullStreamUIPolicyTest() override { | 64 ~FullStreamUIPolicyTest() override { |
| 66 #if defined OS_CHROMEOS | 65 #if defined OS_CHROMEOS |
| 67 test_user_manager_.reset(); | 66 test_user_manager_.reset(); |
| 68 #endif | 67 #endif |
| 69 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
| 70 profile_.reset(NULL); | 69 profile_.reset(NULL); |
| 71 base::RunLoop().RunUntilIdle(); | 70 base::RunLoop().RunUntilIdle(); |
| 72 // Restore the original command line and undo the affects of SetUp(). | |
| 73 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | |
| 74 } | 71 } |
| 75 | 72 |
| 76 // A wrapper function for CheckReadFilteredData, so that we don't need to | 73 // A wrapper function for CheckReadFilteredData, so that we don't need to |
| 77 // enter empty string values for parameters we don't care about. | 74 // enter empty string values for parameters we don't care about. |
| 78 void CheckReadData(ActivityLogDatabasePolicy* policy, | 75 void CheckReadData(ActivityLogDatabasePolicy* policy, |
| 79 const std::string& extension_id, | 76 const std::string& extension_id, |
| 80 int day, | 77 int day, |
| 81 const base::Callback<void( | 78 const base::Callback<void( |
| 82 std::unique_ptr<Action::ActionVector>)>& checker) { | 79 std::unique_ptr<Action::ActionVector>)>& checker) { |
| 83 CheckReadFilteredData( | 80 CheckReadFilteredData( |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 "http://www.google1.com/", | 433 "http://www.google1.com/", |
| 437 "Google1", | 434 "Google1", |
| 438 "http://www.args-url1.com/"); | 435 "http://www.args-url1.com/"); |
| 439 ASSERT_EQ(2, actions->at(1)->action_id()); | 436 ASSERT_EQ(2, actions->at(1)->action_id()); |
| 440 } | 437 } |
| 441 | 438 |
| 442 protected: | 439 protected: |
| 443 ExtensionService* extension_service_; | 440 ExtensionService* extension_service_; |
| 444 std::unique_ptr<TestingProfile> profile_; | 441 std::unique_ptr<TestingProfile> profile_; |
| 445 content::TestBrowserThreadBundle thread_bundle_; | 442 content::TestBrowserThreadBundle thread_bundle_; |
| 446 // Used to preserve a copy of the original command line. | 443 base::test::ScopedCommandLine scoped_command_line_; |
| 447 // The test framework will do this itself as well. However, by then, | |
| 448 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | |
| 449 // TearDown(). | |
| 450 base::CommandLine saved_cmdline_; | |
| 451 | 444 |
| 452 #if defined OS_CHROMEOS | 445 #if defined OS_CHROMEOS |
| 453 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 446 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 454 chromeos::ScopedTestCrosSettings test_cros_settings_; | 447 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 455 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 448 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 456 #endif | 449 #endif |
| 457 }; | 450 }; |
| 458 | 451 |
| 459 TEST_F(FullStreamUIPolicyTest, Construct) { | 452 TEST_F(FullStreamUIPolicyTest, Construct) { |
| 460 ActivityLogDatabasePolicy* policy = new FullStreamUIPolicy(profile_.get()); | 453 ActivityLogDatabasePolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 action_ids.push_back(3); | 1052 action_ids.push_back(3); |
| 1060 action_ids.push_back(4); | 1053 action_ids.push_back(4); |
| 1061 CheckRemoveActions( | 1054 CheckRemoveActions( |
| 1062 policy, action_ids, base::Bind(&FullStreamUIPolicyTest::Action2Deleted)); | 1055 policy, action_ids, base::Bind(&FullStreamUIPolicyTest::Action2Deleted)); |
| 1063 action_ids.clear(); | 1056 action_ids.clear(); |
| 1064 | 1057 |
| 1065 policy->Close(); | 1058 policy->Close(); |
| 1066 } | 1059 } |
| 1067 | 1060 |
| 1068 } // namespace extensions | 1061 } // namespace extensions |
| OLD | NEW |