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