| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/test/content_browser_test.h" | 5 #include "content/test/content_browser_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 CHECK(PathService::Get(DIR_TEST_DATA, &content_test_data_dir)); | 48 CHECK(PathService::Get(DIR_TEST_DATA, &content_test_data_dir)); |
| 49 embedded_test_server()->ServeFilesFromDirectory(content_test_data_dir); | 49 embedded_test_server()->ServeFilesFromDirectory(content_test_data_dir); |
| 50 } | 50 } |
| 51 | 51 |
| 52 ContentBrowserTest::~ContentBrowserTest() { | 52 ContentBrowserTest::~ContentBrowserTest() { |
| 53 CHECK(setup_called_) << "Overridden SetUp() did not call parent " | 53 CHECK(setup_called_) << "Overridden SetUp() did not call parent " |
| 54 "implementation, so test not run."; | 54 "implementation, so test not run."; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ContentBrowserTest::SetUp() { | 57 void ContentBrowserTest::SetUp() { |
| 58 setup_called_ = true; | |
| 59 | |
| 60 shell_main_delegate_.reset(new ShellMainDelegate); | 58 shell_main_delegate_.reset(new ShellMainDelegate); |
| 61 shell_main_delegate_->PreSandboxStartup(); | 59 shell_main_delegate_->PreSandboxStartup(); |
| 62 | 60 |
| 63 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 61 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 64 command_line->AppendSwitch(switches::kContentBrowserTest); | 62 command_line->AppendSwitch(switches::kContentBrowserTest); |
| 65 | 63 |
| 66 SetUpCommandLine(command_line); | 64 SetUpCommandLine(command_line); |
| 67 | 65 |
| 68 // Single-process mode is not set in BrowserMain, so process it explicitly, | 66 // Single-process mode is not set in BrowserMain, so if a subclass hasn't |
| 69 // and set up renderer. | 67 // modified it yet, process it explicitly, and set up renderer. |
| 70 if (command_line->HasSwitch(switches::kSingleProcess)) { | 68 if (command_line->HasSwitch(switches::kSingleProcess)) { |
| 71 single_process_renderer_client_.reset(new ShellContentRendererClient); | 69 if (!single_process_renderer_client_) |
| 70 single_process_renderer_client_.reset(new ShellContentRendererClient()); |
| 72 SetRendererClientForTesting(single_process_renderer_client_.get()); | 71 SetRendererClientForTesting(single_process_renderer_client_.get()); |
| 72 } else { |
| 73 // Confirm no test has called SetContentRendererClient() without |
| 74 // setting up single process mode. |
| 75 DCHECK(!single_process_renderer_client_); |
| 73 } | 76 } |
| 74 | 77 |
| 75 #if defined(OS_MACOSX) | 78 #if defined(OS_MACOSX) |
| 76 // See InProcessBrowserTest::PrepareTestCommandLine(). | 79 // See InProcessBrowserTest::PrepareTestCommandLine(). |
| 77 base::FilePath subprocess_path; | 80 base::FilePath subprocess_path; |
| 78 PathService::Get(base::FILE_EXE, &subprocess_path); | 81 PathService::Get(base::FILE_EXE, &subprocess_path); |
| 79 subprocess_path = subprocess_path.DirName().DirName(); | 82 subprocess_path = subprocess_path.DirName().DirName(); |
| 80 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | 83 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
| 81 subprocess_path = subprocess_path.Append( | 84 subprocess_path = subprocess_path.Append( |
| 82 "Frameworks/Content Shell Helper.app/Contents/MacOS/Content Shell Helper")
; | 85 "Frameworks/Content Shell Helper.app/Contents/MacOS/Content Shell Helper")
; |
| 83 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | 86 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
| 84 subprocess_path); | 87 subprocess_path); |
| 85 #endif | 88 #endif |
| 86 | 89 |
| 87 // LinuxInputMethodContextFactory has to be initialized. | 90 // LinuxInputMethodContextFactory has to be initialized. |
| 88 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(USE_X11) | 91 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(USE_X11) |
| 89 ui::InitializeInputMethodForTesting(); | 92 ui::InitializeInputMethodForTesting(); |
| 90 #endif | 93 #endif |
| 91 | 94 |
| 95 setup_called_ = true; |
| 96 |
| 92 BrowserTestBase::SetUp(); | 97 BrowserTestBase::SetUp(); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void ContentBrowserTest::TearDown() { | 100 void ContentBrowserTest::TearDown() { |
| 96 BrowserTestBase::TearDown(); | 101 BrowserTestBase::TearDown(); |
| 97 | 102 |
| 98 // LinuxInputMethodContextFactory has to be shutdown. | 103 // LinuxInputMethodContextFactory has to be shutdown. |
| 99 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(USE_X11) | 104 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(USE_X11) |
| 100 ui::ShutdownInputMethodForTesting(); | 105 ui::ShutdownInputMethodForTesting(); |
| 101 #endif | 106 #endif |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 #endif | 142 #endif |
| 138 | 143 |
| 139 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 144 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 140 !i.IsAtEnd(); i.Advance()) { | 145 !i.IsAtEnd(); i.Advance()) { |
| 141 i.GetCurrentValue()->FastShutdownIfPossible(); | 146 i.GetCurrentValue()->FastShutdownIfPossible(); |
| 142 } | 147 } |
| 143 | 148 |
| 144 Shell::CloseAllWindows(); | 149 Shell::CloseAllWindows(); |
| 145 } | 150 } |
| 146 | 151 |
| 152 void ContentBrowserTest::SetContentRendererClient( |
| 153 scoped_ptr<ContentRendererClient> renderer_client) { |
| 154 // This routine must be called before SetUp(). |
| 155 DCHECK(!setup_called_); |
| 156 DCHECK(!single_process_renderer_client_); |
| 157 single_process_renderer_client_ = renderer_client.Pass(); |
| 158 } |
| 159 |
| 147 Shell* ContentBrowserTest::CreateBrowser() { | 160 Shell* ContentBrowserTest::CreateBrowser() { |
| 148 return Shell::CreateNewWindow( | 161 return Shell::CreateNewWindow( |
| 149 ShellContentBrowserClient::Get()->browser_context(), | 162 ShellContentBrowserClient::Get()->browser_context(), |
| 150 GURL(kAboutBlankURL), | 163 GURL(kAboutBlankURL), |
| 151 NULL, | 164 NULL, |
| 152 MSG_ROUTING_NONE, | 165 MSG_ROUTING_NONE, |
| 153 gfx::Size()); | 166 gfx::Size()); |
| 154 } | 167 } |
| 155 | 168 |
| 156 Shell* ContentBrowserTest::CreateOffTheRecordBrowser() { | 169 Shell* ContentBrowserTest::CreateOffTheRecordBrowser() { |
| 157 return Shell::CreateNewWindow( | 170 return Shell::CreateNewWindow( |
| 158 ShellContentBrowserClient::Get()->off_the_record_browser_context(), | 171 ShellContentBrowserClient::Get()->off_the_record_browser_context(), |
| 159 GURL(kAboutBlankURL), | 172 GURL(kAboutBlankURL), |
| 160 NULL, | 173 NULL, |
| 161 MSG_ROUTING_NONE, | 174 MSG_ROUTING_NONE, |
| 162 gfx::Size()); | 175 gfx::Size()); |
| 163 } | 176 } |
| 164 | 177 |
| 165 } // namespace content | 178 } // namespace content |
| OLD | NEW |