OLD | NEW |
---|---|
(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 // We need to emulate button pushing because we are testing accessibility, | |
groby-ooo-7-16
2014/08/18 21:42:04
Nit: avoid "we", "I" in comments - they're often u
hcarmona
2014/08/18 23:39:51
Done.
| |
26 // this means that this is part of interactive_ui_tests. | |
27 class LanguageOptionsWebUITest : public InProcessBrowserTest { | |
28 public: | |
29 LanguageOptionsWebUITest() {} | |
30 | |
31 // This method will navigate to the language settings page and show | |
32 // a subset of languages from the list of available languages. | |
33 virtual void SetUpOnMainThread() OVERRIDE { | |
34 // This constant is different for Chrome OS and everything else | |
groby-ooo-7-16
2014/08/18 21:42:05
nit: no need to spell that out - the code gives it
hcarmona
2014/08/18 23:39:51
Done.
| |
35 #ifdef OS_CHROMEOS | |
groby-ooo-7-16
2014/08/18 21:42:05
nit: #if defined(OS_CHROMEOS)
| |
36 auto setting_name = prefs::kLanguagePreferredLanguages; | |
37 #else | |
38 auto setting_name = prefs::kAcceptLanguages; | |
groby-ooo-7-16
2014/08/18 21:42:04
This bugs me. Do you know _why_ they're different?
hcarmona
2014/08/18 23:39:51
Not sure why they're different. It may have to do
| |
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(); | |
89 | |
90 std::string count_deletable_items_script = | |
91 "var count = 0;" | |
groby-ooo-7-16
2014/08/18 21:42:04
Why not querySelectorAll?
I.e. document.activeEle
hcarmona
2014/08/18 23:39:51
Did not know about querySelectorAll, updated code
| |
92 "for (var i = 0; i < document.activeElement.childElementCount; ++i) {" | |
93 " if (document.activeElement.children[i].className == 'deletable-item')" | |
94 " ++count;" | |
95 "}" | |
96 "domAutomationController.send(count);"; | |
97 | |
98 // Count the number of languages in the list. | |
99 int language_count = 0; | |
100 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
101 active_frame, | |
102 count_deletable_items_script, | |
103 &language_count)); | |
104 EXPECT_EQ(3, language_count); | |
105 | |
106 std::string get_children_of_current_element_script = | |
107 "domAutomationController.send(document.activeElement.textContent);"; | |
108 | |
109 | |
110 // Verify that the correct languages are added to the list. | |
111 std::string languages = ""; | |
112 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
113 active_frame, | |
114 get_children_of_current_element_script, | |
115 &languages)); | |
116 EXPECT_EQ("English (United States)SpanishFrench", languages); | |
117 } | |
118 | |
119 // This test will validate that the language webui is accessible through | |
120 // the keyboard. | |
121 // This test must be updated if the tab order of the elements on this page | |
122 // is chagned. | |
123 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestListTabAccessibility) { | |
124 // Verify that the language list is focused by default. | |
125 std::string original_id = GetActiveElementId(); | |
126 EXPECT_EQ("language-options-list", original_id); | |
127 | |
128 // Press tab to select the next element. | |
129 EXPECT_TRUE(PressKey(ui::VKEY_TAB)); | |
130 | |
131 // Make sure that the element is now the button that is next in the tab order. | |
132 // Checking that the list is not selected is not sufficient to validate this | |
133 // use case because we will still want to have a failure if an item inside the | |
134 // list is selected. | |
135 std::string new_id = GetActiveElementId(); | |
136 EXPECT_EQ("language-options-add-button", new_id); | |
137 } | |
138 | |
139 } // namespace language_options_ui_test | |
140 | |
OLD | NEW |