Index: chrome/test/base/accessibility_test_helper_test.cc |
diff --git a/chrome/test/base/accessibility_test_helper_test.cc b/chrome/test/base/accessibility_test_helper_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8baf12189b771595a9c7977d3b7742e7e4ea7da |
--- /dev/null |
+++ b/chrome/test/base/accessibility_test_helper_test.cc |
@@ -0,0 +1,94 @@ |
+// 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.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/files/file_util.h" |
+#include "base/path_service.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "chrome/test/base/accessibility_test_helper.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
+#include "chrome/test/base/ui_test_utils.h" |
+#include "net/base/filename_util.h" |
+ |
+// Paths are to very simple HTML files. One is accessible, the other is not. |
+const base::FilePath kPassHTML( |
+ FILE_PATH_LITERAL("chrome/test/data/accessibility_pass.html")); |
+const base::FilePath kFailHTML( |
+ FILE_PATH_LITERAL("chrome/test/data/accessibility_fail.html")); |
+ |
+/* |
+ * This class is meant as a test for the AccessibilityTestHelper. |
+ * This test does NOT validate the accessibility tests, just the helper. |
+ */ |
+class AccessibilityTestHelperTest : public InProcessBrowserTest { |
+ protected: |
+ // These data members are populated when navigating to a URL. |
+ TabStripModel* tab_strip_model_; |
+ content::WebContents* active_web_contents_; |
+ content::RenderFrameHost* focused_frame_; |
+ |
+ // Construct a URL from a file path that can be used to get to a web page. |
+ base::FilePath BuildURLToFile(const base::FilePath file_path) { |
+ base::FilePath source_root; |
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root)) |
+ return base::FilePath(); |
+ return source_root.Append(file_path); |
+ } |
+ |
+ bool NavigateToURL(base::FilePath address) { |
+ GURL url = net::FilePathToFileURL(BuildURLToFile(address)); |
+ |
+ if (!url.is_valid() || url.is_empty() || !browser()) |
+ return false; |
+ |
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
+ url, 1); |
+ |
+ if (!(tab_strip_model_ = browser()->tab_strip_model())) |
+ return false; |
+ |
+ if (!(active_web_contents_ = tab_strip_model_->GetActiveWebContents())) |
+ return false; |
+ |
+ if (!(focused_frame_ = active_web_contents_->GetFocusedFrame())) |
+ return false; |
+ |
+ return true; |
+ } |
+}; |
+ |
+// This test case is important because we want to make sure that an accessible |
+// page doesn't fail. |
+IN_PROC_BROWSER_TEST_F(AccessibilityTestHelperTest, VerifyAccessibilityPass) { |
+ ASSERT_TRUE(NavigateToURL(kPassHTML)); |
+ |
+ // Run accessibility testing |
+ AccessibilityTestHelper helper; |
+ ASSERT_TRUE(helper.LoadLibrary(active_web_contents_)); |
+ ASSERT_TRUE(helper.RunAccessibilityTest(focused_frame_)); |
+ |
+ // We expect the actual results to be equal to the expected results because |
+ // this page is accessible. |
+ EXPECT_EQ( |
+ AccessibilityTestHelper::kExpectedResults, |
+ helper.accessibility_message()); |
+} |
+ |
+// This test case is important because we want to make sure that a page that |
+// isn't accessible will fail. |
+IN_PROC_BROWSER_TEST_F(AccessibilityTestHelperTest, VerifyAccessibilityFail) { |
+ ASSERT_TRUE(NavigateToURL(kFailHTML)); |
+ |
+ // Run accessibility testing |
+ AccessibilityTestHelper helper; |
+ ASSERT_TRUE(helper.LoadLibrary(active_web_contents_)); |
+ ASSERT_TRUE(helper.RunAccessibilityTest(focused_frame_)); |
+ |
+ // We expect the actual results to not equal the expected results because |
+ // this page is not accessible, so the helper should fail it. |
+ EXPECT_NE( |
+ AccessibilityTestHelper::kExpectedResults, |
+ helper.accessibility_message()); |
+} |
+ |