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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/run_loop.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"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/test_extension_system.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension_builder.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h"
16
17 namespace extensions {
18
19 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.
20 };
21
22 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.
23 scoped_ptr<TestingProfile> profile(
24 static_cast<TestingProfile*>(CreateBrowserContext()));
25 EXPECT_FALSE(
26 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
27
28 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get());
29
30 EXPECT_FALSE(
31 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
32 EXPECT_FALSE(activity_log->IsLogEnabled());
33 EXPECT_FALSE(activity_log->IsLogEnabledOnAnyProfile());
34 }
35
36 TEST_F(IsLogEnabledTest, CommandLineSwitch) {
37 scoped_ptr<TestingProfile> profile1(
38 static_cast<TestingProfile*>(CreateBrowserContext()));
39 scoped_ptr<TestingProfile> profile2(
40 static_cast<TestingProfile*>(CreateBrowserContext()));
41
42 CommandLine command_line(CommandLine::NO_PROGRAM);
43 CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess();
44 CommandLine::ForCurrentProcess()->AppendSwitch(
45 switches::kEnableExtensionActivityLogging);
46 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
47 *CommandLine::ForCurrentProcess() = saved_cmdline_;
48 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
49
50 EXPECT_FALSE(
51 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
52 EXPECT_FALSE(
53 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
54 EXPECT_TRUE(activity_log1->IsLogEnabled());
55 EXPECT_FALSE(activity_log2->IsLogEnabled());
56 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
57 }
58
59 TEST_F(IsLogEnabledTest, PrefSwitch) {
60 scoped_ptr<TestingProfile> profile1(
61 static_cast<TestingProfile*>(CreateBrowserContext()));
62 scoped_ptr<TestingProfile> profile2(
63 static_cast<TestingProfile*>(CreateBrowserContext()));
64
65 EXPECT_FALSE(
66 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
67 EXPECT_FALSE(
68 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
69
70 profile1->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, true);
71 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
72 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
73
74 EXPECT_TRUE(
75 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
76 EXPECT_FALSE(
77 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
78 EXPECT_TRUE(activity_log1->IsLogEnabled());
79 EXPECT_FALSE(activity_log2->IsLogEnabled());
80 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
81 }
82
83 TEST_F(IsLogEnabledTest, WatchdogSwitch) {
84 CommandLine command_line(CommandLine::NO_PROGRAM);
85 scoped_ptr<TestingProfile> profile1(
86 static_cast<TestingProfile*>(CreateBrowserContext()));
87 scoped_ptr<TestingProfile> profile2(
88 static_cast<TestingProfile*>(CreateBrowserContext()));
89 // Extension service is destroyed by the profile.
90 ExtensionService* extension_service1 =
91 static_cast<TestExtensionSystem*>(
92 ExtensionSystem::Get(profile1.get()))->CreateExtensionService(
93 &command_line, base::FilePath(), false);
94 static_cast<TestExtensionSystem*>(
95 ExtensionSystem::Get(profile1.get()))->SetReady();
96
97 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
98 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
99
100 // Allow Activity Log to install extension tracker.
101 base::RunLoop().RunUntilIdle();
102
103 EXPECT_FALSE(
104 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
105 EXPECT_FALSE(
106 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
107
108 scoped_refptr<Extension> extension =
109 ExtensionBuilder()
110 .SetManifest(DictionaryBuilder()
111 .Set("name", "Watchdog Extension ")
112 .Set("version", "1.0.0")
113 .Set("manifest_version", 2))
114 .SetID(kActivityLogExtensionId)
115 .Build();
116 extension_service1->AddExtension(extension.get());
117
118 EXPECT_TRUE(
119 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
120 EXPECT_FALSE(
121 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
122 EXPECT_TRUE(activity_log1->IsLogEnabled());
123 EXPECT_FALSE(activity_log2->IsLogEnabled());
124 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
125
126 extension_service1->DisableExtension(kActivityLogExtensionId,
127 Extension::DISABLE_USER_ACTION);
128
129 EXPECT_FALSE(
130 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
131 EXPECT_FALSE(
132 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
133 EXPECT_FALSE(activity_log1->IsLogEnabled());
134 EXPECT_FALSE(activity_log2->IsLogEnabled());
135 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
136
137 extension_service1->EnableExtension(kActivityLogExtensionId);
138
139 EXPECT_TRUE(
140 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
141 EXPECT_FALSE(
142 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
143 EXPECT_TRUE(activity_log1->IsLogEnabled());
144 EXPECT_FALSE(activity_log2->IsLogEnabled());
145 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
146
147 extension_service1->UninstallExtension(kActivityLogExtensionId, false, NULL);
148
149 EXPECT_FALSE(
150 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
151 EXPECT_FALSE(
152 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
153 EXPECT_FALSE(activity_log1->IsLogEnabled());
154 EXPECT_FALSE(activity_log2->IsLogEnabled());
155 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
156 }
157
158 } // namespace extensions
OLDNEW
« 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