Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/ui/webui/web_ui_browsertest.cc

Issue 11363170: Add an accessibility audit test for WebUI pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reinstate copyright header Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/gtest/single_test_runner.py ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 kMockJS[] = FILE_PATH_LITERAL("mock4js.js"); 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");
49 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); 52 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js");
50 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); 53 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui");
51 base::LazyInstance<std::vector<std::string> > error_messages_ = 54 base::LazyInstance<std::vector<std::string> > error_messages_ =
52 LAZY_INSTANCE_INITIALIZER; 55 LAZY_INSTANCE_INITIALIZER;
53 56
54 // Intercepts all log messages. 57 // Intercepts all log messages.
55 bool LogHandler(int severity, 58 bool LogHandler(int severity,
56 const char* file, 59 const char* file,
57 int line, 60 int line,
58 size_t message_start, 61 size_t message_start,
59 const std::string& str) { 62 const std::string& str) {
60 if (severity == logging::LOG_ERROR && 63 if (severity == logging::LOG_ERROR &&
61 file && 64 file &&
62 std::string("CONSOLE") == file) { 65 std::string("CONSOLE") == file) {
63 error_messages_.Get().push_back(str); 66 error_messages_.Get().push_back(str);
64 } 67 }
65 68
66 return false; 69 return false;
67 } 70 }
68 71
69 } // namespace 72 } // namespace
70 73
71 WebUIBrowserTest::~WebUIBrowserTest() {} 74 WebUIBrowserTest::~WebUIBrowserTest() {}
72 75
73 void WebUIBrowserTest::AddLibrary(const FilePath& library_path) { 76 void WebUIBrowserTest::AddLibrary(const FilePath& library_path) {
74 user_libraries_.push_back(library_path); 77 user_libraries_.push_back(library_path);
75 } 78 }
76 79
80 // Add a helper JS library to the given WebUIBrowserTest from a path relative to
81 // base::DIR_SOURCE_ROOT.
82 // static
83 void AddLibraryFromSourceRoot(WebUIBrowserTest* browser_test,
84 const FilePath& path) {
85 FilePath filePath;
86 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &filePath));
87 filePath = filePath.Append(path);
88 browser_test->AddLibrary(filePath);
89 }
90
77 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { 91 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) {
78 ConstValueVector empty_args; 92 ConstValueVector empty_args;
79 return RunJavascriptFunction(function_name, empty_args); 93 return RunJavascriptFunction(function_name, empty_args);
80 } 94 }
81 95
82 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name, 96 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name,
83 Value* arg) { 97 Value* arg) {
84 ConstValueVector args; 98 ConstValueVector args;
85 args.push_back(arg); 99 args.push_back(arg);
86 return RunJavascriptFunction(function_name, args); 100 return RunJavascriptFunction(function_name, args);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); 336 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder);
323 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, 337 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA,
324 &gen_test_data_directory_)); 338 &gen_test_data_directory_));
325 339
326 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. 340 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test.
327 FilePath resources_pack_path; 341 FilePath resources_pack_path;
328 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); 342 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
329 ResourceBundle::GetSharedInstance().AddDataPackFromPath( 343 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
330 resources_pack_path, ui::SCALE_FACTOR_NONE); 344 resources_pack_path, ui::SCALE_FACTOR_NONE);
331 345
332 FilePath mockPath; 346 AddLibraryFromSourceRoot(this, FilePath(kA11yAuditLibraryJSPath));
333 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &mockPath)); 347 AddLibraryFromSourceRoot(this, FilePath(kMockJSPath));
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)); 348 AddLibrary(FilePath(kWebUILibraryJS));
340 } 349 }
341 350
342 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { 351 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() {
343 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 352 InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
344 TestChromeWebUIControllerFactory::RemoveFactoryOverride( 353 TestChromeWebUIControllerFactory::RemoveFactoryOverride(
345 GURL(kDummyURL).host()); 354 GURL(kDummyURL).host());
346 } 355 }
347 356
348 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { 357 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // testDone directly and expect pass result. 707 // testDone directly and expect pass result.
699 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { 708 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) {
700 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); 709 ASSERT_TRUE(RunJavascriptAsyncTest("testDone"));
701 } 710 }
702 711
703 // Test that calling testDone during RunJavascriptTest still completes when 712 // Test that calling testDone during RunJavascriptTest still completes when
704 // waiting for async result. 713 // waiting for async result.
705 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { 714 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) {
706 ASSERT_TRUE(RunJavascriptTest("testDone")); 715 ASSERT_TRUE(RunJavascriptTest("testDone"));
707 } 716 }
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/single_test_runner.py ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698