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

Side by Side Diff: chrome/browser/chrome_main_browsertest.cc

Issue 120963002: Use a Finch Experiment to control the Browser Blacklist (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 12 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/test/ui/ui_test.h" 5 #include "chrome/test/ui/ui_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/process/launch.h" 9 #include "base/process/launch.h"
10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h" 13 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/chrome_version_info.h"
17 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/test_switches.h" 20 #include "chrome/test/base/test_switches.h"
19 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
22 #include "chrome_elf/blacklist/blacklist.h"
20 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
21 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/content_switches.h"
24 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
25 29
30 #if defined(OS_WIN)
31 #include "base/test/test_reg_util_win.h"
32 #endif
33
26 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch 34 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch
27 // for details. 35 // for details.
28 #if !defined(OS_MACOSX) 36 #if !defined(OS_MACOSX)
29 37
30 class ChromeMainTest : public InProcessBrowserTest { 38 class ChromeMainTest : public InProcessBrowserTest {
31 public: 39 public:
32 ChromeMainTest() {} 40 ChromeMainTest() {}
33 41
34 void Relaunch(const CommandLine& new_command_line) { 42 void Relaunch(const CommandLine& new_command_line) {
35 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); 43 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 chrome::NOTIFICATION_TAB_ADDED, 154 chrome::NOTIFICATION_TAB_ADDED,
147 content::NotificationService::AllSources()); 155 content::NotificationService::AllSources());
148 Relaunch(new_command_line); 156 Relaunch(new_command_line);
149 tab_observer.Wait(); 157 tab_observer.Wait();
150 158
151 // There should be one normal and one incognito window now. 159 // There should be one normal and one incognito window now.
152 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); 160 ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
153 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); 161 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile, host_desktop_type));
154 } 162 }
155 163
164 #if defined(OS_WIN)
165
166 class ChromeBlacklistTrialTest : public InProcessBrowserTest {
167 protected:
168 ChromeBlacklistTrialTest() {}
169
170 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
171 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
172 "BrowserBlacklist/Enabled/");
173 }
174
175 virtual void SetUpInProcessBrowserTestFixture() {
176 registry_util::RegistryOverrideManager override_manager;
177 override_manager.OverrideRegistry(HKEY_CURRENT_USER,
178 L"browser_blacklist_test");
179 }
180
181 DWORD GetBlacklistState() {
182 DWORD blacklist_state;
robertshield 2013/12/27 03:24:29 = 0
csharp 2014/01/02 19:55:36 Done.
183 DWORD blacklist_state_size = sizeof(blacklist_state);
184
185 ::RegGetValue(HKEY_CURRENT_USER,
robertshield 2013/12/27 03:24:29 use base/win/registry here too
csharp 2014/01/02 19:55:36 Done.
186 blacklist::kRegistryBeaconPath,
187 blacklist::kBeaconState,
188 RRF_RT_REG_DWORD,
189 NULL,
190 &blacklist_state,
191 &blacklist_state_size);
192 return blacklist_state;
193 }
194
195 string16 GetBlacklistVersion() {
196 wchar_t key_data[255];
robertshield 2013/12/27 03:24:29 = {}
csharp 2014/01/02 19:55:36 Done.
197 DWORD key_data_size = sizeof(key_data);
198
199 ::RegGetValue(HKEY_CURRENT_USER,
200 blacklist::kRegistryBeaconPath,
201 blacklist::kBeaconVersion,
202 RRF_RT_REG_SZ,
203 NULL,
204 key_data,
205 &key_data_size);
206
207 return key_data;
208 }
209
210 private:
211 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialTest);
212 };
213
214 class ChromeBlacklistTrialFirstRun : public ChromeBlacklistTrialTest {
robertshield 2013/12/27 03:24:29 This class appears to be empty, does it need to ex
csharp 2014/01/02 19:55:36 Done.
215 protected:
216 ChromeBlacklistTrialFirstRun() {}
217
218 private:
219 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialFirstRun);
220 };
221
222 IN_PROC_BROWSER_TEST_F(ChromeBlacklistTrialFirstRun, Verify) {
223 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
224
225 chrome::VersionInfo version_info;
226 string16 version = UTF8ToUTF16(version_info.Version());
227 ASSERT_EQ(version, GetBlacklistVersion());
228 }
229
230 class ChromeBlacklistTrialSetupFailed : public ChromeBlacklistTrialTest {
231 protected:
232 ChromeBlacklistTrialSetupFailed() {}
233
234 virtual void SetUpInProcessBrowserTestFixture() {
235 ChromeBlacklistTrialTest::SetUpInProcessBrowserTestFixture();
236
237 // Set the registry to indicate that the blacklist setup is running,
robertshield 2013/12/27 03:24:29 nit: double space before running
csharp 2014/01/02 19:55:36 Done.
238 // which means it failed to run correctly last time.
239 DWORD blacklist_state = blacklist::BLACKLIST_SETUP_RUNNING;
240 ::RegSetKeyValue(HKEY_CURRENT_USER,
241 blacklist::kRegistryBeaconPath,
242 blacklist::kBeaconState,
243 REG_DWORD,
244 &blacklist_state,
245 sizeof(blacklist_state));
246 }
247
248 private:
249 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialSetupFailed);
250 };
251
252 IN_PROC_BROWSER_TEST_F(ChromeBlacklistTrialSetupFailed, Verify) {
253 // Since the blacklist setup failed, it should now be disabled.
254 ASSERT_EQ(blacklist::BLACKLIST_DISABLED, GetBlacklistState());
255 }
256
257 class ChromeBlacklistTrialVersionChanged : public ChromeBlacklistTrialTest {
258 protected:
259 ChromeBlacklistTrialVersionChanged() {}
260
261 virtual void SetUpInProcessBrowserTestFixture() {
262 ChromeBlacklistTrialTest::SetUpInProcessBrowserTestFixture();
263
264 // Mark the blacklist as disabled for an older version, so it should
265 // be enabled again for the new version.
266 string16 version = L"old_version";
267 ::RegSetKeyValue(HKEY_CURRENT_USER,
268 blacklist::kRegistryBeaconPath,
269 blacklist::kBeaconVersion,
270 REG_SZ,
271 version.c_str(),
272 version.size() * sizeof(wchar_t));
273
274 DWORD blacklist_state = blacklist::BLACKLIST_DISABLED;
275 ::RegSetKeyValue(HKEY_CURRENT_USER,
276 blacklist::kRegistryBeaconPath,
277 blacklist::kBeaconState,
278 REG_DWORD,
279 &blacklist_state,
280 sizeof(blacklist_state));
281 }
282
283 private:
284 DISALLOW_COPY_AND_ASSIGN(ChromeBlacklistTrialVersionChanged);
285 };
286
287 IN_PROC_BROWSER_TEST_F(ChromeBlacklistTrialVersionChanged, Verify) {
288 ASSERT_EQ(blacklist::BLACKLIST_ENABLED, GetBlacklistState());
289
290 chrome::VersionInfo version_info;
291 string16 version = UTF8ToUTF16(version_info.Version());
292 ASSERT_EQ(version, GetBlacklistVersion());
293 }
294 #endif
295
156 #endif // !OS_MACOSX 296 #endif // !OS_MACOSX
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698