Chromium Code Reviews| 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/browser/ui/webui/web_ui_browsertest.h" | 5 #include "chrome/browser/ui/webui/web_ui_browsertest.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "ui/base/resource/resource_handle.h" | 39 #include "ui/base/resource/resource_handle.h" |
| 40 | 40 |
| 41 using content::NavigationController; | 41 using content::NavigationController; |
| 42 using content::RenderViewHost; | 42 using content::RenderViewHost; |
| 43 using content::WebContents; | 43 using content::WebContents; |
| 44 using content::WebUIController; | 44 using content::WebUIController; |
| 45 using content::WebUIMessageHandler; | 45 using content::WebUIMessageHandler; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 const std::string kMockJSPath = "chrome/third_party/mock4js/mock4js.js"; | |
|
Sheridan Rawlins
2012/12/18 01:43:35
Why aren't these also FILE_PATH_LITERALs?
| |
| 49 const FilePath::CharType kMockJS[] = FILE_PATH_LITERAL("mock4js.js"); | 50 const FilePath::CharType kMockJS[] = FILE_PATH_LITERAL("mock4js.js"); |
| 51 const std::string kA11yAuditLibraryJSPath = | |
| 52 "third_party/accessibility-developer-tools/gen/axs_testing.js"; | |
| 50 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); | 53 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); |
| 51 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); | 54 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); |
| 52 base::LazyInstance<std::vector<std::string> > error_messages_ = | 55 base::LazyInstance<std::vector<std::string> > error_messages_ = |
| 53 LAZY_INSTANCE_INITIALIZER; | 56 LAZY_INSTANCE_INITIALIZER; |
| 54 | 57 |
| 55 // Intercepts all log messages. | 58 // Intercepts all log messages. |
| 56 bool LogHandler(int severity, | 59 bool LogHandler(int severity, |
| 57 const char* file, | 60 const char* file, |
| 58 int line, | 61 int line, |
| 59 size_t message_start, | 62 size_t message_start, |
| 60 const std::string& str) { | 63 const std::string& str) { |
| 61 if (severity == logging::LOG_ERROR && | 64 if (severity == logging::LOG_ERROR && |
| 62 file && | 65 file && |
| 63 std::string("CONSOLE") == file) { | 66 std::string("CONSOLE") == file) { |
| 64 error_messages_.Get().push_back(str); | 67 error_messages_.Get().push_back(str); |
| 65 } | 68 } |
| 66 | 69 |
| 67 return false; | 70 return false; |
| 68 } | 71 } |
| 69 | 72 |
| 70 } // namespace | 73 } // namespace |
| 71 | 74 |
| 72 WebUIBrowserTest::~WebUIBrowserTest() {} | 75 WebUIBrowserTest::~WebUIBrowserTest() {} |
| 73 | 76 |
| 74 void WebUIBrowserTest::AddLibrary(const FilePath& library_path) { | 77 void WebUIBrowserTest::AddLibrary(const FilePath& library_path) { |
| 75 user_libraries_.push_back(library_path); | 78 user_libraries_.push_back(library_path); |
| 76 } | 79 } |
| 77 | 80 |
| 81 void WebUIBrowserTest::AddLibraryFromUTFPath(const std::string path) { | |
| 82 FilePath filePath; | |
| 83 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &filePath)); | |
| 84 filePath = filePath.Append(FilePath::FromUTF8Unsafe(path)); | |
| 85 AddLibrary(filePath); | |
| 86 } | |
| 87 | |
| 78 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { | 88 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { |
| 79 ConstValueVector empty_args; | 89 ConstValueVector empty_args; |
| 80 return RunJavascriptFunction(function_name, empty_args); | 90 return RunJavascriptFunction(function_name, empty_args); |
| 81 } | 91 } |
| 82 | 92 |
| 83 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name, | 93 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name, |
| 84 Value* arg) { | 94 Value* arg) { |
| 85 ConstValueVector args; | 95 ConstValueVector args; |
| 86 args.push_back(arg); | 96 args.push_back(arg); |
| 87 return RunJavascriptFunction(function_name, args); | 97 return RunJavascriptFunction(function_name, args); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); | 333 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); |
| 324 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, | 334 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, |
| 325 &gen_test_data_directory_)); | 335 &gen_test_data_directory_)); |
| 326 | 336 |
| 327 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. | 337 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. |
| 328 FilePath resources_pack_path; | 338 FilePath resources_pack_path; |
| 329 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 339 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 330 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 340 ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| 331 resources_pack_path, ui::SCALE_FACTOR_NONE); | 341 resources_pack_path, ui::SCALE_FACTOR_NONE); |
| 332 | 342 |
| 333 FilePath mockPath; | 343 AddLibraryFromUTFPath(kMockJSPath); |
| 334 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &mockPath)); | |
| 335 mockPath = mockPath.AppendASCII("chrome"); | |
| 336 mockPath = mockPath.AppendASCII("third_party"); | |
| 337 mockPath = mockPath.AppendASCII("mock4js"); | |
| 338 mockPath = mockPath.Append(kMockJS); | |
| 339 AddLibrary(mockPath); | |
| 340 AddLibrary(FilePath(kWebUILibraryJS)); | 344 AddLibrary(FilePath(kWebUILibraryJS)); |
| 345 AddLibraryFromUTFPath(kA11yAuditLibraryJSPath); | |
| 341 } | 346 } |
| 342 | 347 |
| 343 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { | 348 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { |
| 349 // EXPECT_TRUE(RunJavascriptTest("runAccessibilityAudit")); | |
| 344 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 350 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
| 345 TestChromeWebUIControllerFactory::RemoveFactoryOverride( | 351 TestChromeWebUIControllerFactory::RemoveFactoryOverride( |
| 346 GURL(kDummyURL).host()); | 352 GURL(kDummyURL).host()); |
| 347 } | 353 } |
| 348 | 354 |
| 349 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { | 355 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { |
| 350 override_selected_web_ui_ = web_ui; | 356 override_selected_web_ui_ = web_ui; |
| 351 } | 357 } |
| 352 | 358 |
| 353 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { | 359 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 // testDone directly and expect pass result. | 705 // testDone directly and expect pass result. |
| 700 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 706 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 701 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 707 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 702 } | 708 } |
| 703 | 709 |
| 704 // Test that calling testDone during RunJavascriptTest still completes when | 710 // Test that calling testDone during RunJavascriptTest still completes when |
| 705 // waiting for async result. | 711 // waiting for async result. |
| 706 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 712 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 707 ASSERT_TRUE(RunJavascriptTest("testDone")); | 713 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 708 } | 714 } |
| OLD | NEW |