| 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_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" |
| 11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/browser_shutdown.h" | 13 #include "chrome/browser/browser_shutdown.h" |
| 14 #include "chrome/browser/browser_window.h" |
| 14 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/profile_manager.h" | 16 #include "chrome/browser/profile_manager.h" |
| 16 #include "chrome/browser/renderer_host/render_process_host.h" | 17 #include "chrome/browser/renderer_host/render_process_host.h" |
| 18 #if defined(OS_WIN) |
| 17 #include "chrome/browser/views/frame/browser_view.h" | 19 #include "chrome/browser/views/frame/browser_view.h" |
| 20 #endif |
| 18 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/main_function_params.h" | 24 #include "chrome/common/main_function_params.h" |
| 22 #include "chrome/test/testing_browser_process.h" | 25 #include "chrome/test/testing_browser_process.h" |
| 23 #include "chrome/test/ui_test_utils.h" | 26 #include "chrome/test/ui_test_utils.h" |
| 24 #include "net/base/host_resolver_unittest.h" | 27 #include "net/base/host_resolver_unittest.h" |
| 25 #include "sandbox/src/sandbox_factory.h" | |
| 26 #include "sandbox/src/dep.h" | 28 #include "sandbox/src/dep.h" |
| 27 | 29 |
| 28 extern int BrowserMain(const MainFunctionParams&); | 30 extern int BrowserMain(const MainFunctionParams&); |
| 29 | 31 |
| 30 const wchar_t kUnitTestShowWindows[] = L"show-windows"; | 32 const wchar_t kUnitTestShowWindows[] = L"show-windows"; |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 bool DieFileDie(const std::wstring& file, bool recurse) { | 36 bool DieFileDie(const std::wstring& file, bool recurse) { |
| 35 if (!file_util::PathExists(file)) | 37 if (!file_util::PathExists(file)) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Don't delete the resources when BrowserMain returns. Many ui classes | 73 // Don't delete the resources when BrowserMain returns. Many ui classes |
| 72 // cache SkBitmaps in a static field so that if we delete the resource | 74 // cache SkBitmaps in a static field so that if we delete the resource |
| 73 // bundle we'll crash. | 75 // bundle we'll crash. |
| 74 browser_shutdown::delete_resources_on_shutdown = false; | 76 browser_shutdown::delete_resources_on_shutdown = false; |
| 75 | 77 |
| 76 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 78 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); |
| 77 original_command_line_.reset(new CommandLine(*command_line)); | 79 original_command_line_.reset(new CommandLine(*command_line)); |
| 78 | 80 |
| 79 SetUpCommandLine(command_line); | 81 SetUpCommandLine(command_line); |
| 80 | 82 |
| 83 #if defined(OS_WIN) |
| 81 // Hide windows on show. | 84 // Hide windows on show. |
| 82 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) | 85 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) |
| 83 BrowserView::SetShowState(SW_HIDE); | 86 BrowserView::SetShowState(SW_HIDE); |
| 87 #endif |
| 84 | 88 |
| 85 if (dom_automation_enabled_) | 89 if (dom_automation_enabled_) |
| 86 command_line->AppendSwitch(switches::kDomAutomationController); | 90 command_line->AppendSwitch(switches::kDomAutomationController); |
| 87 | 91 |
| 88 if (single_process_) | 92 if (single_process_) |
| 89 command_line->AppendSwitch(switches::kSingleProcess); | 93 command_line->AppendSwitch(switches::kSingleProcess); |
| 90 | 94 |
| 91 command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); | 95 command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); |
| 92 | 96 |
| 93 // For some reason the sandbox wasn't happy running in test mode. These | 97 // For some reason the sandbox wasn't happy running in test mode. These |
| (...skipping 10 matching lines...) Expand all Loading... |
| 104 // otherwise they'll try to use unit_test.exe. | 108 // otherwise they'll try to use unit_test.exe. |
| 105 std::wstring subprocess_path; | 109 std::wstring subprocess_path; |
| 106 PathService::Get(base::FILE_EXE, &subprocess_path); | 110 PathService::Get(base::FILE_EXE, &subprocess_path); |
| 107 FilePath fp_subprocess_path = FilePath::FromWStringHack(subprocess_path); | 111 FilePath fp_subprocess_path = FilePath::FromWStringHack(subprocess_path); |
| 108 subprocess_path = fp_subprocess_path.DirName().ToWStringHack(); | 112 subprocess_path = fp_subprocess_path.DirName().ToWStringHack(); |
| 109 file_util::AppendToPath(&subprocess_path, | 113 file_util::AppendToPath(&subprocess_path, |
| 110 chrome::kBrowserProcessExecutablePath); | 114 chrome::kBrowserProcessExecutablePath); |
| 111 command_line->AppendSwitchWithValue(switches::kBrowserSubprocessPath, | 115 command_line->AppendSwitchWithValue(switches::kBrowserSubprocessPath, |
| 112 subprocess_path); | 116 subprocess_path); |
| 113 | 117 |
| 114 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | |
| 115 SandboxInitWrapper sandbox_wrapper; | 118 SandboxInitWrapper sandbox_wrapper; |
| 116 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); | 119 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); |
| 117 params.ui_task = | 120 params.ui_task = |
| 118 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); | 121 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); |
| 119 | 122 |
| 120 scoped_refptr<net::RuleBasedHostMapper> host_mapper( | 123 scoped_refptr<net::RuleBasedHostMapper> host_mapper( |
| 121 new net::RuleBasedHostMapper()); | 124 new net::RuleBasedHostMapper()); |
| 122 ConfigureHostMapper(host_mapper.get()); | 125 ConfigureHostMapper(host_mapper.get()); |
| 123 net::ScopedHostMapper scoped_host_mapper(host_mapper.get()); | 126 net::ScopedHostMapper scoped_host_mapper(host_mapper.get()); |
| 124 BrowserMain(params); | 127 BrowserMain(params); |
| 125 } | 128 } |
| 126 | 129 |
| 127 void InProcessBrowserTest::TearDown() { | 130 void InProcessBrowserTest::TearDown() { |
| 128 // Reinstall testing browser process. | 131 // Reinstall testing browser process. |
| 129 delete g_browser_process; | 132 delete g_browser_process; |
| 130 g_browser_process = new TestingBrowserProcess(); | 133 g_browser_process = new TestingBrowserProcess(); |
| 131 | 134 |
| 132 browser_shutdown::delete_resources_on_shutdown = true; | 135 browser_shutdown::delete_resources_on_shutdown = true; |
| 133 | 136 |
| 137 #if defined(WIN) |
| 134 BrowserView::SetShowState(-1); | 138 BrowserView::SetShowState(-1); |
| 139 #endif |
| 135 | 140 |
| 136 *CommandLine::ForCurrentProcessMutable() = *original_command_line_; | 141 *CommandLine::ForCurrentProcessMutable() = *original_command_line_; |
| 137 RenderProcessHost::set_run_renderer_in_process(original_single_process_); | 142 RenderProcessHost::set_run_renderer_in_process(original_single_process_); |
| 138 } | 143 } |
| 139 | 144 |
| 140 void InProcessBrowserTest::Observe(NotificationType type, | 145 void InProcessBrowserTest::Observe(NotificationType type, |
| 141 const NotificationSource& source, | 146 const NotificationSource& source, |
| 142 const NotificationDetails& details) { | 147 const NotificationDetails& details) { |
| 143 if (type == NotificationType::BROWSER_CLOSED) { | 148 if (type == NotificationType::BROWSER_CLOSED) { |
| 144 DCHECK(Source<Browser>(source).ptr() == browser_); | 149 DCHECK(Source<Browser>(source).ptr() == browser_); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 MessageLoopForUI::current()->Quit(); | 217 MessageLoopForUI::current()->Quit(); |
| 213 } | 218 } |
| 214 | 219 |
| 215 void InProcessBrowserTest::ConfigureHostMapper( | 220 void InProcessBrowserTest::ConfigureHostMapper( |
| 216 net::RuleBasedHostMapper* host_mapper) { | 221 net::RuleBasedHostMapper* host_mapper) { |
| 217 host_mapper->AllowDirectLookup("*.google.com"); | 222 host_mapper->AllowDirectLookup("*.google.com"); |
| 218 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | 223 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
| 219 // We don't want the test code to use it. | 224 // We don't want the test code to use it. |
| 220 host_mapper->AddSimulatedFailure("wpad"); | 225 host_mapper->AddSimulatedFailure("wpad"); |
| 221 } | 226 } |
| OLD | NEW |