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 "win8/test/metro_registration_helper.h" | |
63 #include "win8/test/test_registrar_constants.h" | |
64 #endif | |
65 | |
57 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 66 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
58 #include "chrome/browser/captive_portal/captive_portal_service.h" | 67 #include "chrome/browser/captive_portal/captive_portal_service.h" |
59 #endif | 68 #endif |
60 | 69 |
61 namespace { | 70 namespace { |
62 | 71 |
63 // Passed as value of kTestType. | 72 // Passed as value of kTestType. |
64 const char kBrowserTestType[] = "browser"; | 73 const char kBrowserTestType[] = "browser"; |
65 | 74 |
66 // Used when running in single-process mode. | 75 // Used when running in single-process mode. |
(...skipping 20 matching lines...) Expand all Loading... | |
87 chrome_path = chrome_path.DirName(); | 96 chrome_path = chrome_path.DirName(); |
88 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); | 97 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); |
89 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); | 98 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
90 #endif // defined(OS_MACOSX) | 99 #endif // defined(OS_MACOSX) |
91 CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 100 CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
92 } | 101 } |
93 | 102 |
94 InProcessBrowserTest::~InProcessBrowserTest() { | 103 InProcessBrowserTest::~InProcessBrowserTest() { |
95 } | 104 } |
96 | 105 |
106 //static | |
107 void InProcessBrowserTest::SetUpTestCase() { | |
108 BrowserTestBase::SetUpTestCase(); | |
109 | |
110 #if defined(OS_WIN) && defined(USE_AURA) | |
111 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | |
112 CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) { | |
113 com_initializer_ = new base::win::ScopedCOMInitializer(); | |
114 ui::win::CreateATLModuleIfNeeded(); | |
115 ASSERT_TRUE(win8::MakeTestDefaultBrowserSynchronously()); | |
116 } | |
117 #endif | |
118 } | |
119 | |
120 //static | |
121 void InProcessBrowserTest::TearDownTestCase() { | |
122 #if defined(OS_WIN) && defined(USE_AURA) | |
123 delete com_initializer_; | |
grt (UTC plus 2)
2013/06/20 23:10:06
com_initializer_ = NULL; after calling delete
gab
2013/06/20 23:47:21
Done.
| |
124 #endif | |
125 BrowserTestBase::TearDownTestCase(); | |
126 } | |
127 | |
97 void InProcessBrowserTest::SetUp() { | 128 void InProcessBrowserTest::SetUp() { |
98 // Undo TestingBrowserProcess creation in ChromeTestSuite. | 129 // Undo TestingBrowserProcess creation in ChromeTestSuite. |
99 // TODO(phajdan.jr): Extract a smaller test suite so we don't need this. | 130 // TODO(phajdan.jr): Extract a smaller test suite so we don't need this. |
100 DCHECK(g_browser_process); | 131 DCHECK(g_browser_process); |
101 delete g_browser_process; | 132 delete g_browser_process; |
102 g_browser_process = NULL; | 133 g_browser_process = NULL; |
103 | 134 |
104 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 135 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
105 // Allow subclasses to change the command line before running any tests. | 136 // Allow subclasses to change the command line before running any tests. |
106 SetUpCommandLine(command_line); | 137 SetUpCommandLine(command_line); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 BrowserTestBase::SetUp(); | 193 BrowserTestBase::SetUp(); |
163 } | 194 } |
164 | 195 |
165 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { | 196 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { |
166 // Propagate commandline settings from test_launcher_utils. | 197 // Propagate commandline settings from test_launcher_utils. |
167 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | 198 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
168 | 199 |
169 // This is a Browser test. | 200 // This is a Browser test. |
170 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); | 201 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); |
171 | 202 |
203 #if defined(OS_WIN) && defined(USE_AURA) | |
204 if (command_line->HasSwitch(switches::kAshBrowserTests)) { | |
205 command_line->AppendSwitchNative(switches::kViewerLaunchViaAppId, | |
206 win8::test::kDefaultTestAppUserModelId); | |
207 // Ash browser tests need the real compositor. | |
208 command_line->AppendSwitch(switches::kDisableTestCompositor); | |
209 } | |
210 #endif | |
211 | |
172 #if defined(OS_MACOSX) | 212 #if defined(OS_MACOSX) |
173 // Explicitly set the path of the binary used for child processes, otherwise | 213 // 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. | 214 // they'll try to use browser_tests which doesn't contain ChromeMain. |
175 base::FilePath subprocess_path; | 215 base::FilePath subprocess_path; |
176 PathService::Get(base::FILE_EXE, &subprocess_path); | 216 PathService::Get(base::FILE_EXE, &subprocess_path); |
177 // Recreate the real environment, run the helper within the app bundle. | 217 // Recreate the real environment, run the helper within the app bundle. |
178 subprocess_path = subprocess_path.DirName().DirName(); | 218 subprocess_path = subprocess_path.DirName().DirName(); |
179 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | 219 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
180 subprocess_path = | 220 subprocess_path = |
181 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); | 221 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 | 432 // On the Mac, this eventually reaches |
393 // -[BrowserWindowController windowWillClose:], which will post a deferred | 433 // -[BrowserWindowController windowWillClose:], which will post a deferred |
394 // -autorelease on itself to ultimately destroy the Browser object. The line | 434 // -autorelease on itself to ultimately destroy the Browser object. The line |
395 // below is necessary to pump these pending messages to ensure all Browsers | 435 // below is necessary to pump these pending messages to ensure all Browsers |
396 // get deleted. | 436 // get deleted. |
397 content::RunAllPendingInMessageLoop(); | 437 content::RunAllPendingInMessageLoop(); |
398 delete autorelease_pool_; | 438 delete autorelease_pool_; |
399 autorelease_pool_ = NULL; | 439 autorelease_pool_ = NULL; |
400 #endif | 440 #endif |
401 } | 441 } |
442 | |
443 #if defined(OS_WIN) && defined(USE_AURA) | |
444 //static | |
445 base::win::ScopedCOMInitializer* InProcessBrowserTest::com_initializer_ = NULL; | |
grt (UTC plus 2)
2013/06/20 23:10:06
i find it natural for static member definitions li
gab
2013/06/20 23:47:21
Done.
| |
446 #endif | |
OLD | NEW |