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> |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 38 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
39 #endif | 39 #endif |
40 | 40 |
41 using content::BrowserThread; | 41 using content::BrowserThread; |
42 | 42 |
43 namespace extensions { | 43 namespace extensions { |
44 | 44 |
45 class FullStreamUIPolicyTest : public testing::Test { | 45 class FullStreamUIPolicyTest : public testing::Test { |
46 public: | 46 public: |
47 FullStreamUIPolicyTest() | 47 FullStreamUIPolicyTest() |
48 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 48 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
49 saved_cmdline_(base::CommandLine::NO_PROGRAM) { | |
50 #if defined OS_CHROMEOS | 49 #if defined OS_CHROMEOS |
51 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 50 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
52 #endif | 51 #endif |
53 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 52 base::CommandLine no_program_command_line(base::CommandLine::NO_PROGRAM); |
54 saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | |
55 profile_.reset(new TestingProfile()); | 53 profile_.reset(new TestingProfile()); |
56 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 54 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
57 switches::kEnableExtensionActivityLogging); | 55 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); |
58 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 56 command_line->AppendSwitch(switches::kEnableExtensionActivityLogTesting); |
59 switches::kEnableExtensionActivityLogTesting); | |
60 extension_service_ = static_cast<TestExtensionSystem*>( | 57 extension_service_ = static_cast<TestExtensionSystem*>( |
61 ExtensionSystem::Get(profile_.get()))->CreateExtensionService | 58 ExtensionSystem::Get(profile_.get()))->CreateExtensionService |
62 (&command_line, base::FilePath(), false); | 59 (&no_program_command_line, base::FilePath(), false); |
63 } | 60 } |
64 | 61 |
65 ~FullStreamUIPolicyTest() override { | 62 ~FullStreamUIPolicyTest() override { |
66 #if defined OS_CHROMEOS | 63 #if defined OS_CHROMEOS |
67 test_user_manager_.reset(); | 64 test_user_manager_.reset(); |
68 #endif | 65 #endif |
69 base::RunLoop().RunUntilIdle(); | 66 base::RunLoop().RunUntilIdle(); |
70 profile_.reset(NULL); | 67 profile_.reset(NULL); |
71 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
72 // Restore the original command line and undo the affects of SetUp(). | |
73 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | |
74 } | 69 } |
75 | 70 |
76 // A wrapper function for CheckReadFilteredData, so that we don't need to | 71 // A wrapper function for CheckReadFilteredData, so that we don't need to |
77 // enter empty string values for parameters we don't care about. | 72 // enter empty string values for parameters we don't care about. |
78 void CheckReadData(ActivityLogDatabasePolicy* policy, | 73 void CheckReadData(ActivityLogDatabasePolicy* policy, |
79 const std::string& extension_id, | 74 const std::string& extension_id, |
80 int day, | 75 int day, |
81 const base::Callback<void( | 76 const base::Callback<void( |
82 std::unique_ptr<Action::ActionVector>)>& checker) { | 77 std::unique_ptr<Action::ActionVector>)>& checker) { |
83 CheckReadFilteredData( | 78 CheckReadFilteredData( |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 "http://www.google1.com/", | 431 "http://www.google1.com/", |
437 "Google1", | 432 "Google1", |
438 "http://www.args-url1.com/"); | 433 "http://www.args-url1.com/"); |
439 ASSERT_EQ(2, actions->at(1)->action_id()); | 434 ASSERT_EQ(2, actions->at(1)->action_id()); |
440 } | 435 } |
441 | 436 |
442 protected: | 437 protected: |
443 ExtensionService* extension_service_; | 438 ExtensionService* extension_service_; |
444 std::unique_ptr<TestingProfile> profile_; | 439 std::unique_ptr<TestingProfile> profile_; |
445 content::TestBrowserThreadBundle thread_bundle_; | 440 content::TestBrowserThreadBundle thread_bundle_; |
446 // Used to preserve a copy of the original 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 | 441 |
452 #if defined OS_CHROMEOS | 442 #if defined OS_CHROMEOS |
453 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 443 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
454 chromeos::ScopedTestCrosSettings test_cros_settings_; | 444 chromeos::ScopedTestCrosSettings test_cros_settings_; |
455 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 445 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
456 #endif | 446 #endif |
457 }; | 447 }; |
458 | 448 |
459 TEST_F(FullStreamUIPolicyTest, Construct) { | 449 TEST_F(FullStreamUIPolicyTest, Construct) { |
460 ActivityLogDatabasePolicy* policy = new FullStreamUIPolicy(profile_.get()); | 450 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); | 1049 action_ids.push_back(3); |
1060 action_ids.push_back(4); | 1050 action_ids.push_back(4); |
1061 CheckRemoveActions( | 1051 CheckRemoveActions( |
1062 policy, action_ids, base::Bind(&FullStreamUIPolicyTest::Action2Deleted)); | 1052 policy, action_ids, base::Bind(&FullStreamUIPolicyTest::Action2Deleted)); |
1063 action_ids.clear(); | 1053 action_ids.clear(); |
1064 | 1054 |
1065 policy->Close(); | 1055 policy->Close(); |
1066 } | 1056 } |
1067 | 1057 |
1068 } // namespace extensions | 1058 } // namespace extensions |
OLD | NEW |