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 #include "chrome/browser/ui/webui/web_ui_browsertest.h" | 4 #include "chrome/browser/ui/webui/web_ui_browsertest.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | |
15 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
18 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
19 #include "content/browser/webui/web_ui.h" | 18 #include "content/browser/webui/web_ui.h" |
20 #include "testing/gtest/include/gtest/gtest-spi.h" | 19 #include "testing/gtest/include/gtest/gtest-spi.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); | 24 const FilePath::StringType kWebUILibraryJS = |
26 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); | 25 FILE_PATH_LITERAL("test_api.js"); |
| 26 const FilePath::StringType kWebUITestFolder = FILE_PATH_LITERAL("webui"); |
27 base::LazyInstance<std::vector<std::string> > error_messages_( | 27 base::LazyInstance<std::vector<std::string> > error_messages_( |
28 base::LINKER_INITIALIZED); | 28 base::LINKER_INITIALIZED); |
29 | 29 |
30 // Intercepts all log messages. | 30 // Intercepts all log messages. |
31 bool LogHandler(int severity, | 31 bool LogHandler(int severity, |
32 const char* file, | 32 const char* file, |
33 int line, | 33 int line, |
34 size_t message_start, | 34 size_t message_start, |
35 const std::string& str) { | 35 const std::string& str) { |
36 if (severity == logging::LOG_ERROR) | 36 if (severity == logging::LOG_ERROR) |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 static WebUIBrowserTest* s_test_; | 237 static WebUIBrowserTest* s_test_; |
238 }; | 238 }; |
239 WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; | 239 WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; |
240 | 240 |
241 IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { | 241 IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { |
242 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); | 242 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); |
243 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | 243 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); |
244 EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"), | 244 EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"), |
245 "WebUITestHandler::Observe"); | 245 "WebUITestHandler::Observe"); |
246 } | 246 } |
247 | |
248 | |
249 // This test framework is used in the generated tests, which are included | |
250 // below. WebUIBrowserTest requires being on a page which is a WebUI page. Using | |
251 // the TestChromeWebUIFactory, we use a dummy URL |kChromeTestBrowserTestPass|, | |
252 // which we force to be a WebUI page. | |
253 class WebUIBrowserTestPass | |
254 : public WebUIBrowserTest, | |
255 public TestChromeWebUIFactory::WebUIProvider { | |
256 private: | |
257 // TestChromeWebUIFactory::WebUIProvider: | |
258 virtual WebUI* NewWebUI(TabContents* tab_contents, | |
259 const GURL& url) OVERRIDE { | |
260 return new WebUI(tab_contents); | |
261 } | |
262 | |
263 // InProcessBrowserTest: | |
264 virtual void SetUpOnMainThread() OVERRIDE { | |
265 WebUIBrowserTest::SetUpOnMainThread(); | |
266 ui_test_utils::NavigateToURL(browser(), | |
267 GURL(kChromeTestBrowserTestPass)); | |
268 } | |
269 | |
270 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
271 WebUIBrowserTest::SetUpInProcessBrowserTestFixture(); | |
272 TestChromeWebUIFactory::AddFactoryOverride( | |
273 GURL(kChromeTestBrowserTestPass).host(), this); | |
274 } | |
275 | |
276 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
277 WebUIBrowserTest::TearDownInProcessBrowserTestFixture(); | |
278 TestChromeWebUIFactory::RemoveFactoryOverride( | |
279 GURL(kChromeTestBrowserTestPass).host()); | |
280 } | |
281 | |
282 static const char kChromeTestBrowserTestPass[]; | |
283 }; | |
284 | |
285 const char WebUIBrowserTestPass::kChromeTestBrowserTestPass[] = | |
286 "chrome://WebUIBrowserTestPass"; | |
287 | |
288 #include "chrome/browser/ui/webui/web_ui_browsertest-inl.h" | |
OLD | NEW |