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

Side by Side 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: Changes based on feedback from groby@ 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/options/deletable_item_list.js ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/ui/browser_window.h"
7 #include "chrome/browser/ui/chrome_pages.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/common/pref_names.h"
10 #include "chrome/common/url_constants.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/interactive_test_utils.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 namespace language_options_ui_test {
21
22 namespace {
23
24 // This class will test the language options settings.
25 // This test is part of the interactive_ui_tests isntead of browser_tests
26 // because it is necessary to emulate pushing a button in order to properly
27 // test accessiblity.
28 class LanguageOptionsWebUITest : public InProcessBrowserTest {
29 public:
30 LanguageOptionsWebUITest() {}
31
32 // This method will navigate to the language settings page and show
33 // a subset of languages from the list of available languages.
34 virtual void SetUpOnMainThread() OVERRIDE {
35 #if defined(OS_CHROMEOS)
36 auto setting_name = prefs::kLanguagePreferredLanguages;
37 #else
38 auto setting_name = prefs::kAcceptLanguages;
39 #endif
40
41 const GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage);
42 ui_test_utils::NavigateToURL(browser(), url);
43 browser()->profile()->GetPrefs()->SetString(setting_name, "en-US,es,fr");
44 }
45
46 protected:
47 // Will get the id of the element in the UI that has focus.
48 std::string GetActiveElementId() {
49 std::string get_element_id_script =
50 "domAutomationController.send(document.activeElement.id);";
51 std::string element_id;
52 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
53 GetActiveFrame(),
54 get_element_id_script,
55 &element_id));
56 return element_id;
57 }
58
59 content::RenderFrameHost* GetActiveFrame() {
60 return GetActiveWebContents()->GetFocusedFrame();
61 }
62
63 content::WebContents* GetActiveWebContents() {
64 return browser()->tab_strip_model()->GetActiveWebContents();
65 }
66
67 // Press and release a key in a particular window. Returns false on error.
68 bool PressKey(ui::KeyboardCode key_code) {
69 return ui_test_utils::SendKeyPressSync(browser(), key_code,
70 false, false, false, false);
71 }
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(LanguageOptionsWebUITest);
75 };
76
77 } // namespace
78
79 // This test will verify that the appropriate languages are available.
80 // This test will also fail if the language page is not loaded because a random
81 // page will not have the language list.
82 // Test assumes that the default active element is the list of languages.
83 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestAvailableLanguages) {
84 // Verify that the language list is focused by default.
85 std::string original_id = GetActiveElementId();
86 EXPECT_EQ("language-options-list", original_id);
87
88 content::RenderFrameHost* active_frame = GetActiveFrame();
Dan Beam 2014/08/19 00:06:37 ASSERT_TRUE(active_frame);
hcarmona 2014/08/19 00:36:52 Not changed because test would have crashed by thi
89
90 std::string count_deletable_items_script =
91 "domAutomationController.send("
92 " document.activeElement.querySelectorAll('.deletable-item').length);";
93
94 // Count the number of languages in the list.
95 int language_count = 0;
96 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
Dan Beam 2014/08/19 00:06:37 nit: ASSERT_TRUE()
hcarmona 2014/08/19 00:36:52 Done.
97 active_frame,
98 count_deletable_items_script,
99 &language_count));
100 EXPECT_EQ(3, language_count);
101
102 std::string get_children_of_current_element_script =
103 "domAutomationController.send(document.activeElement.textContent);";
104
105
Dan Beam 2014/08/19 00:06:37 nit: remove 1 \n
hcarmona 2014/08/19 00:36:52 Done.
106 // Verify that the correct languages are added to the list.
107 std::string languages = "";
Dan Beam 2014/08/19 00:06:37 nit: just std::string languages;
hcarmona 2014/08/19 00:36:52 Done.
108 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
109 active_frame,
110 get_children_of_current_element_script,
111 &languages));
112 EXPECT_EQ("English (United States)SpanishFrench", languages);
113 }
114
115 // This test will validate that the language webui is accessible through
116 // the keyboard.
117 // This test must be updated if the tab order of the elements on this page
118 // is chagned.
119 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestListTabAccessibility) {
120 // Verify that the language list is focused by default.
121 std::string original_id = GetActiveElementId();
122 EXPECT_EQ("language-options-list", original_id);
123
124 // Press tab to select the next element.
125 EXPECT_TRUE(PressKey(ui::VKEY_TAB));
Dan Beam 2014/08/19 00:06:37 nit: ASSERT_TRUE()
hcarmona 2014/08/19 00:36:52 Done.
126
127 // Make sure that the element is now the button that is next in the tab order.
128 // Checking that the list is no longer selected is not sufficient to validate
129 // this use case because this test should fail if an item inside the list is
130 // selected.
131 std::string new_id = GetActiveElementId();
132 EXPECT_EQ("language-options-add-button", new_id);
133 }
134
135 } // namespace language_options_ui_test
136
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/deletable_item_list.js ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698