OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "chrome/browser/ui/host_desktop.h" | 29 #include "chrome/browser/ui/host_desktop.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/logging_chrome.h" | 34 #include "chrome/common/logging_chrome.h" |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "chrome/renderer/chrome_content_renderer_client.h" | 36 #include "chrome/renderer/chrome_content_renderer_client.h" |
37 #include "chrome/test/base/chrome_test_suite.h" | 37 #include "chrome/test/base/chrome_test_suite.h" |
38 #include "chrome/test/base/test_launcher_utils.h" | 38 #include "chrome/test/base/test_launcher_utils.h" |
39 #include "chrome/test/base/test_switches.h" | |
39 #include "chrome/test/base/testing_browser_process.h" | 40 #include "chrome/test/base/testing_browser_process.h" |
40 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
41 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
42 #include "content/public/browser/notification_types.h" | 43 #include "content/public/browser/notification_types.h" |
43 #include "content/public/test/browser_test_utils.h" | 44 #include "content/public/test/browser_test_utils.h" |
44 #include "content/public/test/test_browser_thread.h" | 45 #include "content/public/test/test_browser_thread.h" |
45 #include "content/public/test/test_launcher.h" | 46 #include "content/public/test/test_launcher.h" |
46 #include "content/public/test/test_navigation_observer.h" | 47 #include "content/public/test/test_navigation_observer.h" |
47 #include "net/dns/mock_host_resolver.h" | 48 #include "net/dns/mock_host_resolver.h" |
48 #include "net/test/spawned_test_server/spawned_test_server.h" | 49 #include "net/test/spawned_test_server/spawned_test_server.h" |
49 #include "ui/compositor/compositor_switches.h" | 50 #include "ui/compositor/compositor_switches.h" |
50 | 51 |
51 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
52 #include "chrome/browser/chromeos/audio/audio_handler.h" | 53 #include "chrome/browser/chromeos/audio/audio_handler.h" |
53 #elif defined(OS_MACOSX) | 54 #elif defined(OS_MACOSX) |
54 #include "base/mac/scoped_nsautorelease_pool.h" | 55 #include "base/mac/scoped_nsautorelease_pool.h" |
55 #endif | 56 #endif |
56 | 57 |
58 #if defined(OS_WIN) && defined(USE_AURA) | |
59 #include "base/win/scoped_com_initializer.h" | |
60 #include "base/win/windows_version.h" | |
61 #include "ui/base/win/atl_module.h" | |
62 #include "ui/compositor/compositor_setup.h" | |
63 #include "win8/test/metro_registration_helper.h" | |
64 #include "win8/test/test_registrar_constants.h" | |
65 #endif | |
66 | |
57 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 67 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
58 #include "chrome/browser/captive_portal/captive_portal_service.h" | 68 #include "chrome/browser/captive_portal/captive_portal_service.h" |
59 #endif | 69 #endif |
60 | 70 |
61 namespace { | 71 namespace { |
62 | 72 |
63 // Passed as value of kTestType. | 73 // Passed as value of kTestType. |
64 const char kBrowserTestType[] = "browser"; | 74 const char kBrowserTestType[] = "browser"; |
65 | 75 |
66 // Used when running in single-process mode. | 76 // Used when running in single-process mode. |
67 base::LazyInstance<chrome::ChromeContentRendererClient>::Leaky | 77 base::LazyInstance<chrome::ChromeContentRendererClient>::Leaky |
68 g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 78 g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
69 | 79 |
70 } // namespace | 80 } // namespace |
71 | 81 |
82 #if defined(OS_WIN) && defined(USE_AURA) | |
83 //static | |
84 base::win::ScopedCOMInitializer* InProcessBrowserTest::com_initializer_ = NULL; | |
85 #endif | |
86 | |
72 InProcessBrowserTest::InProcessBrowserTest() | 87 InProcessBrowserTest::InProcessBrowserTest() |
73 : browser_(NULL), | 88 : browser_(NULL), |
74 exit_when_last_browser_closes_(true) | 89 exit_when_last_browser_closes_(true) |
75 #if defined(OS_MACOSX) | 90 #if defined(OS_MACOSX) |
76 , autorelease_pool_(NULL) | 91 , autorelease_pool_(NULL) |
77 #endif // OS_MACOSX | 92 #endif // OS_MACOSX |
78 { | 93 { |
79 #if defined(OS_MACOSX) | 94 #if defined(OS_MACOSX) |
80 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. | 95 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. |
81 // Before we run the browser, we have to hack the path to the exe to match | 96 // Before we run the browser, we have to hack the path to the exe to match |
82 // what it would be if Chrome was running, because it is used to fork renderer | 97 // what it would be if Chrome was running, because it is used to fork renderer |
83 // processes, on Linux at least (failure to do so will cause a browser_test to | 98 // processes, on Linux at least (failure to do so will cause a browser_test to |
84 // be run instead of a renderer). | 99 // be run instead of a renderer). |
85 base::FilePath chrome_path; | 100 base::FilePath chrome_path; |
86 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); | 101 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
87 chrome_path = chrome_path.DirName(); | 102 chrome_path = chrome_path.DirName(); |
88 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); | 103 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); |
89 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); | 104 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
90 #endif // defined(OS_MACOSX) | 105 #endif // defined(OS_MACOSX) |
91 CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 106 CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
92 } | 107 } |
93 | 108 |
94 InProcessBrowserTest::~InProcessBrowserTest() { | 109 InProcessBrowserTest::~InProcessBrowserTest() { |
95 } | 110 } |
96 | 111 |
112 //static | |
113 void InProcessBrowserTest::SetUpTestCase() { | |
jam
2013/06/21 16:32:05
I'm not sure I understand the usage of this static
gab
2013/06/21 16:47:00
Ah ok, sounds good, I had noticed this was the cas
| |
114 BrowserTestBase::SetUpTestCase(); | |
115 | |
116 #if defined(OS_WIN) && defined(USE_AURA) | |
117 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | |
118 CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) { | |
119 com_initializer_ = new base::win::ScopedCOMInitializer(); | |
120 ui::win::CreateATLModuleIfNeeded(); | |
121 ASSERT_TRUE(win8::MakeTestDefaultBrowserSynchronously()); | |
122 | |
123 // Ash browser tests need the real compositor. | |
124 ui::DisableTestCompositor(); | |
125 } | |
126 #endif | |
127 } | |
128 | |
129 //static | |
130 void InProcessBrowserTest::TearDownTestCase() { | |
131 #if defined(OS_WIN) && defined(USE_AURA) | |
132 delete com_initializer_; | |
133 com_initializer_ = NULL; | |
134 #endif | |
135 BrowserTestBase::TearDownTestCase(); | |
136 } | |
137 | |
97 void InProcessBrowserTest::SetUp() { | 138 void InProcessBrowserTest::SetUp() { |
98 // Undo TestingBrowserProcess creation in ChromeTestSuite. | 139 // Undo TestingBrowserProcess creation in ChromeTestSuite. |
99 // TODO(phajdan.jr): Extract a smaller test suite so we don't need this. | 140 // TODO(phajdan.jr): Extract a smaller test suite so we don't need this. |
100 DCHECK(g_browser_process); | 141 DCHECK(g_browser_process); |
101 delete g_browser_process; | 142 delete g_browser_process; |
102 g_browser_process = NULL; | 143 g_browser_process = NULL; |
103 | 144 |
104 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 145 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
105 // Allow subclasses to change the command line before running any tests. | 146 // Allow subclasses to change the command line before running any tests. |
106 SetUpCommandLine(command_line); | 147 SetUpCommandLine(command_line); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 BrowserTestBase::SetUp(); | 203 BrowserTestBase::SetUp(); |
163 } | 204 } |
164 | 205 |
165 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { | 206 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { |
166 // Propagate commandline settings from test_launcher_utils. | 207 // Propagate commandline settings from test_launcher_utils. |
167 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | 208 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
168 | 209 |
169 // This is a Browser test. | 210 // This is a Browser test. |
170 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); | 211 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); |
171 | 212 |
213 #if defined(OS_WIN) && defined(USE_AURA) | |
214 if (command_line->HasSwitch(switches::kAshBrowserTests)) { | |
215 command_line->AppendSwitchNative(switches::kViewerLaunchViaAppId, | |
216 win8::test::kDefaultTestAppUserModelId); | |
217 } | |
218 #endif | |
219 | |
172 #if defined(OS_MACOSX) | 220 #if defined(OS_MACOSX) |
173 // Explicitly set the path of the binary used for child processes, otherwise | 221 // Explicitly set the path of the binary used for child processes, otherwise |
174 // they'll try to use browser_tests which doesn't contain ChromeMain. | 222 // they'll try to use browser_tests which doesn't contain ChromeMain. |
175 base::FilePath subprocess_path; | 223 base::FilePath subprocess_path; |
176 PathService::Get(base::FILE_EXE, &subprocess_path); | 224 PathService::Get(base::FILE_EXE, &subprocess_path); |
177 // Recreate the real environment, run the helper within the app bundle. | 225 // Recreate the real environment, run the helper within the app bundle. |
178 subprocess_path = subprocess_path.DirName().DirName(); | 226 subprocess_path = subprocess_path.DirName().DirName(); |
179 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | 227 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
180 subprocess_path = | 228 subprocess_path = |
181 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); | 229 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 // On the Mac, this eventually reaches | 440 // On the Mac, this eventually reaches |
393 // -[BrowserWindowController windowWillClose:], which will post a deferred | 441 // -[BrowserWindowController windowWillClose:], which will post a deferred |
394 // -autorelease on itself to ultimately destroy the Browser object. The line | 442 // -autorelease on itself to ultimately destroy the Browser object. The line |
395 // below is necessary to pump these pending messages to ensure all Browsers | 443 // below is necessary to pump these pending messages to ensure all Browsers |
396 // get deleted. | 444 // get deleted. |
397 content::RunAllPendingInMessageLoop(); | 445 content::RunAllPendingInMessageLoop(); |
398 delete autorelease_pool_; | 446 delete autorelease_pool_; |
399 autorelease_pool_ = NULL; | 447 autorelease_pool_ = NULL; |
400 #endif | 448 #endif |
401 } | 449 } |
OLD | NEW |