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

Unified Diff: chrome/browser/ui/webui/options/language_options_interactive_uitest.cc

Issue 464703002: Fixed a11y tab-handling for language settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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/browser/ui/webui/options/language_options_interactive_uitest.cc
diff --git a/chrome/browser/ui/webui/options/language_options_interactive_uitest.cc b/chrome/browser/ui/webui/options/language_options_interactive_uitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd7342720fe2de2203fb79db366bd10dc3a1efec
--- /dev/null
+++ b/chrome/browser/ui/webui/options/language_options_interactive_uitest.cc
@@ -0,0 +1,183 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/chrome_pages.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/browser_test_utils.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/events/test/event_generator.h"
+
+namespace language_options_ui_test {
+
+namespace {
+
+// TODO(hcarmona): Figure out a better way of getting this constant.
+const char kAcceptLanguages[] = "intl.accept_languages";
+
+// This class will test the language options settings.
+// We need to emulate button pushing because we are testing accessibility,
+// this means that this is part of interactive_ui_tests.
+class LanguageOptionsInteractiveTest : public InProcessBrowserTest {
+ public:
+ LanguageOptionsInteractiveTest() {}
+
+ protected:
+ // This method will navigate to the language settings page and show
+ // a subset of languages from the list of available languages that is not
+ // the default.
+ bool NavigateToLanguagePage() {
+ const GURL& url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage);
groby-ooo-7-16 2014/08/12 23:57:27 Make this non-ref. GetSettingsUrl returns an objec
hcarmona 2014/08/13 20:24:39 Done.
+ ui_test_utils::NavigateToURL(browser(), url);
+ browser()->profile()->GetPrefs()->SetString(
+ kAcceptLanguages, "en-US,es,fr");
+ return true;
+ }
+
+ bool GetActiveElementId(std::string *element_id) {
+ content::RenderFrameHost* active_frame = NULL;
+ if (!GetActiveFrame(active_frame))
+ return false;
+
+ return content::ExecuteScriptAndExtractString(
+ active_frame,
+ "domAutomationController.send(document.activeElement.id);",
+ element_id);
+ }
+
+ // Will get the active frame. Returns false on error.
+ bool GetActiveFrame(content::RenderFrameHost* &active_frame) {
groby-ooo-7-16 2014/08/12 23:57:27 No outparams via ref, sorry :( - Here and elsewhe
hcarmona 2014/08/13 20:24:39 Done.
+ content::WebContents* web_contents = NULL;
+ if (GetActiveWebContents(web_contents)) {
groby-ooo-7-16 2014/08/12 23:57:27 If this "should never happen", it's OK to just get
hcarmona 2014/08/13 20:24:39 Done.
+ active_frame = web_contents->GetFocusedFrame();
+ return active_frame;
+ }
+
+ return false;
+ }
+
+ // Will get the active web contents. Returns false on error.
+ bool GetActiveWebContents(content::WebContents* &web_contents) {
+ if (browser()) {
+ if (TabStripModel* tab_strip_model = browser()->tab_strip_model()) {
+ web_contents = tab_strip_model->GetActiveWebContents();
+ return web_contents;
+ }
+ }
+
+ return false;
+ }
+
+ // Press and release a key in a particular window. Returns false on error.
+ bool PressKey(ui::KeyboardCode key_code) {
+ gfx::NativeWindow native_window = NULL;
+ if (!GetNativeWindow(native_window))
groby-ooo-7-16 2014/08/12 23:57:27 NULL check not needed if this should always be not
hcarmona 2014/08/13 20:24:39 Done.
+ return false;
+
+ ui::test::EventGenerator eventGen(native_window);
+ eventGen.PressKey(key_code, ui::EF_NONE);
+ eventGen.ReleaseKey(key_code, ui::EF_NONE);
+ return true;
+ }
+
+ protected:
+ // Will get the native window. Returns false on error.
+ bool GetNativeWindow(gfx::NativeWindow &native_window) {
groby-ooo-7-16 2014/08/12 23:57:27 Chrome's code standard doesn't allow out parameter
hcarmona 2014/08/13 20:24:39 Done.
+ if (browser()) {
+ if (BrowserWindow* window = browser()->window()) {
+ native_window = window->GetNativeWindow();
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LanguageOptionsInteractiveTest);
+};
+
+} // namespace
+
+// This test will verify that after calling NavigateToLanguagePage
+// we are in the correct page.
+// TODO(hcarmona):
+// Is this test necessary? All other tests will fail if this one fails.
groby-ooo-7-16 2014/08/12 23:57:28 If this is a precondition, I'd handle this in the
hcarmona 2014/08/13 20:24:39 Done.
+// How to handle change in title format? (that would break this test)
groby-ooo-7-16 2014/08/12 23:57:27 Don't worry about that - it's up to the person cha
hcarmona 2014/08/13 20:24:39 Acknowledged.
+IN_PROC_BROWSER_TEST_F(LanguageOptionsInteractiveTest, TestNavigateToLanguage) {
+ ASSERT_TRUE(NavigateToLanguagePage());
+
+ content::WebContents* web_contents = NULL;
+ ASSERT_TRUE(GetActiveWebContents(web_contents));
+
+ base::string16 expected_title = l10n_util::GetStringFUTF16(
+ IDS_OPTIONS_TAB_TITLE,
+ l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE),
+ l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_DIALOG_TITLE));
+
+ EXPECT_EQ(expected_title, web_contents->GetTitle());
+}
+
+// This test will verify that the appropriate languages are available.
+IN_PROC_BROWSER_TEST_F(LanguageOptionsInteractiveTest, TestMockLanguages) {
+ ASSERT_TRUE(NavigateToLanguagePage());
+
+ content::RenderFrameHost* active_frame = NULL;
+ ASSERT_TRUE(GetActiveFrame(active_frame));
+
+ int language_count = 0;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
+ active_frame,
+ "var count = 0;"
+ "for (var i = 0; i < document.activeElement.childElementCount; ++i) {"
+ " if (document.activeElement.children[i].className == 'deletable-item')"
+ " ++count;"
+ "}"
+ "domAutomationController.send(count);",
+ &language_count));
+
+ // this test will fail until I can add languages
+ EXPECT_EQ(3, language_count);
+
+ std::string languages = "";
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ active_frame,
+ "domAutomationController.send(document.activeElement.textContent);",
+ &languages));
+
+ // this test will fail until I can add languages
+ EXPECT_EQ("English (United States)SpanishFrench", languages);
+}
+
+// TODO(hcarmona): There is an error that needs to be addressed:
+// Cannot get a GdkWindow for a key event.
+// Cannot translate a XKeyEvent to a GdkEvent.
groby-ooo-7-16 2014/08/12 23:57:27 Might want to ping yukishiino@ about this.
hcarmona 2014/08/13 20:24:39 Found another way to send keyboard events that get
+// Test appearst to work even though there are these errors
+// This test will validate that the language webui is accessible through
+// the keyboard.
+IN_PROC_BROWSER_TEST_F(LanguageOptionsInteractiveTest, HOCTestAccessibility) {
+ ASSERT_TRUE(NavigateToLanguagePage());
+
+ // verify that the list is focused by default
+ std::string original_id;
+ ASSERT_TRUE(GetActiveElementId(&original_id));
+ EXPECT_EQ("language-options-list", original_id);
+
+ // press tab to select the next element
+ ASSERT_TRUE(PressKey(ui::VKEY_TAB));
+
+ // make sure that the next element is the button that is next in the tab order
groby-ooo-7-16 2014/08/12 23:57:27 Can you instead just test that it's moved on to a
hcarmona 2014/08/13 20:24:39 Kept this expectation the same because we want to
+ std::string new_id;
+ ASSERT_TRUE(GetActiveElementId(&new_id));
+ EXPECT_EQ("language-options-add-button", new_id);
+}
+
+} // namespace language_options_ui_test

Powered by Google App Engine
This is Rietveld 408576698