Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1072)

Unified Diff: chrome/browser/extensions/activity_log/is_log_enabled_unittest.cc

Issue 18430004: Sets correct ActivityLog enabled status to the first renderer process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added a unittest Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/activity_log/is_log_enabled_unittest.cc
diff --git a/chrome/browser/extensions/activity_log/is_log_enabled_unittest.cc b/chrome/browser/extensions/activity_log/is_log_enabled_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..597acb59ea88a112c725c463e9f513744413a445
--- /dev/null
+++ b/chrome/browser/extensions/activity_log/is_log_enabled_unittest.cc
@@ -0,0 +1,158 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/run_loop.h"
+#include "chrome/browser/extensions/activity_log/activity_log.h"
+#include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/test_extension_system.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension_builder.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "chrome/test/base/testing_profile.h"
+
+namespace extensions {
+
+class IsLogEnabledTest : public ChromeRenderViewHostTestHarness {
felt 2013/08/13 15:05:40 i think you can replace this with a typedef
pmarch 2013/08/13 15:52:54 Done.
+};
+
+TEST_F(IsLogEnabledTest, NoSwitch) {
felt 2013/08/13 15:05:40 can you put ActivityLog in the name of the test cl
pmarch 2013/08/13 15:52:54 Done.
+ scoped_ptr<TestingProfile> profile(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+ EXPECT_FALSE(
+ profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+
+ ActivityLog* activity_log = ActivityLog::GetInstance(profile.get());
+
+ EXPECT_FALSE(
+ profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(activity_log->IsLogEnabled());
+ EXPECT_FALSE(activity_log->IsLogEnabledOnAnyProfile());
+}
+
+TEST_F(IsLogEnabledTest, CommandLineSwitch) {
+ scoped_ptr<TestingProfile> profile1(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+ scoped_ptr<TestingProfile> profile2(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess();
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableExtensionActivityLogging);
+ ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
+ *CommandLine::ForCurrentProcess() = saved_cmdline_;
+ ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
+
+ EXPECT_FALSE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_TRUE(activity_log1->IsLogEnabled());
+ EXPECT_FALSE(activity_log2->IsLogEnabled());
+ EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
felt 2013/08/13 15:05:40 why not also check activity_log1->IsLogEnabledOnAn
pmarch 2013/08/13 15:52:54 IsLogEnabledOnAnyProfile is a static method, but y
+}
+
+TEST_F(IsLogEnabledTest, PrefSwitch) {
+ scoped_ptr<TestingProfile> profile1(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+ scoped_ptr<TestingProfile> profile2(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+
+ EXPECT_FALSE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+
+ profile1->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, true);
+ ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
+ ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
+
+ EXPECT_TRUE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_TRUE(activity_log1->IsLogEnabled());
+ EXPECT_FALSE(activity_log2->IsLogEnabled());
+ EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
+}
+
+TEST_F(IsLogEnabledTest, WatchdogSwitch) {
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ scoped_ptr<TestingProfile> profile1(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+ scoped_ptr<TestingProfile> profile2(
+ static_cast<TestingProfile*>(CreateBrowserContext()));
+ // Extension service is destroyed by the profile.
+ ExtensionService* extension_service1 =
+ static_cast<TestExtensionSystem*>(
+ ExtensionSystem::Get(profile1.get()))->CreateExtensionService(
+ &command_line, base::FilePath(), false);
+ static_cast<TestExtensionSystem*>(
+ ExtensionSystem::Get(profile1.get()))->SetReady();
+
+ ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
+ ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
+
+ // Allow Activity Log to install extension tracker.
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_FALSE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+
+ scoped_refptr<Extension> extension =
+ ExtensionBuilder()
+ .SetManifest(DictionaryBuilder()
+ .Set("name", "Watchdog Extension ")
+ .Set("version", "1.0.0")
+ .Set("manifest_version", 2))
+ .SetID(kActivityLogExtensionId)
+ .Build();
+ extension_service1->AddExtension(extension.get());
+
+ EXPECT_TRUE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_TRUE(activity_log1->IsLogEnabled());
+ EXPECT_FALSE(activity_log2->IsLogEnabled());
+ EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
+
+ extension_service1->DisableExtension(kActivityLogExtensionId,
+ Extension::DISABLE_USER_ACTION);
+
+ EXPECT_FALSE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(activity_log1->IsLogEnabled());
+ EXPECT_FALSE(activity_log2->IsLogEnabled());
+ EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
+
+ extension_service1->EnableExtension(kActivityLogExtensionId);
+
+ EXPECT_TRUE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_TRUE(activity_log1->IsLogEnabled());
+ EXPECT_FALSE(activity_log2->IsLogEnabled());
+ EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
+
+ extension_service1->UninstallExtension(kActivityLogExtensionId, false, NULL);
+
+ EXPECT_FALSE(
+ profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(
+ profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
+ EXPECT_FALSE(activity_log1->IsLogEnabled());
+ EXPECT_FALSE(activity_log2->IsLogEnabled());
+ EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_log_unittest.cc ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698