| 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/public/test/content_browser_test.h" | 5 #include "content/public/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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/threading/thread_restrictions.h" | |
| 14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 15 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/common/content_paths.h" | 15 #include "content/public/common/content_paths.h" |
| 17 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 19 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 20 #include "content/shell/browser/shell_browser_context.h" | 19 #include "content/shell/browser/shell_browser_context.h" |
| 21 #include "content/shell/browser/shell_content_browser_client.h" | 20 #include "content/shell/browser/shell_content_browser_client.h" |
| 22 #include "content/shell/common/shell_switches.h" | 21 #include "content/shell/common/shell_switches.h" |
| 23 #include "content/shell/renderer/layout_test/layout_test_content_renderer_client
.h" | 22 #include "content/shell/renderer/layout_test/layout_test_content_renderer_client
.h" |
| 24 #include "content/test/test_content_client.h" | 23 #include "content/test/test_content_client.h" |
| 25 | 24 |
| 26 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 27 #include "content/shell/app/shell_main_delegate.h" | 26 #include "content/shell/app/shell_main_delegate.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 #if defined(OS_MACOSX) | |
| 31 #include "base/mac/scoped_nsautorelease_pool.h" | |
| 32 #endif | |
| 33 | |
| 34 #if !defined(OS_CHROMEOS) && defined(OS_LINUX) | 29 #if !defined(OS_CHROMEOS) && defined(OS_LINUX) |
| 35 #include "ui/base/ime/input_method_initializer.h" | 30 #include "ui/base/ime/input_method_initializer.h" |
| 36 #endif | 31 #endif |
| 37 | 32 |
| 38 namespace content { | 33 namespace content { |
| 39 | 34 |
| 40 ContentBrowserTest::ContentBrowserTest() { | 35 ContentBrowserTest::ContentBrowserTest() { |
| 41 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
| 42 // See comment in InProcessBrowserTest::InProcessBrowserTest(). | 37 // See comment in InProcessBrowserTest::InProcessBrowserTest(). |
| 43 base::FilePath content_shell_path; | 38 base::FilePath content_shell_path; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // LinuxInputMethodContextFactory has to be shutdown. | 95 // LinuxInputMethodContextFactory has to be shutdown. |
| 101 #if !defined(OS_CHROMEOS) && defined(OS_LINUX) | 96 #if !defined(OS_CHROMEOS) && defined(OS_LINUX) |
| 102 ui::ShutdownInputMethodForTesting(); | 97 ui::ShutdownInputMethodForTesting(); |
| 103 #endif | 98 #endif |
| 104 | 99 |
| 105 #if defined(OS_ANDROID) | 100 #if defined(OS_ANDROID) |
| 106 shell_main_delegate_.reset(); | 101 shell_main_delegate_.reset(); |
| 107 #endif | 102 #endif |
| 108 } | 103 } |
| 109 | 104 |
| 110 void ContentBrowserTest::RunTestOnMainThreadLoop() { | 105 void ContentBrowserTest::PreRunTestOnMainThread() { |
| 111 if (!switches::IsRunLayoutTestSwitchPresent()) { | 106 if (!switches::IsRunLayoutTestSwitchPresent()) { |
| 112 CHECK_EQ(Shell::windows().size(), 1u); | 107 CHECK_EQ(Shell::windows().size(), 1u); |
| 113 shell_ = Shell::windows()[0]; | 108 shell_ = Shell::windows()[0]; |
| 114 } | 109 } |
| 115 | 110 |
| 116 #if defined(OS_MACOSX) | 111 #if defined(OS_MACOSX) |
| 117 // On Mac, without the following autorelease pool, code which is directly | 112 // On Mac, without the following autorelease pool, code which is directly |
| 118 // executed (as opposed to executed inside a message loop) would autorelease | 113 // executed (as opposed to executed inside a message loop) would autorelease |
| 119 // objects into a higher-level pool. This pool is not recycled in-sync with | 114 // objects into a higher-level pool. This pool is not recycled in-sync with |
| 120 // the message loops' pools and causes problems with code relying on | 115 // the message loops' pools and causes problems with code relying on |
| 121 // deallocation via an autorelease pool (such as browser window closure and | 116 // deallocation via an autorelease pool (such as browser window closure and |
| 122 // browser shutdown). To avoid this, the following pool is recycled after each | 117 // browser shutdown). To avoid this, the following pool is recycled after each |
| 123 // time code is directly executed. | 118 // time code is directly executed. |
| 124 base::mac::ScopedNSAutoreleasePool pool; | 119 pool_ = new base::mac::ScopedNSAutoreleasePool; |
| 125 #endif | 120 #endif |
| 126 | 121 |
| 127 // Pump startup related events. | 122 // Pump startup related events. |
| 128 DCHECK(base::MessageLoopForUI::IsCurrent()); | 123 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 129 base::RunLoop().RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
| 130 | 125 |
| 131 #if defined(OS_MACOSX) | 126 #if defined(OS_MACOSX) |
| 132 pool.Recycle(); | 127 pool_->Recycle(); |
| 133 #endif | 128 #endif |
| 129 } |
| 134 | 130 |
| 135 SetUpOnMainThread(); | 131 void ContentBrowserTest::PostRunTestOnMainThread() { |
| 136 | |
| 137 bool old_io_allowed_value = base::ThreadRestrictions::SetIOAllowed(false); | |
| 138 RunTestOnMainThread(); | |
| 139 base::ThreadRestrictions::SetIOAllowed(old_io_allowed_value); | |
| 140 | |
| 141 TearDownOnMainThread(); | |
| 142 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
| 143 pool.Recycle(); | 133 pool_->Recycle(); |
| 144 #endif | 134 #endif |
| 145 | 135 |
| 146 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 136 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 147 !i.IsAtEnd(); i.Advance()) { | 137 !i.IsAtEnd(); i.Advance()) { |
| 148 i.GetCurrentValue()->FastShutdownIfPossible(); | 138 i.GetCurrentValue()->FastShutdownIfPossible(); |
| 149 } | 139 } |
| 150 | 140 |
| 151 Shell::CloseAllWindows(); | 141 Shell::CloseAllWindows(); |
| 152 } | 142 } |
| 153 | 143 |
| 154 Shell* ContentBrowserTest::CreateBrowser() { | 144 Shell* ContentBrowserTest::CreateBrowser() { |
| 155 return Shell::CreateNewWindow( | 145 return Shell::CreateNewWindow( |
| 156 ShellContentBrowserClient::Get()->browser_context(), | 146 ShellContentBrowserClient::Get()->browser_context(), |
| 157 GURL(url::kAboutBlankURL), | 147 GURL(url::kAboutBlankURL), |
| 158 NULL, | 148 NULL, |
| 159 gfx::Size()); | 149 gfx::Size()); |
| 160 } | 150 } |
| 161 | 151 |
| 162 Shell* ContentBrowserTest::CreateOffTheRecordBrowser() { | 152 Shell* ContentBrowserTest::CreateOffTheRecordBrowser() { |
| 163 return Shell::CreateNewWindow( | 153 return Shell::CreateNewWindow( |
| 164 ShellContentBrowserClient::Get()->off_the_record_browser_context(), | 154 ShellContentBrowserClient::Get()->off_the_record_browser_context(), |
| 165 GURL(url::kAboutBlankURL), | 155 GURL(url::kAboutBlankURL), |
| 166 NULL, | 156 NULL, |
| 167 gfx::Size()); | 157 gfx::Size()); |
| 168 } | 158 } |
| 169 | 159 |
| 170 } // namespace content | 160 } // namespace content |
| OLD | NEW |