| 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/scoped_command_line.h" | 7 #include "base/test/scoped_command_line.h" |
| 8 #include "chrome/browser/extensions/activity_log/activity_log.h" | 8 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 9 #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" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); | 109 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); |
| 110 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); | 110 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); |
| 111 ActivityLog* activity_log3 = ActivityLog::GetInstance(profile3.get()); | 111 ActivityLog* activity_log3 = ActivityLog::GetInstance(profile3.get()); |
| 112 | 112 |
| 113 EXPECT_EQ(1, | 113 EXPECT_EQ(1, |
| 114 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 114 profile1->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 115 EXPECT_EQ(0, | 115 EXPECT_EQ(0, |
| 116 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 116 profile2->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 117 EXPECT_EQ(2, | 117 EXPECT_EQ(2, |
| 118 profile3->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); | 118 profile3->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 119 EXPECT_TRUE(activity_log1->IsWatchdogAppActive()); | 119 EXPECT_TRUE(activity_log1->is_active()); |
| 120 EXPECT_FALSE(activity_log2->IsWatchdogAppActive()); | 120 EXPECT_FALSE(activity_log2->is_active()); |
| 121 EXPECT_TRUE(activity_log3->IsWatchdogAppActive()); | 121 EXPECT_TRUE(activity_log3->is_active()); |
| 122 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); | 122 EXPECT_TRUE(activity_log1->IsDatabaseEnabled()); |
| 123 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); | 123 EXPECT_FALSE(activity_log2->IsDatabaseEnabled()); |
| 124 EXPECT_TRUE(activity_log3->IsDatabaseEnabled()); | 124 EXPECT_TRUE(activity_log3->IsDatabaseEnabled()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) { | 127 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) { |
| 128 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 128 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 129 std::unique_ptr<TestingProfile> profile1( | 129 std::unique_ptr<TestingProfile> profile1( |
| 130 static_cast<TestingProfile*>(CreateBrowserContext())); | 130 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 131 std::unique_ptr<TestingProfile> profile2( | 131 std::unique_ptr<TestingProfile> profile2( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 extensions::UNINSTALL_REASON_FOR_TESTING, | 276 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 277 base::Bind(&base::DoNothing), | 277 base::Bind(&base::DoNothing), |
| 278 NULL); | 278 NULL); |
| 279 | 279 |
| 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 | 285 |
| 286 // Tests that if the cached count in the profile preferences is incorrect, the |
| 287 // activity log will correct itself. |
| 288 TEST_F(ActivityLogEnabledTest, IncorrectPrefsRecovery) { |
| 289 std::unique_ptr<TestingProfile> profile( |
| 290 static_cast<TestingProfile*>(CreateBrowserContext())); |
| 291 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 292 ExtensionService* extension_service = |
| 293 static_cast<TestExtensionSystem*>( |
| 294 ExtensionSystem::Get(profile.get()))->CreateExtensionService( |
| 295 &command_line, base::FilePath(), false); |
| 296 |
| 297 // Set the preferences to indicate a cached count of 10. |
| 298 profile->GetPrefs()->SetInteger(prefs::kWatchdogExtensionActive, 10); |
| 299 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); |
| 300 |
| 301 static_cast<TestExtensionSystem*>( |
| 302 ExtensionSystem::Get(profile.get()))->SetReady(); |
| 303 base::RunLoop().RunUntilIdle(); |
| 304 |
| 305 // Even though the cached count was 10, the activity log should correctly |
| 306 // realize that there were no real consumers, and should be inactive and |
| 307 // correct the prefs. |
| 308 EXPECT_FALSE(activity_log->is_active()); |
| 309 EXPECT_EQ( |
| 310 0, profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 311 |
| 312 // Testing adding an extension maintains pref and active correctness. |
| 313 scoped_refptr<Extension> extension = |
| 314 ExtensionBuilder() |
| 315 .SetManifest(DictionaryBuilder() |
| 316 .Set("name", "Watchdog Extension ") |
| 317 .Set("version", "1.0.0") |
| 318 .Set("manifest_version", 2) |
| 319 .Build()) |
| 320 .SetID(kExtensionID) |
| 321 .Build(); |
| 322 extension_service->AddExtension(extension.get()); |
| 323 |
| 324 EXPECT_EQ( |
| 325 1, profile->GetPrefs()->GetInteger(prefs::kWatchdogExtensionActive)); |
| 326 EXPECT_TRUE(activity_log->is_active()); |
| 327 } |
| 328 |
| 286 } // namespace extensions | 329 } // namespace extensions |
| OLD | NEW |