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" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "chrome/test/ui_test_utils.h" | 17 #include "chrome/test/ui_test_utils.h" |
17 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
18 #include "content/browser/webui/web_ui.h" | 19 #include "content/browser/webui/web_ui.h" |
19 #include "testing/gtest/include/gtest/gtest-spi.h" | 20 #include "testing/gtest/include/gtest/gtest-spi.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const FilePath::StringType kWebUILibraryJS = | 25 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); |
25 FILE_PATH_LITERAL("test_api.js"); | 26 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); |
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 static WebUIBrowserTest* s_test_; | 271 static WebUIBrowserTest* s_test_; |
272 }; | 272 }; |
273 WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; | 273 WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; |
274 | 274 |
275 IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { | 275 IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { |
276 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); | 276 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); |
277 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | 277 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); |
278 EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"), | 278 EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"), |
279 "WebUITestHandler::Observe"); | 279 "WebUITestHandler::Observe"); |
280 } | 280 } |
| 281 |
| 282 |
| 283 // crbug.com/88104 - v8_shell#host doesn't build when host=="arm". |
| 284 #if !defined(ARCH_CPU_ARM_FAMILY) |
| 285 // This test framework is used in the generated tests, which are included |
| 286 // below. WebUIBrowserTest requires being on a page which is a WebUI page. Using |
| 287 // the TestChromeWebUIFactory, we use a dummy URL |kChromeTestBrowserTestPass|, |
| 288 // which we force to be a WebUI page. |
| 289 class WebUIBrowserTestPass |
| 290 : public WebUIBrowserTest, |
| 291 public TestChromeWebUIFactory::WebUIProvider { |
| 292 private: |
| 293 // TestChromeWebUIFactory::WebUIProvider: |
| 294 virtual WebUI* NewWebUI(TabContents* tab_contents, |
| 295 const GURL& url) OVERRIDE { |
| 296 return new WebUI(tab_contents); |
| 297 } |
| 298 |
| 299 // InProcessBrowserTest: |
| 300 virtual void SetUpOnMainThread() OVERRIDE { |
| 301 WebUIBrowserTest::SetUpOnMainThread(); |
| 302 ui_test_utils::NavigateToURL(browser(), |
| 303 GURL(kChromeTestBrowserTestPass)); |
| 304 } |
| 305 |
| 306 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 307 WebUIBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 308 TestChromeWebUIFactory::AddFactoryOverride( |
| 309 GURL(kChromeTestBrowserTestPass).host(), this); |
| 310 } |
| 311 |
| 312 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 313 WebUIBrowserTest::TearDownInProcessBrowserTestFixture(); |
| 314 TestChromeWebUIFactory::RemoveFactoryOverride( |
| 315 GURL(kChromeTestBrowserTestPass).host()); |
| 316 } |
| 317 |
| 318 static const char kChromeTestBrowserTestPass[]; |
| 319 }; |
| 320 |
| 321 const char WebUIBrowserTestPass::kChromeTestBrowserTestPass[] = |
| 322 "chrome://WebUIBrowserTestPass"; |
| 323 |
| 324 #include "chrome/test/data/webui/sample_pass-inl.h" |
| 325 |
| 326 #endif // !defined(ARCH_CPU_ARM_FAMILY) |
OLD | NEW |