OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string.h> | 5 #include <string.h> |
6 | 6 |
| 7 #include "base/files/file_util.h" |
| 8 #include "base/path_service.h" |
7 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "net/base/filename_util.h" |
14 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 class InProcessBrowserTestP | 22 class InProcessBrowserTestP |
20 : public InProcessBrowserTest, | 23 : public InProcessBrowserTest, |
21 public ::testing::WithParamInterface<const char*> { | 24 public ::testing::WithParamInterface<const char*> { |
22 }; | 25 }; |
23 | 26 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 for (size_t i = 0; i < arraysize(kURLs); ++i) { | 76 for (size_t i = 0; i < arraysize(kURLs); ++i) { |
74 GURL url(kURLs[i]); | 77 GURL url(kURLs[i]); |
75 LoadFailObserver observer(contents); | 78 LoadFailObserver observer(contents); |
76 ui_test_utils::NavigateToURL(browser(), url); | 79 ui_test_utils::NavigateToURL(browser(), url); |
77 EXPECT_TRUE(observer.failed_load()); | 80 EXPECT_TRUE(observer.failed_load()); |
78 EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, observer.error_code()); | 81 EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, observer.error_code()); |
79 EXPECT_EQ(url, observer.validated_url()); | 82 EXPECT_EQ(url, observer.validated_url()); |
80 } | 83 } |
81 } | 84 } |
82 | 85 |
| 86 // Paths are to very simple HTML files. One is accessible, the other is not. |
| 87 const base::FilePath::CharType kPassHTML[] = |
| 88 FILE_PATH_LITERAL("chrome/test/data/accessibility_pass.html"); |
| 89 const base::FilePath::CharType kFailHTML[] = |
| 90 FILE_PATH_LITERAL("chrome/test/data/accessibility_fail.html"); |
| 91 |
| 92 /* |
| 93 * This class is meant as a test for the accessibility audit in the |
| 94 * InProcessBrowserTest. These tests do NOT validate the accessibility audit, |
| 95 * just the ability to run it. |
| 96 */ |
| 97 class InProcessAccessibilityBrowserTest : public InProcessBrowserTest { |
| 98 protected: |
| 99 // Construct a URL from a file path that can be used to get to a web page. |
| 100 base::FilePath BuildURLToFile(const base::FilePath::CharType* file_path) { |
| 101 base::FilePath source_root; |
| 102 if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root)) |
| 103 return base::FilePath(); |
| 104 return source_root.Append(file_path); |
| 105 } |
| 106 |
| 107 bool NavigateToURL(const base::FilePath::CharType* address) { |
| 108 GURL url = net::FilePathToFileURL(BuildURLToFile(address)); |
| 109 |
| 110 if (!url.is_valid() || url.is_empty() || !browser()) |
| 111 return false; |
| 112 |
| 113 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 114 browser(), url, 1); |
| 115 return true; |
| 116 } |
| 117 }; |
| 118 |
| 119 // Test that an accessible page doesn't fail the accessibility audit. |
| 120 IN_PROC_BROWSER_TEST_F( |
| 121 InProcessAccessibilityBrowserTest, VerifyAccessibilityPass) { |
| 122 ASSERT_TRUE(NavigateToURL(kPassHTML)); |
| 123 |
| 124 std::string test_result; |
| 125 EXPECT_TRUE(RunAccessibilityChecks(&test_result)); |
| 126 |
| 127 // No error message on success. |
| 128 EXPECT_EQ("", test_result); |
| 129 } |
| 130 |
| 131 // Test that a page that is not accessible will fail the accessibility audit. |
| 132 IN_PROC_BROWSER_TEST_F( |
| 133 InProcessAccessibilityBrowserTest, VerifyAccessibilityFail) { |
| 134 ASSERT_TRUE(NavigateToURL(kFailHTML)); |
| 135 |
| 136 std::string test_result; |
| 137 EXPECT_FALSE(RunAccessibilityChecks(&test_result)); |
| 138 |
| 139 // Error should NOT be empty on failure. |
| 140 EXPECT_NE("", test_result); |
| 141 } |
| 142 |
83 } // namespace | 143 } // namespace |
OLD | NEW |