OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/browser_shutdown.h" | 12 #include "chrome/browser/browser_shutdown.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/profile_manager.h" | 14 #include "chrome/browser/profile_manager.h" |
| 15 #include "chrome/browser/renderer_host/render_process_host.h" |
15 #include "chrome/browser/views/frame/browser_view.h" | 16 #include "chrome/browser/views/frame/browser_view.h" |
16 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/main_function_params.h" | 20 #include "chrome/common/main_function_params.h" |
20 #include "chrome/test/testing_browser_process.h" | 21 #include "chrome/test/testing_browser_process.h" |
21 #include "chrome/test/ui_test_utils.h" | 22 #include "chrome/test/ui_test_utils.h" |
22 #include "sandbox/src/sandbox_factory.h" | 23 #include "sandbox/src/sandbox_factory.h" |
23 #include "sandbox/src/dep.h" | 24 #include "sandbox/src/dep.h" |
24 | 25 |
(...skipping 11 matching lines...) Expand all Loading... |
36 for (int i = 0; i < 10; ++i) { | 37 for (int i = 0; i < 10; ++i) { |
37 if (file_util::Delete(file, recurse)) | 38 if (file_util::Delete(file, recurse)) |
38 return true; | 39 return true; |
39 PlatformThread::Sleep(100); | 40 PlatformThread::Sleep(100); |
40 } | 41 } |
41 return false; | 42 return false; |
42 } | 43 } |
43 | 44 |
44 } // namespace | 45 } // namespace |
45 | 46 |
46 InProcessBrowserTest::InProcessBrowserTest() : browser_(NULL) { | 47 InProcessBrowserTest::InProcessBrowserTest() |
| 48 : browser_(NULL), |
| 49 show_window_(false), |
| 50 dom_automation_enabled_(false) { |
47 } | 51 } |
48 | 52 |
49 void InProcessBrowserTest::SetUp() { | 53 void InProcessBrowserTest::SetUp() { |
50 // Cleanup the user data dir. | 54 // Cleanup the user data dir. |
51 std::wstring user_data_dir; | 55 std::wstring user_data_dir; |
52 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 56 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
53 ASSERT_LT(10, static_cast<int>(user_data_dir.size())) << | 57 ASSERT_LT(10, static_cast<int>(user_data_dir.size())) << |
54 "The user data directory name passed into this test was too " | 58 "The user data directory name passed into this test was too " |
55 "short to delete safely. Please check the user-data-dir " | 59 "short to delete safely. Please check the user-data-dir " |
56 "argument and try again."; | 60 "argument and try again."; |
57 ASSERT_TRUE(DieFileDie(user_data_dir, true)); | 61 ASSERT_TRUE(DieFileDie(user_data_dir, true)); |
58 | 62 |
59 // The unit test suite creates a testingbrowser, but we want the real thing. | 63 // The unit test suite creates a testingbrowser, but we want the real thing. |
60 // Delete the current one. We'll install the testing one in TearDown. | 64 // Delete the current one. We'll install the testing one in TearDown. |
61 delete g_browser_process; | 65 delete g_browser_process; |
62 | 66 |
63 // Don't delete the resources when BrowserMain returns. Many ui classes | 67 // Don't delete the resources when BrowserMain returns. Many ui classes |
64 // cache SkBitmaps in a static field so that if we delete the resource | 68 // cache SkBitmaps in a static field so that if we delete the resource |
65 // bundle we'll crash. | 69 // bundle we'll crash. |
66 browser_shutdown::delete_resources_on_shutdown = false; | 70 browser_shutdown::delete_resources_on_shutdown = false; |
67 | 71 |
68 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 72 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); |
69 | 73 |
70 // Hide windows on show. | 74 // Hide windows on show. |
71 if (!command_line->HasSwitch(kUnitTestShowWindows)) | 75 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) |
72 BrowserView::SetShowState(SW_HIDE); | 76 BrowserView::SetShowState(SW_HIDE); |
73 | 77 |
| 78 if (dom_automation_enabled_) |
| 79 command_line->AppendSwitch(switches::kDomAutomationController); |
| 80 |
74 command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); | 81 command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); |
75 | 82 |
76 // For some reason the sandbox wasn't happy running in test mode. These | 83 // For some reason the sandbox wasn't happy running in test mode. These |
77 // tests aren't intended to test the sandbox, so we turn it off. | 84 // tests aren't intended to test the sandbox, so we turn it off. |
78 command_line->AppendSwitch(switches::kNoSandbox); | 85 command_line->AppendSwitch(switches::kNoSandbox); |
79 | 86 |
| 87 // Single-process mode is not set in BrowserMain so it needs to be processed |
| 88 // explicitlty. |
| 89 if (command_line->HasSwitch(switches::kSingleProcess)) |
| 90 RenderProcessHost::set_run_renderer_in_process(true); |
| 91 |
80 // Explicitly set the path of the exe used for the renderer, otherwise it'll | 92 // Explicitly set the path of the exe used for the renderer, otherwise it'll |
81 // try to use unit_test.exe. | 93 // try to use unit_test.exe. |
82 std::wstring renderer_path; | 94 std::wstring renderer_path; |
83 PathService::Get(base::FILE_EXE, &renderer_path); | 95 PathService::Get(base::FILE_EXE, &renderer_path); |
84 file_util::TrimFilename(&renderer_path); | 96 file_util::TrimFilename(&renderer_path); |
85 file_util::AppendToPath(&renderer_path, | 97 file_util::AppendToPath(&renderer_path, |
86 chrome::kBrowserProcessExecutableName); | 98 chrome::kBrowserProcessExecutableName); |
87 command_line->AppendSwitchWithValue(switches::kRendererPath, renderer_path); | 99 command_line->AppendSwitchWithValue(switches::kRendererPath, renderer_path); |
88 | 100 |
89 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 101 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 184 |
173 // Remove all registered notifications, otherwise by the time the | 185 // Remove all registered notifications, otherwise by the time the |
174 // destructor is run the NotificationService is dead. | 186 // destructor is run the NotificationService is dead. |
175 registrar_.RemoveAll(); | 187 registrar_.RemoveAll(); |
176 | 188 |
177 // Stop the HTTP server. | 189 // Stop the HTTP server. |
178 http_server_ = NULL; | 190 http_server_ = NULL; |
179 | 191 |
180 MessageLoopForUI::current()->Quit(); | 192 MessageLoopForUI::current()->Quit(); |
181 } | 193 } |
OLD | NEW |