OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
Paweł Hajdan Jr.
2015/01/29 13:01:19
nit: 2015
Also since this file is a browser test,
hcarmona
2015/01/30 22:19:47
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/files/file_util.h" | |
6 #include "base/path_service.h" | |
7 #include "chrome/browser/ui/browser.h" | |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
9 #include "chrome/test/base/accessibility_test_helper.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | |
11 #include "chrome/test/base/ui_test_utils.h" | |
12 #include "net/base/filename_util.h" | |
13 | |
14 // Paths are to very simple HTML files. One is accessible, the other is not. | |
15 const base::FilePath kPassHTML( | |
16 FILE_PATH_LITERAL("chrome/test/data/accessibility_pass.html")); | |
17 const base::FilePath kFailHTML( | |
18 FILE_PATH_LITERAL("chrome/test/data/accessibility_fail.html")); | |
19 | |
20 /* | |
21 * This class is meant as a test for the AccessibilityTestHelper. | |
22 * This test does NOT validate the accessibility tests, just the helper. | |
23 */ | |
24 class AccessibilityTestHelperTest : public InProcessBrowserTest { | |
25 protected: | |
26 // These data members are populated when navigating to a URL. | |
27 TabStripModel* tab_strip_model_; | |
28 content::WebContents* active_web_contents_; | |
29 content::RenderFrameHost* focused_frame_; | |
30 | |
31 // Construct a URL from a file path that can be used to get to a web page. | |
32 base::FilePath BuildURLToFile(const base::FilePath file_path) { | |
33 base::FilePath source_root; | |
34 if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root)) | |
35 return base::FilePath(); | |
36 return source_root.Append(file_path); | |
37 } | |
38 | |
39 bool NavigateToURL(base::FilePath address) { | |
40 GURL url = net::FilePathToFileURL(BuildURLToFile(address)); | |
41 | |
42 if (!url.is_valid() || url.is_empty() || !browser()) | |
43 return false; | |
44 | |
45 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | |
46 url, 1); | |
47 | |
48 if (!(tab_strip_model_ = browser()->tab_strip_model())) | |
49 return false; | |
50 | |
51 if (!(active_web_contents_ = tab_strip_model_->GetActiveWebContents())) | |
52 return false; | |
53 | |
54 if (!(focused_frame_ = active_web_contents_->GetFocusedFrame())) | |
55 return false; | |
56 | |
57 return true; | |
58 } | |
59 }; | |
60 | |
61 // This test case is important because we want to make sure that an accessible | |
62 // page doesn't fail. | |
63 IN_PROC_BROWSER_TEST_F(AccessibilityTestHelperTest, VerifyAccessibilityPass) { | |
64 ASSERT_TRUE(NavigateToURL(kPassHTML)); | |
65 | |
66 // Run accessibility testing | |
67 AccessibilityTestHelper helper; | |
68 ASSERT_TRUE(helper.LoadLibrary(active_web_contents_)); | |
69 ASSERT_TRUE(helper.RunAccessibilityTest(focused_frame_)); | |
70 | |
71 // We expect the actual results to be equal to the expected results because | |
72 // this page is accessible. | |
73 EXPECT_EQ( | |
74 AccessibilityTestHelper::kExpectedResults, | |
75 helper.accessibility_message()); | |
76 } | |
77 | |
78 // This test case is important because we want to make sure that a page that | |
79 // isn't accessible will fail. | |
80 IN_PROC_BROWSER_TEST_F(AccessibilityTestHelperTest, VerifyAccessibilityFail) { | |
81 ASSERT_TRUE(NavigateToURL(kFailHTML)); | |
82 | |
83 // Run accessibility testing | |
84 AccessibilityTestHelper helper; | |
85 ASSERT_TRUE(helper.LoadLibrary(active_web_contents_)); | |
86 ASSERT_TRUE(helper.RunAccessibilityTest(focused_frame_)); | |
87 | |
88 // We expect the actual results to not equal the expected results because | |
89 // this page is not accessible, so the helper should fail it. | |
90 EXPECT_NE( | |
91 AccessibilityTestHelper::kExpectedResults, | |
92 helper.accessibility_message()); | |
93 } | |
94 | |
OLD | NEW |