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 char kPassHTML[] = "chrome/test/data/accessibility_pass.html"; |
| 88 const char kFailHTML[] = "chrome/test/data/accessibility_fail.html"; |
| 89 |
| 90 /* |
| 91 * This class is meant as a test for the accessibility audit in the |
| 92 * InProcessBrowserTest. These tests do NOT validate the accessibility audit, |
| 93 * just the ability to run it. |
| 94 */ |
| 95 class InProcessAccessibilityBrowsertest : public InProcessBrowserTest { |
| 96 protected: |
| 97 // Construct a URL from a file path that can be used to get to a web page. |
| 98 base::FilePath BuildURLToFile(const char* file_path) { |
| 99 base::FilePath source_root; |
| 100 if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root)) |
| 101 return base::FilePath(); |
| 102 return source_root.Append(file_path); |
| 103 } |
| 104 |
| 105 bool NavigateToURL(const char* address) { |
| 106 GURL url = net::FilePathToFileURL(BuildURLToFile(address)); |
| 107 |
| 108 if (!url.is_valid() || url.is_empty() || !browser()) |
| 109 return false; |
| 110 |
| 111 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 112 browser(), url, 1); |
| 113 return true; |
| 114 } |
| 115 }; |
| 116 |
| 117 // Test that an accessible page doesn't fail the accessibility audit. |
| 118 IN_PROC_BROWSER_TEST_F( |
| 119 InProcessAccessibilityBrowsertest, VerifyAccessibilityPass) { |
| 120 |
| 121 ASSERT_TRUE(NavigateToURL(kPassHTML)); |
| 122 |
| 123 std::string test_result; |
| 124 EXPECT_TRUE(RunAccessibilityChecks(&test_result)); |
| 125 |
| 126 // No error message on success. |
| 127 EXPECT_EQ("", test_result); |
| 128 } |
| 129 |
| 130 // Test that a page that is not accessible will fail the accessibility audit. |
| 131 IN_PROC_BROWSER_TEST_F( |
| 132 InProcessAccessibilityBrowsertest, VerifyAccessibilityFail) { |
| 133 |
| 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 |