| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "chrome/browser/extensions/activity_log/activity_log.h" | 7 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 8 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" | 8 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/test_extension_system.h" | 10 #include "chrome/browser/extensions/test_extension_system.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 void TearDown() override { | 38 void TearDown() override { |
| 39 #if defined OS_CHROMEOS | 39 #if defined OS_CHROMEOS |
| 40 test_user_manager_.reset(); | 40 test_user_manager_.reset(); |
| 41 #endif | 41 #endif |
| 42 ChromeRenderViewHostTestHarness::TearDown(); | 42 ChromeRenderViewHostTestHarness::TearDown(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 #if defined OS_CHROMEOS | 45 #if defined OS_CHROMEOS |
| 46 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 46 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 47 chromeos::ScopedTestCrosSettings test_cros_settings_; | 47 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 48 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 48 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 49 #endif | 49 #endif |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 TEST_F(ActivityLogEnabledTest, NoSwitch) { | 52 TEST_F(ActivityLogEnabledTest, NoSwitch) { |
| 53 scoped_ptr<TestingProfile> profile( | 53 std::unique_ptr<TestingProfile> profile( |
| 54 static_cast<TestingProfile*>(CreateBrowserContext())); | 54 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 55 EXPECT_FALSE( | 55 EXPECT_FALSE( |
| 56 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 56 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 57 | 57 |
| 58 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); | 58 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); |
| 59 | 59 |
| 60 EXPECT_EQ(0, | 60 EXPECT_EQ(0, |
| 61 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 61 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 62 EXPECT_FALSE(activity_log->IsDatabaseEnabled()); | 62 EXPECT_FALSE(activity_log->IsDatabaseEnabled()); |
| 63 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); | 63 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) { | 66 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) { |
| 67 scoped_ptr<TestingProfile> profile1( | 67 std::unique_ptr<TestingProfile> profile1( |
| 68 static_cast<TestingProfile*>(CreateBrowserContext())); | 68 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 69 scoped_ptr<TestingProfile> profile2( | 69 std::unique_ptr<TestingProfile> profile2( |
| 70 static_cast<TestingProfile*>(CreateBrowserContext())); | 70 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 71 | 71 |
| 72 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 72 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 73 base::CommandLine saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | 73 base::CommandLine saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); |
| 74 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 74 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 75 switches::kEnableExtensionActivityLogging); | 75 switches::kEnableExtensionActivityLogging); |
| 76 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); | 76 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); |
| 77 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | 77 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; |
| 78 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); | 78 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); |
| 79 | 79 |
| 80 EXPECT_EQ(0, | 80 EXPECT_EQ(0, |
| 81 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 81 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 82 EXPECT_EQ(0, | 82 EXPECT_EQ(0, |
| 83 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 83 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 84 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); | 84 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); |
| 85 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); | 85 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); |
| 86 EXPECT_FALSE(activity_log1->IsWatchdogAppActive()); | 86 EXPECT_FALSE(activity_log1->IsWatchdogAppActive()); |
| 87 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); | 87 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST_F(ActivityLogEnabledTest, PrefSwitch) { | 90 TEST_F(ActivityLogEnabledTest, PrefSwitch) { |
| 91 scoped_ptr<TestingProfile> profile1( | 91 std::unique_ptr<TestingProfile> profile1( |
| 92 static_cast<TestingProfile*>(CreateBrowserContext())); | 92 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 93 scoped_ptr<TestingProfile> profile2( | 93 std::unique_ptr<TestingProfile> profile2( |
| 94 static_cast<TestingProfile*>(CreateBrowserContext())); | 94 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 95 scoped_ptr<TestingProfile> profile3( | 95 std::unique_ptr<TestingProfile> profile3( |
| 96 static_cast<TestingProfile*>(CreateBrowserContext())); | 96 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 97 | 97 |
| 98 EXPECT_EQ(0, | 98 EXPECT_EQ(0, |
| 99 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 99 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 100 EXPECT_EQ(0, | 100 EXPECT_EQ(0, |
| 101 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 101 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 102 EXPECT_EQ(0, | 102 EXPECT_EQ(0, |
| 103 profile3->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 103 profile3->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 104 | 104 |
| 105 profile1->GetPrefs()->SetInteger(prefs::kWatchdogExtensionActive, 1); | 105 profile1->GetPrefs()->SetInteger(prefs::kWatchdogExtensionActive, 1); |
| 106 profile3->GetPrefs()->SetInteger(prefs::kWatchdogExtensionActive, 2); | 106 profile3->GetPrefs()->SetInteger(prefs::kWatchdogExtensionActive, 2); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 EXPECT_TRUE(activity_log1->IsWatchdogAppActive()); | 117 EXPECT_TRUE(activity_log1->IsWatchdogAppActive()); |
| 118 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); | 118 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); |
| 119 EXPECT_TRUE(activity_log3->IsWatchdogAppActive()); | 119 EXPECT_TRUE(activity_log3->IsWatchdogAppActive()); |
| 120 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); | 120 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); |
| 121 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); | 121 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); |
| 122 EXPECT_TRUE(activity_log3->IsDatabaseEnabled()); | 122 EXPECT_TRUE(activity_log3->IsDatabaseEnabled()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) { | 125 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) { |
| 126 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 126 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 127 scoped_ptr<TestingProfile> profile1( | 127 std::unique_ptr<TestingProfile> profile1( |
| 128 static_cast<TestingProfile*>(CreateBrowserContext())); | 128 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 129 scoped_ptr<TestingProfile> profile2( | 129 std::unique_ptr<TestingProfile> profile2( |
| 130 static_cast<TestingProfile*>(CreateBrowserContext())); | 130 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 131 // Extension service is destroyed by the profile. | 131 // Extension service is destroyed by the profile. |
| 132 ExtensionService* extension_service1 = | 132 ExtensionService* extension_service1 = |
| 133 static_cast<TestExtensionSystem*>( | 133 static_cast<TestExtensionSystem*>( |
| 134 ExtensionSystem::Get(profile1.get()))->CreateExtensionService( | 134 ExtensionSystem::Get(profile1.get()))->CreateExtensionService( |
| 135 &command_line, base::FilePath(), false); | 135 &command_line, base::FilePath(), false); |
| 136 static_cast<TestExtensionSystem*>( | 136 static_cast<TestExtensionSystem*>( |
| 137 ExtensionSystem::Get(profile1.get()))->SetReady(); | 137 ExtensionSystem::Get(profile1.get()))->SetReady(); |
| 138 | 138 |
| 139 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); | 139 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); |
| 140 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); | 140 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 EXPECT_FALSE(activity_log1->IsDatabaseEnabled()); | 228 EXPECT_FALSE(activity_log1->IsDatabaseEnabled()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 TEST_F(ActivityLogEnabledTest, AppAndCommandLine) { | 231 TEST_F(ActivityLogEnabledTest, AppAndCommandLine) { |
| 232 // Set the command line switch. | 232 // Set the command line switch. |
| 233 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 233 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 234 base::CommandLine saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | 234 base::CommandLine saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); |
| 235 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 235 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 236 switches::kEnableExtensionActivityLogging); | 236 switches::kEnableExtensionActivityLogging); |
| 237 | 237 |
| 238 scoped_ptr<TestingProfile> profile( | 238 std::unique_ptr<TestingProfile> profile( |
| 239 static_cast<TestingProfile*>(CreateBrowserContext())); | 239 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 240 // Extension service is destroyed by the profile. | 240 // Extension service is destroyed by the profile. |
| 241 ExtensionService* extension_service = | 241 ExtensionService* extension_service = |
| 242 static_cast<TestExtensionSystem*>( | 242 static_cast<TestExtensionSystem*>( |
| 243 ExtensionSystem::Get(profile.get()))->CreateExtensionService( | 243 ExtensionSystem::Get(profile.get()))->CreateExtensionService( |
| 244 &command_line, base::FilePath(), false); | 244 &command_line, base::FilePath(), false); |
| 245 static_cast<TestExtensionSystem*>( | 245 static_cast<TestExtensionSystem*>( |
| 246 ExtensionSystem::Get(profile.get()))->SetReady(); | 246 ExtensionSystem::Get(profile.get()))->SetReady(); |
| 247 | 247 |
| 248 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); | 248 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); |
| 249 // Allow Activity Log to install extension tracker. | 249 // Allow Activity Log to install extension tracker. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 280 EXPECT_TRUE(activity_log->IsDatabaseEnabled()); | 280 EXPECT_TRUE(activity_log->IsDatabaseEnabled()); |
| 281 EXPECT_EQ(0, | 281 EXPECT_EQ(0, |
| 282 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 282 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 283 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); | 283 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); |
| 284 | 284 |
| 285 // Cleanup. | 285 // Cleanup. |
| 286 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | 286 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; |
| 287 } | 287 } |
| 288 | 288 |
| 289 } // namespace extensions | 289 } // namespace extensions |
| OLD | NEW |