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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log_enabled_unittest.cc

Issue 23729005: Enable Activity Logging by default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added definition of 'active' Created 7 years, 3 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }; 46 };
47 47
48 TEST_F(ActivityLogEnabledTest, NoSwitch) { 48 TEST_F(ActivityLogEnabledTest, NoSwitch) {
49 scoped_ptr<TestingProfile> profile( 49 scoped_ptr<TestingProfile> profile(
50 static_cast<TestingProfile*>(CreateBrowserContext())); 50 static_cast<TestingProfile*>(CreateBrowserContext()));
51 EXPECT_FALSE( 51 EXPECT_FALSE(
52 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 52 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
53 53
54 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); 54 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get());
55 55
56 EXPECT_FALSE( 56 EXPECT_FALSE(
57 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 57 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
58 EXPECT_FALSE(activity_log->IsLogEnabled()); 58 EXPECT_FALSE(activity_log->IsDatabaseEnabled());
59 EXPECT_FALSE(activity_log->IsLogEnabledOnAnyProfile()); 59 EXPECT_FALSE(activity_log->IsWatchdogAppActive());
60 } 60 }
61 61
62 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) { 62 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) {
63 scoped_ptr<TestingProfile> profile1( 63 scoped_ptr<TestingProfile> profile1(
64 static_cast<TestingProfile*>(CreateBrowserContext())); 64 static_cast<TestingProfile*>(CreateBrowserContext()));
65 scoped_ptr<TestingProfile> profile2( 65 scoped_ptr<TestingProfile> profile2(
66 static_cast<TestingProfile*>(CreateBrowserContext())); 66 static_cast<TestingProfile*>(CreateBrowserContext()));
67 67
68 CommandLine command_line(CommandLine::NO_PROGRAM); 68 CommandLine command_line(CommandLine::NO_PROGRAM);
69 CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess(); 69 CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess();
70 CommandLine::ForCurrentProcess()->AppendSwitch( 70 CommandLine::ForCurrentProcess()->AppendSwitch(
71 switches::kEnableExtensionActivityLogging); 71 switches::kEnableExtensionActivityLogging);
72 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); 72 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
73 *CommandLine::ForCurrentProcess() = saved_cmdline_; 73 *CommandLine::ForCurrentProcess() = saved_cmdline_;
74 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); 74 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
75 75
76 EXPECT_FALSE( 76 EXPECT_FALSE(
77 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 77 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
78 EXPECT_FALSE( 78 EXPECT_FALSE(
79 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 79 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
80 EXPECT_TRUE(activity_log1->IsLogEnabled()); 80 EXPECT_TRUE(activity_log1->IsDatabaseEnabled());
81 EXPECT_FALSE(activity_log2->IsLogEnabled()); 81 EXPECT_FALSE(activity_log2->IsDatabaseEnabled());
82 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); 82 EXPECT_FALSE(activity_log1->IsWatchdogAppActive());
83 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); 83 EXPECT_FALSE(activity_log2->IsWatchdogAppActive());
84 } 84 }
85 85
86 TEST_F(ActivityLogEnabledTest, PrefSwitch) { 86 TEST_F(ActivityLogEnabledTest, PrefSwitch) {
87 scoped_ptr<TestingProfile> profile1( 87 scoped_ptr<TestingProfile> profile1(
88 static_cast<TestingProfile*>(CreateBrowserContext())); 88 static_cast<TestingProfile*>(CreateBrowserContext()));
89 scoped_ptr<TestingProfile> profile2( 89 scoped_ptr<TestingProfile> profile2(
90 static_cast<TestingProfile*>(CreateBrowserContext())); 90 static_cast<TestingProfile*>(CreateBrowserContext()));
91 91
92 EXPECT_FALSE( 92 EXPECT_FALSE(
93 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 93 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
94 EXPECT_FALSE( 94 EXPECT_FALSE(
95 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 95 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
96 96
97 profile1->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, true); 97 profile1->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, true);
98 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); 98 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
99 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); 99 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
100 100
101 EXPECT_TRUE( 101 EXPECT_TRUE(
102 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 102 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
103 EXPECT_FALSE( 103 EXPECT_FALSE(
104 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 104 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
105 EXPECT_TRUE(activity_log1->IsLogEnabled()); 105 EXPECT_TRUE(activity_log1->IsWatchdogAppActive());
106 EXPECT_FALSE(activity_log2->IsLogEnabled()); 106 EXPECT_FALSE(activity_log2->IsWatchdogAppActive());
107 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); 107 EXPECT_TRUE(activity_log1->IsDatabaseEnabled());
108 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); 108 EXPECT_FALSE(activity_log2->IsDatabaseEnabled());
109 } 109 }
110 110
111 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) { 111 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) {
112 CommandLine command_line(CommandLine::NO_PROGRAM); 112 CommandLine command_line(CommandLine::NO_PROGRAM);
113 scoped_ptr<TestingProfile> profile1( 113 scoped_ptr<TestingProfile> profile1(
114 static_cast<TestingProfile*>(CreateBrowserContext())); 114 static_cast<TestingProfile*>(CreateBrowserContext()));
115 scoped_ptr<TestingProfile> profile2( 115 scoped_ptr<TestingProfile> profile2(
116 static_cast<TestingProfile*>(CreateBrowserContext())); 116 static_cast<TestingProfile*>(CreateBrowserContext()));
117 // Extension service is destroyed by the profile. 117 // Extension service is destroyed by the profile.
118 ExtensionService* extension_service1 = 118 ExtensionService* extension_service1 =
(...skipping 21 matching lines...) Expand all
140 .Set("version", "1.0.0") 140 .Set("version", "1.0.0")
141 .Set("manifest_version", 2)) 141 .Set("manifest_version", 2))
142 .SetID(kActivityLogExtensionId) 142 .SetID(kActivityLogExtensionId)
143 .Build(); 143 .Build();
144 extension_service1->AddExtension(extension.get()); 144 extension_service1->AddExtension(extension.get());
145 145
146 EXPECT_TRUE( 146 EXPECT_TRUE(
147 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 147 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
148 EXPECT_FALSE( 148 EXPECT_FALSE(
149 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 149 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
150 EXPECT_TRUE(activity_log1->IsLogEnabled()); 150 EXPECT_TRUE(activity_log1->IsWatchdogAppActive());
151 EXPECT_FALSE(activity_log2->IsLogEnabled()); 151 EXPECT_FALSE(activity_log2->IsWatchdogAppActive());
152 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); 152 EXPECT_TRUE(activity_log1->IsDatabaseEnabled());
153 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); 153 EXPECT_FALSE(activity_log2->IsDatabaseEnabled());
154 154
155 extension_service1->DisableExtension(kActivityLogExtensionId, 155 extension_service1->DisableExtension(kActivityLogExtensionId,
156 Extension::DISABLE_USER_ACTION); 156 Extension::DISABLE_USER_ACTION);
157 157
158 EXPECT_FALSE( 158 EXPECT_FALSE(
159 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 159 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
160 EXPECT_FALSE( 160 EXPECT_FALSE(
161 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 161 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
162 EXPECT_FALSE(activity_log1->IsLogEnabled()); 162 EXPECT_FALSE(activity_log1->IsWatchdogAppActive());
163 EXPECT_FALSE(activity_log2->IsLogEnabled()); 163 EXPECT_FALSE(activity_log2->IsWatchdogAppActive());
164 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); 164 EXPECT_FALSE(activity_log1->IsDatabaseEnabled());
165 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); 165 EXPECT_FALSE(activity_log2->IsDatabaseEnabled());
166 166
167 extension_service1->EnableExtension(kActivityLogExtensionId); 167 extension_service1->EnableExtension(kActivityLogExtensionId);
168 168
169 EXPECT_TRUE( 169 EXPECT_TRUE(
170 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 170 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
171 EXPECT_FALSE( 171 EXPECT_FALSE(
172 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 172 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
173 EXPECT_TRUE(activity_log1->IsLogEnabled()); 173 EXPECT_TRUE(activity_log1->IsWatchdogAppActive());
174 EXPECT_FALSE(activity_log2->IsLogEnabled()); 174 EXPECT_FALSE(activity_log2->IsWatchdogAppActive());
175 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); 175 EXPECT_TRUE(activity_log1->IsDatabaseEnabled());
176 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); 176 EXPECT_FALSE(activity_log2->IsDatabaseEnabled());
177 177
178 extension_service1->UninstallExtension(kActivityLogExtensionId, false, NULL); 178 extension_service1->UninstallExtension(kActivityLogExtensionId, false, NULL);
179 179
180 EXPECT_FALSE( 180 EXPECT_FALSE(
181 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 181 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
182 EXPECT_FALSE( 182 EXPECT_FALSE(
183 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); 183 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
184 EXPECT_FALSE(activity_log1->IsLogEnabled()); 184 EXPECT_FALSE(activity_log1->IsWatchdogAppActive());
185 EXPECT_FALSE(activity_log2->IsLogEnabled()); 185 EXPECT_FALSE(activity_log2->IsWatchdogAppActive());
186 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); 186 EXPECT_FALSE(activity_log1->IsDatabaseEnabled());
187 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); 187 EXPECT_FALSE(activity_log2->IsDatabaseEnabled());
188 }
189
190 TEST_F(ActivityLogEnabledTest, AppAndCommandLine) {
191 // Set the command line switch.
192 CommandLine command_line(CommandLine::NO_PROGRAM);
193 CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess();
194 CommandLine::ForCurrentProcess()->AppendSwitch(
195 switches::kEnableExtensionActivityLogging);
196
197 scoped_ptr<TestingProfile> profile(
198 static_cast<TestingProfile*>(CreateBrowserContext()));
199 // Extension service is destroyed by the profile.
200 ExtensionService* extension_service =
201 static_cast<TestExtensionSystem*>(
202 ExtensionSystem::Get(profile.get()))->CreateExtensionService(
203 &command_line, base::FilePath(), false);
204 static_cast<TestExtensionSystem*>(
205 ExtensionSystem::Get(profile.get()))->SetReady();
206
207 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get());
208 // Allow Activity Log to install extension tracker.
209 base::RunLoop().RunUntilIdle();
210
211 EXPECT_TRUE(activity_log->IsDatabaseEnabled());
212 EXPECT_FALSE(
213 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
214 EXPECT_FALSE(activity_log->IsWatchdogAppActive());
215
216 // Enable the extension.
217 scoped_refptr<Extension> extension =
218 ExtensionBuilder()
219 .SetManifest(DictionaryBuilder()
220 .Set("name", "Watchdog Extension ")
221 .Set("version", "1.0.0")
222 .Set("manifest_version", 2))
223 .SetID(kActivityLogExtensionId)
224 .Build();
225 extension_service->AddExtension(extension.get());
226
227 EXPECT_TRUE(activity_log->IsDatabaseEnabled());
228 EXPECT_TRUE(
229 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
230 EXPECT_TRUE(activity_log->IsWatchdogAppActive());
231
232 extension_service->UninstallExtension(kActivityLogExtensionId, false, NULL);
233
234 EXPECT_TRUE(activity_log->IsDatabaseEnabled());
235 EXPECT_FALSE(
236 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
237 EXPECT_FALSE(activity_log->IsWatchdogAppActive());
238
239 // Cleanup.
240 *CommandLine::ForCurrentProcess() = saved_cmdline_;
188 } 241 }
189 242
190 } // namespace extensions 243 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698