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

Unified Diff: chrome/test/base/in_process_browser_test.cc

Issue 582493002: Enable accessibility testing for the bookmark browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for Review Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/in_process_browser_test.cc
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index 5b01038eb80b7beadf7ddb349b1ddfaca63c81aa..1bc4b6d6e57a9292c64dab860a0a964fe0940d42 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -35,6 +35,7 @@
#include "chrome/common/logging_chrome.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
+#include "chrome/test/base/accessibility_test_helper.h"
#include "chrome/test/base/chrome_test_suite.h"
#include "chrome/test/base/test_launcher_utils.h"
#include "chrome/test/base/test_switches.h"
@@ -116,7 +117,8 @@ InProcessBrowserTest::InProcessBrowserTest()
: browser_(NULL),
exit_when_last_browser_closes_(true),
open_about_blank_on_browser_launch_(true),
- multi_desktop_test_(false)
+ multi_desktop_test_(false),
+ run_accessibility_checks_(false)
#if defined(OS_MACOSX)
, autorelease_pool_(NULL)
#endif // OS_MACOSX
@@ -260,6 +262,28 @@ void InProcessBrowserTest::PrepareTestCommandLine(
command_line->AppendArg(url::kAboutBlankURL);
}
+void InProcessBrowserTest::RunAccessibilityChecks() {
+ // A failure here means it is not possible to test for accessibility and it
Paweł Hajdan Jr. 2015/01/29 13:01:19 nit: All the comments in this method seem to just
hcarmona 2015/01/30 22:19:47 Done.
+ // doesn't make sense to continue.
+ ASSERT_TRUE(browser());
+ auto tab_strip = browser()->tab_strip_model();
+ ASSERT_TRUE(tab_strip);
+ auto web_contents = tab_strip->GetActiveWebContents();
+ ASSERT_TRUE(web_contents);
+ auto focused_frame = web_contents->GetFocusedFrame();
+ ASSERT_TRUE(focused_frame);
+
+ AccessibilityTestHelper helper;
+ // Failing to load libraries or failing to run the test is fatal.
+ ASSERT_TRUE(helper.LoadLibrary(web_contents));
+ ASSERT_TRUE(helper.RunAccessibilityTest(focused_frame));
+
+ // Failing the test is not fatal and we should continue to report other
+ // failures.
+ EXPECT_EQ(AccessibilityTestHelper::kExpectedResults,
+ helper.accessibility_message());
+}
+
bool InProcessBrowserTest::CreateUserDataDirectory() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
base::FilePath user_data_dir =
@@ -365,6 +389,14 @@ void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) {
browser->window()->Show();
}
+void InProcessBrowserTest::DisableAccessibilityChecks() {
+ run_accessibility_checks_for_test_case_ = false;
+}
+
+void InProcessBrowserTest::EnableAccessibilityChecks() {
+ run_accessibility_checks_for_test_case_ = true;
+}
+
#if !defined(OS_MACOSX)
base::CommandLine InProcessBrowserTest::GetCommandLineForRelaunch() {
base::CommandLine new_command_line(
@@ -439,12 +471,24 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
autorelease_pool_->Recycle();
#endif
+ // run_accessibility_checks_for_test_case_ must be set BEFORE calling
+ // RunTestOnMainThread because a test has the option to override the decision
+ // to run accessibility tests in the test body.
+ run_accessibility_checks_for_test_case_ = run_accessibility_checks_;
+
if (!HasFatalFailure())
RunTestOnMainThread();
#if defined(OS_MACOSX)
autorelease_pool_->Recycle();
#endif
+ // This will be true if
+ // - The current test called EnableAccessibilityChecks
+ // - The current test did NOT call DisableAccessibilityChecks and
+ // run_accessibility_checks_ is true.
+ if (run_accessibility_checks_for_test_case_)
+ RunAccessibilityChecks();
+
// Invoke cleanup and quit even if there are failures. This is similar to
// gtest in that it invokes TearDown even if Setup fails.
TearDownOnMainThread();

Powered by Google App Engine
This is Rietveld 408576698