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 FilePath::CharType kMockJSPath[] = | |
Sheridan Rawlins
2012/12/18 01:43:35
Any reason we can't keep these alphabetical?
aboxhall
2012/12/18 19:21:35
Nope. Done.
| |
50 FILE_PATH_LITERAL("chrome/third_party/mock4js/mock4js.js"); | |
49 const FilePath::CharType kMockJS[] = FILE_PATH_LITERAL("mock4js.js"); | 51 const FilePath::CharType kMockJS[] = FILE_PATH_LITERAL("mock4js.js"); |
52 const FilePath::CharType kA11yAuditLibraryJSPath[] = FILE_PATH_LITERAL( | |
53 "third_party/accessibility-developer-tools/gen/axs_testing.js"); | |
50 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); | 54 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); |
51 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); | 55 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); |
52 base::LazyInstance<std::vector<std::string> > error_messages_ = | 56 base::LazyInstance<std::vector<std::string> > error_messages_ = |
53 LAZY_INSTANCE_INITIALIZER; | 57 LAZY_INSTANCE_INITIALIZER; |
54 | 58 |
55 // Intercepts all log messages. | 59 // Intercepts all log messages. |
56 bool LogHandler(int severity, | 60 bool LogHandler(int severity, |
57 const char* file, | 61 const char* file, |
58 int line, | 62 int line, |
59 size_t message_start, | 63 size_t message_start, |
60 const std::string& str) { | 64 const std::string& str) { |
61 if (severity == logging::LOG_ERROR && | 65 if (severity == logging::LOG_ERROR && |
62 file && | 66 file && |
63 std::string("CONSOLE") == file) { | 67 std::string("CONSOLE") == file) { |
64 error_messages_.Get().push_back(str); | 68 error_messages_.Get().push_back(str); |
65 } | 69 } |
66 | 70 |
67 return false; | 71 return false; |
68 } | 72 } |
69 | 73 |
70 } // namespace | 74 } // namespace |
71 | 75 |
72 WebUIBrowserTest::~WebUIBrowserTest() {} | 76 WebUIBrowserTest::~WebUIBrowserTest() {} |
73 | 77 |
74 void WebUIBrowserTest::AddLibrary(const FilePath& library_path) { | 78 void WebUIBrowserTest::AddLibrary(const FilePath& library_path) { |
75 user_libraries_.push_back(library_path); | 79 user_libraries_.push_back(library_path); |
76 } | 80 } |
77 | 81 |
82 void WebUIBrowserTest::AddLibraryFromPath(const FilePath path) { | |
Sheridan Rawlins
2012/12/18 01:43:35
const FilePath& path
aboxhall
2012/12/18 19:21:35
Done.
| |
83 FilePath filePath; | |
84 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &filePath)); | |
85 filePath = filePath.Append(path); | |
86 AddLibrary(filePath); | |
87 } | |
88 | |
78 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { | 89 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { |
79 ConstValueVector empty_args; | 90 ConstValueVector empty_args; |
80 return RunJavascriptFunction(function_name, empty_args); | 91 return RunJavascriptFunction(function_name, empty_args); |
81 } | 92 } |
82 | 93 |
83 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name, | 94 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name, |
84 Value* arg) { | 95 Value* arg) { |
85 ConstValueVector args; | 96 ConstValueVector args; |
86 args.push_back(arg); | 97 args.push_back(arg); |
87 return RunJavascriptFunction(function_name, args); | 98 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); | 334 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); |
324 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, | 335 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, |
325 &gen_test_data_directory_)); | 336 &gen_test_data_directory_)); |
326 | 337 |
327 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. | 338 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. |
328 FilePath resources_pack_path; | 339 FilePath resources_pack_path; |
329 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 340 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
330 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 341 ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
331 resources_pack_path, ui::SCALE_FACTOR_NONE); | 342 resources_pack_path, ui::SCALE_FACTOR_NONE); |
332 | 343 |
333 FilePath mockPath; | 344 AddLibraryFromPath(FilePath(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)); | 345 AddLibrary(FilePath(kWebUILibraryJS)); |
346 AddLibraryFromPath(FilePath(kA11yAuditLibraryJSPath)); | |
341 } | 347 } |
342 | 348 |
343 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { | 349 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { |
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; |
(...skipping 348 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 |