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

Side by Side Diff: chrome/browser/ui/webui/options/language_options_interactive_uitest.cc

Issue 2913343002: Start removing deprecated Options UI code (Closed)
Patch Set: thestig@ review Created 3 years, 6 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
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/macros.h"
6 #include "base/test/scoped_feature_list.h"
7 #include "build/build_config.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/chrome_pages.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_features.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/interactive_test_utils.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/prefs/pref_service.h"
19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/browser_test_utils.h"
22
23 namespace language_options_ui_test {
24
25 namespace {
26
27 // This class will test the language options settings.
28 // This test is part of the interactive_ui_tests isntead of browser_tests
29 // because it is necessary to emulate pushing a button in order to properly
30 // test accessibility.
31 class LanguageOptionsWebUITest : public InProcessBrowserTest {
32 public:
33 LanguageOptionsWebUITest() {}
34
35 void SetUpInProcessBrowserTestFixture() override {
36 disable_md_settings_.InitAndDisableFeature(
37 features::kMaterialDesignSettings);
38 }
39
40 // This method will navigate to the language settings page and show
41 // a subset of languages from the list of available languages.
42 void SetUpOnMainThread() override {
43 #if defined(OS_CHROMEOS)
44 auto* setting_name = prefs::kLanguagePreferredLanguages;
45 #else
46 auto* setting_name = prefs::kAcceptLanguages;
47 #endif
48
49 const GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage);
50 ui_test_utils::NavigateToURL(browser(), url);
51 browser()->profile()->GetPrefs()->SetString(setting_name, "en-US,es,fr");
52 }
53
54 protected:
55 // Will get the id of the element in the UI that has focus.
56 std::string GetActiveElementId() {
57 std::string get_element_id_script =
58 "domAutomationController.send(document.activeElement.id);";
59 std::string element_id;
60 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
61 GetActiveFrame(),
62 get_element_id_script,
63 &element_id));
64 return element_id;
65 }
66
67 content::RenderFrameHost* GetActiveFrame() {
68 return GetActiveWebContents()->GetFocusedFrame();
69 }
70
71 content::RenderViewHost* GetRenderViewHost() {
72 return GetActiveWebContents()->GetRenderViewHost();
73 }
74
75 content::WebContents* GetActiveWebContents() {
76 return browser()->tab_strip_model()->GetActiveWebContents();
77 }
78
79 // Press and release a key in the browser. This will wait for the element on
80 // the page to change.
81 bool PressKey(ui::KeyboardCode key_code) {
82 return ui_test_utils::SendKeyPressAndWait(
83 browser(),
84 key_code,
85 false,
86 false,
87 false,
88 false,
89 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
90 content::Source<content::RenderViewHost>(GetRenderViewHost()));
91 }
92
93 private:
94 base::test::ScopedFeatureList disable_md_settings_;
95
96 DISALLOW_COPY_AND_ASSIGN(LanguageOptionsWebUITest);
97 };
98
99 } // namespace
100
101 // This test will verify that the appropriate languages are available.
102 // This test will also fail if the language page is not loaded because a random
103 // page will not have the language list.
104 // Test assumes that the default active element is the list of languages.
105 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestAvailableLanguages) {
106 // Verify that the language list is focused by default.
107 std::string original_id = GetActiveElementId();
108 EXPECT_EQ("language-options-list", original_id);
109
110 content::RenderFrameHost* active_frame = GetActiveFrame();
111
112 std::string count_deletable_items_script =
113 "domAutomationController.send("
114 " document.activeElement.querySelectorAll('.deletable-item').length);";
115
116 // Count the number of languages in the list.
117 int language_count = 0;
118 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
119 active_frame,
120 count_deletable_items_script,
121 &language_count));
122 EXPECT_EQ(3, language_count);
123
124 std::string get_children_of_current_element_script =
125 "domAutomationController.send(document.activeElement.textContent);";
126
127 // Verify that the correct languages are added to the list.
128 std::string languages;
129 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
130 active_frame,
131 get_children_of_current_element_script,
132 &languages));
133 EXPECT_EQ("English (United States)SpanishFrench", languages);
134 }
135
136 // This test will validate that the language webui is accessible through
137 // the keyboard.
138 // This test must be updated if the tab order of the elements on this page
139 // is changed.
140
141 // Crashes on Win 7. http://crbug.com/500609
142 #if defined(OS_WIN)
143 #define MAYBE_TestListTabAccessibility DISABLED_TestListTabAccessibility
144 #else
145 #define MAYBE_TestListTabAccessibility TestListTabAccessibility
146 #endif
147
148 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest,
149 MAYBE_TestListTabAccessibility) {
150 // Verify that the language list is focused by default.
151 std::string original_id = GetActiveElementId();
152 EXPECT_EQ("language-options-list", original_id);
153
154 // Press tab to select the next element.
155 ASSERT_TRUE(PressKey(ui::VKEY_TAB));
156
157 // Make sure that the element is now the button that is next in the tab order.
158 // Checking that the list is no longer selected is not sufficient to validate
159 // this use case because this test should fail if an item inside the list is
160 // selected.
161 std::string new_id = GetActiveElementId();
162 EXPECT_EQ("language-options-add-button", new_id);
163 }
164
165 } // namespace language_options_ui_test
166
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698