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

Side by Side Diff: chrome/test/in_process_browser_test.cc

Issue 1763023: Re-apply http://codereview.chromium.org/1622012 (Closed)
Patch Set: Add missing files (I thought git would do that) Created 10 years, 7 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
« no previous file with comments | « chrome/test/in_process_browser_test.h ('k') | chrome/test/live_sync/live_sync_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/in_process_browser_test.h" 5 #include "chrome/test/in_process_browser_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 void InProcessBrowserTest::SetUp() { 88 void InProcessBrowserTest::SetUp() {
89 // Cleanup the user data dir. 89 // Cleanup the user data dir.
90 FilePath user_data_dir; 90 FilePath user_data_dir;
91 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 91 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
92 ASSERT_LT(10, static_cast<int>(user_data_dir.value().size())) << 92 ASSERT_LT(10, static_cast<int>(user_data_dir.value().size())) <<
93 "The user data directory name passed into this test was too " 93 "The user data directory name passed into this test was too "
94 "short to delete safely. Please check the user-data-dir " 94 "short to delete safely. Please check the user-data-dir "
95 "argument and try again."; 95 "argument and try again.";
96 if (ShouldDeleteProfile()) 96 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true));
97 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true));
98 97
99 // The unit test suite creates a testingbrowser, but we want the real thing. 98 // The unit test suite creates a testingbrowser, but we want the real thing.
100 // Delete the current one. We'll install the testing one in TearDown. 99 // Delete the current one. We'll install the testing one in TearDown.
101 delete g_browser_process; 100 delete g_browser_process;
101 g_browser_process = NULL;
102
103 SetUpUserDataDirectory();
102 104
103 // Don't delete the resources when BrowserMain returns. Many ui classes 105 // Don't delete the resources when BrowserMain returns. Many ui classes
104 // cache SkBitmaps in a static field so that if we delete the resource 106 // cache SkBitmaps in a static field so that if we delete the resource
105 // bundle we'll crash. 107 // bundle we'll crash.
106 browser_shutdown::delete_resources_on_shutdown = false; 108 browser_shutdown::delete_resources_on_shutdown = false;
107 109
108 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); 110 CommandLine* command_line = CommandLine::ForCurrentProcessMutable();
109 original_command_line_.reset(new CommandLine(*command_line)); 111 original_command_line_.reset(new CommandLine(*command_line));
110 112
111 SetUpCommandLine(command_line); 113 SetUpCommandLine(command_line);
(...skipping 21 matching lines...) Expand all
133 command_line->AppendSwitch(switches::kNoSandbox); 135 command_line->AppendSwitch(switches::kNoSandbox);
134 136
135 // Don't show the first run ui. 137 // Don't show the first run ui.
136 command_line->AppendSwitch(switches::kNoFirstRun); 138 command_line->AppendSwitch(switches::kNoFirstRun);
137 139
138 // This is a Browser test. 140 // This is a Browser test.
139 command_line->AppendSwitchWithValue(switches::kTestType, 141 command_line->AppendSwitchWithValue(switches::kTestType,
140 ASCIIToWide(kBrowserTestType)); 142 ASCIIToWide(kBrowserTestType));
141 143
142 // Single-process mode is not set in BrowserMain so it needs to be processed 144 // Single-process mode is not set in BrowserMain so it needs to be processed
143 // explicitlty. 145 // explicitly.
144 original_single_process_ = RenderProcessHost::run_renderer_in_process(); 146 original_single_process_ = RenderProcessHost::run_renderer_in_process();
145 if (command_line->HasSwitch(switches::kSingleProcess)) 147 if (command_line->HasSwitch(switches::kSingleProcess))
146 RenderProcessHost::set_run_renderer_in_process(true); 148 RenderProcessHost::set_run_renderer_in_process(true);
147 149
148 // Explicitly set the path of the exe used for the renderer and plugin, 150 // Explicitly set the path of the exe used for the renderer and plugin,
149 // otherwise they'll try to use unit_test.exe. 151 // otherwise they'll try to use unit_test.exe.
150 FilePath subprocess_path; 152 FilePath subprocess_path;
151 PathService::Get(base::FILE_EXE, &subprocess_path); 153 PathService::Get(base::FILE_EXE, &subprocess_path);
152 subprocess_path = subprocess_path.DirName(); 154 subprocess_path = subprocess_path.DirName();
153 subprocess_path = subprocess_path.AppendASCII(WideToASCII( 155 subprocess_path = subprocess_path.AppendASCII(WideToASCII(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 ChromeThread::IO, FROM_HERE, 274 ChromeThread::IO, FROM_HERE,
273 NewRunnableFunction(chrome_browser_net::SetUrlRequestMocksEnabled, true)); 275 NewRunnableFunction(chrome_browser_net::SetUrlRequestMocksEnabled, true));
274 276
275 browser_ = CreateBrowser(profile); 277 browser_ = CreateBrowser(profile);
276 278
277 // Start the timeout timer to prevent hangs. 279 // Start the timeout timer to prevent hangs.
278 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, 280 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
279 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), 281 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
280 initial_timeout_); 282 initial_timeout_);
281 283
282 RunTestOnMainThread(); 284 // If an ASSERT_ failed during SetUp, skip the InProcessBrowserTest test body.
285 if (!HasFatalFailure())
286 RunTestOnMainThread();
283 CleanUpOnMainThread(); 287 CleanUpOnMainThread();
284 288
285 // Close all browser windows. This might not happen immediately, since some 289 // Close all browser windows. This might not happen immediately, since some
286 // may need to wait for beforeunload and unload handlers to fire in a tab. 290 // may need to wait for beforeunload and unload handlers to fire in a tab.
287 // When all windows are closed, the last window will call Quit(). Call 291 // When all windows are closed, the last window will call Quit(). Call
288 // Quit() explicitly if no windows are open. 292 // Quit() explicitly if no windows are open.
289 #if defined(OS_MACOSX) 293 #if defined(OS_MACOSX)
290 // When the browser window closes, Cocoa will generate an inner-loop that 294 // When the browser window closes, Cocoa will generate an inner-loop that
291 // processes the RenderProcessHost delete task, so allow task nesting. 295 // processes the RenderProcessHost delete task, so allow task nesting.
292 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); 296 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 372
369 GTEST_NONFATAL_FAILURE_(error_message.c_str()); 373 GTEST_NONFATAL_FAILURE_(error_message.c_str());
370 374
371 MessageLoopForUI::current()->Quit(); 375 MessageLoopForUI::current()->Quit();
372 } 376 }
373 377
374 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { 378 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) {
375 DCHECK_GT(timeout_value, 0); 379 DCHECK_GT(timeout_value, 0);
376 initial_timeout_ = timeout_value; 380 initial_timeout_ = timeout_value;
377 } 381 }
OLDNEW
« no previous file with comments | « chrome/test/in_process_browser_test.h ('k') | chrome/test/live_sync/live_sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698