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

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

Issue 4947002: Mac: Let browser_tests run in bundled mode for their whole lifetime. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: test Created 10 years, 1 month 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
« no previous file with comments | « chrome/test/in_process_browser_test.h ('k') | chrome/test/plugin/pdf_browsertest.cc » ('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 "app/app_switches.h" 7 #include "app/app_switches.h"
8 #include "app/gfx/gl/gl_implementation.h" 8 #include "app/gfx/gl/gl_implementation.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/common/notification_registrar.h" 36 #include "chrome/common/notification_registrar.h"
37 #include "chrome/common/notification_type.h" 37 #include "chrome/common/notification_type.h"
38 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
39 #include "chrome/test/test_launcher_utils.h" 39 #include "chrome/test/test_launcher_utils.h"
40 #include "chrome/test/testing_browser_process.h" 40 #include "chrome/test/testing_browser_process.h"
41 #include "chrome/test/ui_test_utils.h" 41 #include "chrome/test/ui_test_utils.h"
42 #include "net/base/mock_host_resolver.h" 42 #include "net/base/mock_host_resolver.h"
43 #include "net/test/test_server.h" 43 #include "net/test/test_server.h"
44 #include "sandbox/src/dep.h" 44 #include "sandbox/src/dep.h"
45 45
46 #if defined(OS_CHROMEOS)
47 #include "chrome/browser/chromeos/cros/cros_library.h"
48 #endif // defined(OS_CHROMEOS)
49
50 #if defined(OS_MACOSX)
51 #include "base/mac_util.h"
52 #endif
53
46 #if defined(OS_WIN) 54 #if defined(OS_WIN)
47 #include "chrome/browser/views/frame/browser_view.h" 55 #include "chrome/browser/views/frame/browser_view.h"
48 #endif 56 #endif
49 57
50 #if defined(OS_CHROMEOS)
51 #include "chrome/browser/chromeos/cros/cros_library.h"
52 #endif // defined(OS_CHROMEOS)
53
54 namespace { 58 namespace {
55 59
56 void InitializeBrowser(Browser* browser) { 60 void InitializeBrowser(Browser* browser) {
57 browser->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), 61 browser->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
58 PageTransition::START_PAGE); 62 PageTransition::START_PAGE);
59 63
60 // Wait for the page to finish loading. 64 // Wait for the page to finish loading.
61 ui_test_utils::WaitForNavigation( 65 ui_test_utils::WaitForNavigation(
62 &browser->GetSelectedTabContents()->controller()); 66 &browser->GetSelectedTabContents()->controller());
63 67
64 browser->window()->Show(); 68 browser->window()->Show();
65 } 69 }
66 70
67 } // namespace 71 } // namespace
68 72
69 extern int BrowserMain(const MainFunctionParams&); 73 extern int BrowserMain(const MainFunctionParams&);
70 74
71 const wchar_t kUnitTestShowWindows[] = L"show-windows"; 75 const wchar_t kUnitTestShowWindows[] = L"show-windows";
72 76
73 // Passed as value of kTestType. 77 // Passed as value of kTestType.
74 static const char kBrowserTestType[] = "browser"; 78 static const char kBrowserTestType[] = "browser";
75 79
76 InProcessBrowserTest::InProcessBrowserTest() 80 InProcessBrowserTest::InProcessBrowserTest()
77 : browser_(NULL), 81 : browser_(NULL),
78 test_server_(net::TestServer::TYPE_HTTP,
79 FilePath(FILE_PATH_LITERAL("chrome/test/data"))),
80 show_window_(false), 82 show_window_(false),
81 dom_automation_enabled_(false), 83 dom_automation_enabled_(false),
82 tab_closeable_state_watcher_enabled_(false), 84 tab_closeable_state_watcher_enabled_(false),
83 original_single_process_(false) { 85 original_single_process_(false) {
86 #if defined(OS_MACOSX)
87 mac_util::SetOverrideAmIBundled(true);
88 #endif
89
90 // Before we run the browser, we have to hack the path to the exe to match
91 // what it would be if Chrome was running, because it is used to fork renderer
92 // processes, on Linux at least (failure to do so will cause a browser_test to
93 // be run instead of a renderer).
94 FilePath chrome_path;
95 CHECK(PathService::Get(base::FILE_EXE, &chrome_path));
96 chrome_path = chrome_path.DirName();
97 #if defined(OS_WIN)
98 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath);
99 #elif defined(OS_POSIX)
100 chrome_path = chrome_path.Append(
101 WideToASCII(chrome::kBrowserProcessExecutablePath));
102 #endif
103 CHECK(PathService::Override(base::FILE_EXE, chrome_path));
104
105 test_server_.reset(new net::TestServer(
106 net::TestServer::TYPE_HTTP,
107 FilePath(FILE_PATH_LITERAL("chrome/test/data"))));
84 } 108 }
85 109
86 InProcessBrowserTest::~InProcessBrowserTest() { 110 InProcessBrowserTest::~InProcessBrowserTest() {
87 } 111 }
88 112
89 void InProcessBrowserTest::SetUp() { 113 void InProcessBrowserTest::SetUp() {
90 // Remember the command line. Normally this doesn't matter, because the test 114 // Remember the command line. Normally this doesn't matter, because the test
91 // harness creates a new process for each test, but when the test harness is 115 // harness creates a new process for each test, but when the test harness is
92 // running in single process mode, we can't let one test's command-line 116 // running in single process mode, we can't let one test's command-line
93 // changes (e.g. enabling DOM automation) affect other tests. 117 // changes (e.g. enabling DOM automation) affect other tests.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 #if defined(OS_WIN) 171 #if defined(OS_WIN)
148 // The Windows sandbox requires that the browser and child processes are the 172 // The Windows sandbox requires that the browser and child processes are the
149 // same binary. So we launch browser_process.exe which loads chrome.dll 173 // same binary. So we launch browser_process.exe which loads chrome.dll
150 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, 174 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
151 command_line->GetProgram()); 175 command_line->GetProgram());
152 #else 176 #else
153 // Explicitly set the path of the binary used for child processes, otherwise 177 // Explicitly set the path of the binary used for child processes, otherwise
154 // they'll try to use browser_tests which doesn't contain ChromeMain. 178 // they'll try to use browser_tests which doesn't contain ChromeMain.
155 FilePath subprocess_path; 179 FilePath subprocess_path;
156 PathService::Get(base::FILE_EXE, &subprocess_path); 180 PathService::Get(base::FILE_EXE, &subprocess_path);
157 subprocess_path = subprocess_path.DirName();
158 subprocess_path = subprocess_path.AppendASCII(WideToASCII(
159 chrome::kBrowserProcessExecutablePath));
160 #if defined(OS_MACOSX) 181 #if defined(OS_MACOSX)
161 // Recreate the real environment, run the helper within the app bundle. 182 // Recreate the real environment, run the helper within the app bundle.
162 subprocess_path = subprocess_path.DirName().DirName(); 183 subprocess_path = subprocess_path.DirName().DirName();
163 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); 184 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents");
164 subprocess_path = 185 subprocess_path =
165 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); 186 subprocess_path.Append("Versions").Append(chrome::kChromeVersion);
166 subprocess_path = 187 subprocess_path =
167 subprocess_path.Append(chrome::kHelperProcessExecutablePath); 188 subprocess_path.Append(chrome::kHelperProcessExecutablePath);
168 #endif 189 #endif
169 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, 190 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
(...skipping 28 matching lines...) Expand all
198 219
199 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol 220 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol
200 // We don't want the test code to use it. 221 // We don't want the test code to use it.
201 host_resolver_->AddSimulatedFailure("wpad"); 222 host_resolver_->AddSimulatedFailure("wpad");
202 223
203 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( 224 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc(
204 host_resolver_.get()); 225 host_resolver_.get());
205 226
206 SetUpInProcessBrowserTestFixture(); 227 SetUpInProcessBrowserTestFixture();
207 228
208 // Before we run the browser, we have to hack the path to the exe to match
209 // what it would be if Chrome was running, because it is used to fork renderer
210 // processes, on Linux at least (failure to do so will cause a browser_test to
211 // be run instead of a renderer).
212 FilePath chrome_path;
213 CHECK(PathService::Get(base::FILE_EXE, &chrome_path));
214 chrome_path = chrome_path.DirName();
215 #if defined(OS_WIN)
216 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath);
217 #elif defined(OS_POSIX)
218 chrome_path = chrome_path.Append(
219 WideToASCII(chrome::kBrowserProcessExecutablePath));
220 #endif
221 CHECK(PathService::Override(base::FILE_EXE, chrome_path));
222
223 BrowserMain(params); 229 BrowserMain(params);
224 TearDownInProcessBrowserTestFixture(); 230 TearDownInProcessBrowserTestFixture();
225 } 231 }
226 232
227 bool InProcessBrowserTest::CreateUserDataDirectory() { 233 bool InProcessBrowserTest::CreateUserDataDirectory() {
228 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); 234 CommandLine* command_line = CommandLine::ForCurrentProcessMutable();
229 FilePath user_data_dir = 235 FilePath user_data_dir =
230 command_line->GetSwitchValuePath(switches::kUserDataDir); 236 command_line->GetSwitchValuePath(switches::kUserDataDir);
231 if (user_data_dir.empty()) { 237 if (user_data_dir.empty()) {
232 if (temp_user_data_dir_.CreateUniqueTempDir() && 238 if (temp_user_data_dir_.CreateUniqueTempDir() &&
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 return; 352 return;
347 353
348 // Invoke CloseAllBrowsersAndExit on a running message loop. 354 // Invoke CloseAllBrowsersAndExit on a running message loop.
349 // CloseAllBrowsersAndExit exits the message loop after everything has been 355 // CloseAllBrowsersAndExit exits the message loop after everything has been
350 // shut down properly. 356 // shut down properly.
351 MessageLoopForUI::current()->PostTask( 357 MessageLoopForUI::current()->PostTask(
352 FROM_HERE, 358 FROM_HERE,
353 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); 359 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit));
354 ui_test_utils::RunMessageLoop(); 360 ui_test_utils::RunMessageLoop();
355 } 361 }
OLDNEW
« no previous file with comments | « chrome/test/in_process_browser_test.h ('k') | chrome/test/plugin/pdf_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698