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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_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: ChromeOS fix 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 #if defined OS_CHROMEOS
18 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/device_settings_service.h"
21 #endif
22
23 namespace extensions {
24
25 class ActivityLogEnabledTest : public ChromeRenderViewHostTestHarness {
26 protected:
27 virtual void SetUp() OVERRIDE {
28 ChromeRenderViewHostTestHarness::SetUp();
29 #if defined OS_CHROMEOS
30 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
31 #endif
32 }
33
34 virtual void TearDown() OVERRIDE {
35 #if defined OS_CHROMEOS
36 test_user_manager_.reset();
37 #endif
38 ChromeRenderViewHostTestHarness::TearDown();
39 }
40
41 #if defined OS_CHROMEOS
42 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
43 chromeos::ScopedTestCrosSettings test_cros_settings_;
44 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
45 #endif
46 };
47
48 TEST_F(ActivityLogEnabledTest, NoSwitch) {
49 scoped_ptr<TestingProfile> profile(
50 static_cast<TestingProfile*>(CreateBrowserContext()));
51 EXPECT_FALSE(
52 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
53
54 ActivityLog* activity_log = ActivityLog::GetInstance(profile.get());
55
56 EXPECT_FALSE(
57 profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
58 EXPECT_FALSE(activity_log->IsLogEnabled());
59 EXPECT_FALSE(activity_log->IsLogEnabledOnAnyProfile());
60 }
61
62 TEST_F(ActivityLogEnabledTest, CommandLineSwitch) {
63 scoped_ptr<TestingProfile> profile1(
64 static_cast<TestingProfile*>(CreateBrowserContext()));
65 scoped_ptr<TestingProfile> profile2(
66 static_cast<TestingProfile*>(CreateBrowserContext()));
67
68 CommandLine command_line(CommandLine::NO_PROGRAM);
69 CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess();
70 CommandLine::ForCurrentProcess()->AppendSwitch(
71 switches::kEnableExtensionActivityLogging);
72 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
73 *CommandLine::ForCurrentProcess() = saved_cmdline_;
74 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
75
76 EXPECT_FALSE(
77 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
78 EXPECT_FALSE(
79 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
80 EXPECT_TRUE(activity_log1->IsLogEnabled());
81 EXPECT_FALSE(activity_log2->IsLogEnabled());
82 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile());
83 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
84 }
85
86 TEST_F(ActivityLogEnabledTest, PrefSwitch) {
87 scoped_ptr<TestingProfile> profile1(
88 static_cast<TestingProfile*>(CreateBrowserContext()));
89 scoped_ptr<TestingProfile> profile2(
90 static_cast<TestingProfile*>(CreateBrowserContext()));
91
92 EXPECT_FALSE(
93 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
94 EXPECT_FALSE(
95 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
96
97 profile1->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, true);
98 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
99 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
100
101 EXPECT_TRUE(
102 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
103 EXPECT_FALSE(
104 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
105 EXPECT_TRUE(activity_log1->IsLogEnabled());
106 EXPECT_FALSE(activity_log2->IsLogEnabled());
107 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile());
108 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
109 }
110
111 TEST_F(ActivityLogEnabledTest, WatchdogSwitch) {
112 CommandLine command_line(CommandLine::NO_PROGRAM);
113 scoped_ptr<TestingProfile> profile1(
114 static_cast<TestingProfile*>(CreateBrowserContext()));
115 scoped_ptr<TestingProfile> profile2(
116 static_cast<TestingProfile*>(CreateBrowserContext()));
117 // Extension service is destroyed by the profile.
118 ExtensionService* extension_service1 =
119 static_cast<TestExtensionSystem*>(
120 ExtensionSystem::Get(profile1.get()))->CreateExtensionService(
121 &command_line, base::FilePath(), false);
122 static_cast<TestExtensionSystem*>(
123 ExtensionSystem::Get(profile1.get()))->SetReady();
124
125 ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get());
126 ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get());
127
128 // Allow Activity Log to install extension tracker.
129 base::RunLoop().RunUntilIdle();
130
131 EXPECT_FALSE(
132 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
133 EXPECT_FALSE(
134 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
135
136 scoped_refptr<Extension> extension =
137 ExtensionBuilder()
138 .SetManifest(DictionaryBuilder()
139 .Set("name", "Watchdog Extension ")
140 .Set("version", "1.0.0")
141 .Set("manifest_version", 2))
142 .SetID(kActivityLogExtensionId)
143 .Build();
144 extension_service1->AddExtension(extension.get());
145
146 EXPECT_TRUE(
147 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
148 EXPECT_FALSE(
149 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
150 EXPECT_TRUE(activity_log1->IsLogEnabled());
151 EXPECT_FALSE(activity_log2->IsLogEnabled());
152 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile());
153 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
154
155 extension_service1->DisableExtension(kActivityLogExtensionId,
156 Extension::DISABLE_USER_ACTION);
157
158 EXPECT_FALSE(
159 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
160 EXPECT_FALSE(
161 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
162 EXPECT_FALSE(activity_log1->IsLogEnabled());
163 EXPECT_FALSE(activity_log2->IsLogEnabled());
164 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile());
165 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
166
167 extension_service1->EnableExtension(kActivityLogExtensionId);
168
169 EXPECT_TRUE(
170 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
171 EXPECT_FALSE(
172 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
173 EXPECT_TRUE(activity_log1->IsLogEnabled());
174 EXPECT_FALSE(activity_log2->IsLogEnabled());
175 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile());
176 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
177
178 extension_service1->UninstallExtension(kActivityLogExtensionId, false, NULL);
179
180 EXPECT_FALSE(
181 profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
182 EXPECT_FALSE(
183 profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive));
184 EXPECT_FALSE(activity_log1->IsLogEnabled());
185 EXPECT_FALSE(activity_log2->IsLogEnabled());
186 EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile());
187 EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile());
188 }
189
190 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698