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 "base/test/command_line_test_util.h" |
7 #include "chrome/browser/extensions/activity_log/activity_log.h" | 8 #include "chrome/browser/extensions/activity_log/activity_log.h" |
8 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" | 9 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/test_extension_system.h" | 11 #include "chrome/browser/extensions/test_extension_system.h" |
11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
16 #include "extensions/browser/uninstall_reason.h" | 17 #include "extensions/browser/uninstall_reason.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 EXPECT_FALSE(activity_log->IsDatabaseEnabled()); | 63 EXPECT_FALSE(activity_log->IsDatabaseEnabled()); |
63 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); | 64 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); |
64 } | 65 } |
65 | 66 |
66 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) { | 67 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) { |
67 std::unique_ptr<TestingProfile> profile1( | 68 std::unique_ptr<TestingProfile> profile1( |
68 static_cast<TestingProfile*>(CreateBrowserContext())); | 69 static_cast<TestingProfile*>(CreateBrowserContext())); |
69 std::unique_ptr<TestingProfile> profile2( | 70 std::unique_ptr<TestingProfile> profile2( |
70 static_cast<TestingProfile*>(CreateBrowserContext())); | 71 static_cast<TestingProfile*>(CreateBrowserContext())); |
71 | 72 |
72 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 73 ActivityLog* activity_log1; |
73 base::CommandLine saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | 74 { |
74 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 75 base::test::ScopedCommandLine scoped_command_line; |
| 76 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
75 switches::kEnableExtensionActivityLogging); | 77 switches::kEnableExtensionActivityLogging); |
76 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); | 78 activity_log1 = ActivityLog::GetInstance(profile1.get()); |
77 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | 79 } |
78 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); | 80 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); |
79 | 81 |
80 EXPECT_EQ(0, | 82 EXPECT_EQ(0, |
81 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 83 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
82 EXPECT_EQ(0, | 84 EXPECT_EQ(0, |
83 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 85 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
84 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); | 86 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); |
85 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); | 87 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); |
86 EXPECT_FALSE(activity_log1->IsWatchdogAppActive()); | 88 EXPECT_FALSE(activity_log1->IsWatchdogAppActive()); |
87 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); | 89 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 extension_service1->DisableExtension(kExtensionID, | 224 extension_service1->DisableExtension(kExtensionID, |
223 Extension::DISABLE_USER_ACTION); | 225 Extension::DISABLE_USER_ACTION); |
224 extension_service1->DisableExtension("fpofdchlamddhnajleknffcbmnjfahpg", | 226 extension_service1->DisableExtension("fpofdchlamddhnajleknffcbmnjfahpg", |
225 Extension::DISABLE_USER_ACTION); | 227 Extension::DISABLE_USER_ACTION); |
226 EXPECT_EQ(0, | 228 EXPECT_EQ(0, |
227 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 229 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
228 EXPECT_FALSE(activity_log1->IsDatabaseEnabled()); | 230 EXPECT_FALSE(activity_log1->IsDatabaseEnabled()); |
229 } | 231 } |
230 | 232 |
231 TEST_F(ActivityLogEnabledTest, AppAndCommandLine) { | 233 TEST_F(ActivityLogEnabledTest, AppAndCommandLine) { |
232 // Set the command line switch. | 234 base::test::ScopedCommandLine scoped_command_line; |
233 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 235 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
234 base::CommandLine saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); | |
235 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
236 switches::kEnableExtensionActivityLogging); | 236 switches::kEnableExtensionActivityLogging); |
237 | 237 |
238 std::unique_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 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
241 ExtensionService* extension_service = | 242 ExtensionService* extension_service = |
242 static_cast<TestExtensionSystem*>( | 243 static_cast<TestExtensionSystem*>( |
243 ExtensionSystem::Get(profile.get()))->CreateExtensionService( | 244 ExtensionSystem::Get(profile.get()))->CreateExtensionService( |
244 &command_line, base::FilePath(), false); | 245 &command_line, base::FilePath(), false); |
245 static_cast<TestExtensionSystem*>( | 246 static_cast<TestExtensionSystem*>( |
246 ExtensionSystem::Get(profile.get()))->SetReady(); | 247 ExtensionSystem::Get(profile.get()))->SetReady(); |
247 | 248 |
248 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); | 249 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); |
249 // Allow Activity Log to install extension tracker. | 250 // Allow Activity Log to install extension tracker. |
250 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
(...skipping 23 matching lines...) Expand all Loading... |
274 extension_service->UninstallExtension( | 275 extension_service->UninstallExtension( |
275 kExtensionID, | 276 kExtensionID, |
276 extensions::UNINSTALL_REASON_FOR_TESTING, | 277 extensions::UNINSTALL_REASON_FOR_TESTING, |
277 base::Bind(&base::DoNothing), | 278 base::Bind(&base::DoNothing), |
278 NULL); | 279 NULL); |
279 | 280 |
280 EXPECT_TRUE(activity_log->IsDatabaseEnabled()); | 281 EXPECT_TRUE(activity_log->IsDatabaseEnabled()); |
281 EXPECT_EQ(0, | 282 EXPECT_EQ(0, |
282 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 283 profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
283 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); | 284 EXPECT_FALSE(activity_log->IsWatchdogAppActive()); |
284 | |
285 // Cleanup. | |
286 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; | |
287 } | 285 } |
288 | 286 |
289 } // namespace extensions | 287 } // namespace extensions |
OLD | NEW |