Chromium Code Reviews| 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/url_constants.h" | |
| 10 #include "chrome/test/base/in_process_browser_test.h" | |
| 11 #include "chrome/test/base/ui_test_utils.h" | |
| 12 #include "content/public/browser/render_frame_host.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "content/public/test/browser_test_utils.h" | |
| 15 #include "grit/generated_resources.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/events/test/event_generator.h" | |
| 18 | |
| 19 namespace language_options_ui_test { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // TODO(hcarmona): Figure out a better way of getting this constant. | |
| 24 const char kAcceptLanguages[] = "intl.accept_languages"; | |
| 25 | |
| 26 // This class will test the language options settings. | |
| 27 // We need to emulate button pushing because we are testing accessibility, | |
| 28 // this means that this is part of interactive_ui_tests. | |
| 29 class LanguageOptionsInteractiveTest : public InProcessBrowserTest { | |
| 30 public: | |
| 31 LanguageOptionsInteractiveTest() {} | |
| 32 | |
| 33 protected: | |
| 34 // This method will navigate to the language settings page and show | |
| 35 // a subset of languages from the list of available languages that is not | |
| 36 // the default. | |
| 37 bool NavigateToLanguagePage() { | |
| 38 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.
| |
| 39 ui_test_utils::NavigateToURL(browser(), url); | |
| 40 browser()->profile()->GetPrefs()->SetString( | |
| 41 kAcceptLanguages, "en-US,es,fr"); | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 bool GetActiveElementId(std::string *element_id) { | |
| 46 content::RenderFrameHost* active_frame = NULL; | |
| 47 if (!GetActiveFrame(active_frame)) | |
| 48 return false; | |
| 49 | |
| 50 return content::ExecuteScriptAndExtractString( | |
| 51 active_frame, | |
| 52 "domAutomationController.send(document.activeElement.id);", | |
| 53 element_id); | |
| 54 } | |
| 55 | |
| 56 // Will get the active frame. Returns false on error. | |
| 57 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.
| |
| 58 content::WebContents* web_contents = NULL; | |
| 59 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.
| |
| 60 active_frame = web_contents->GetFocusedFrame(); | |
| 61 return active_frame; | |
| 62 } | |
| 63 | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 // Will get the active web contents. Returns false on error. | |
| 68 bool GetActiveWebContents(content::WebContents* &web_contents) { | |
| 69 if (browser()) { | |
| 70 if (TabStripModel* tab_strip_model = browser()->tab_strip_model()) { | |
| 71 web_contents = tab_strip_model->GetActiveWebContents(); | |
| 72 return web_contents; | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 // Press and release a key in a particular window. Returns false on error. | |
| 80 bool PressKey(ui::KeyboardCode key_code) { | |
| 81 gfx::NativeWindow native_window = NULL; | |
| 82 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.
| |
| 83 return false; | |
| 84 | |
| 85 ui::test::EventGenerator eventGen(native_window); | |
| 86 eventGen.PressKey(key_code, ui::EF_NONE); | |
| 87 eventGen.ReleaseKey(key_code, ui::EF_NONE); | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 protected: | |
| 92 // Will get the native window. Returns false on error. | |
| 93 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.
| |
| 94 if (browser()) { | |
| 95 if (BrowserWindow* window = browser()->window()) { | |
| 96 native_window = window->GetNativeWindow(); | |
| 97 return true; | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 return false; | |
| 102 } | |
| 103 | |
| 104 private: | |
| 105 DISALLOW_COPY_AND_ASSIGN(LanguageOptionsInteractiveTest); | |
| 106 }; | |
| 107 | |
| 108 } // namespace | |
| 109 | |
| 110 // This test will verify that after calling NavigateToLanguagePage | |
| 111 // we are in the correct page. | |
| 112 // TODO(hcarmona): | |
| 113 // 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.
| |
| 114 // 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.
| |
| 115 IN_PROC_BROWSER_TEST_F(LanguageOptionsInteractiveTest, TestNavigateToLanguage) { | |
| 116 ASSERT_TRUE(NavigateToLanguagePage()); | |
| 117 | |
| 118 content::WebContents* web_contents = NULL; | |
| 119 ASSERT_TRUE(GetActiveWebContents(web_contents)); | |
| 120 | |
| 121 base::string16 expected_title = l10n_util::GetStringFUTF16( | |
| 122 IDS_OPTIONS_TAB_TITLE, | |
| 123 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE), | |
| 124 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_DIALOG_TITLE)); | |
| 125 | |
| 126 EXPECT_EQ(expected_title, web_contents->GetTitle()); | |
| 127 } | |
| 128 | |
| 129 // This test will verify that the appropriate languages are available. | |
| 130 IN_PROC_BROWSER_TEST_F(LanguageOptionsInteractiveTest, TestMockLanguages) { | |
| 131 ASSERT_TRUE(NavigateToLanguagePage()); | |
| 132 | |
| 133 content::RenderFrameHost* active_frame = NULL; | |
| 134 ASSERT_TRUE(GetActiveFrame(active_frame)); | |
| 135 | |
| 136 int language_count = 0; | |
| 137 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 138 active_frame, | |
| 139 "var count = 0;" | |
| 140 "for (var i = 0; i < document.activeElement.childElementCount; ++i) {" | |
| 141 " if (document.activeElement.children[i].className == 'deletable-item')" | |
| 142 " ++count;" | |
| 143 "}" | |
| 144 "domAutomationController.send(count);", | |
| 145 &language_count)); | |
| 146 | |
| 147 // this test will fail until I can add languages | |
| 148 EXPECT_EQ(3, language_count); | |
| 149 | |
| 150 std::string languages = ""; | |
| 151 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
| 152 active_frame, | |
| 153 "domAutomationController.send(document.activeElement.textContent);", | |
| 154 &languages)); | |
| 155 | |
| 156 // this test will fail until I can add languages | |
| 157 EXPECT_EQ("English (United States)SpanishFrench", languages); | |
| 158 } | |
| 159 | |
| 160 // TODO(hcarmona): There is an error that needs to be addressed: | |
| 161 // Cannot get a GdkWindow for a key event. | |
| 162 // 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
| |
| 163 // Test appearst to work even though there are these errors | |
| 164 // This test will validate that the language webui is accessible through | |
| 165 // the keyboard. | |
| 166 IN_PROC_BROWSER_TEST_F(LanguageOptionsInteractiveTest, HOCTestAccessibility) { | |
| 167 ASSERT_TRUE(NavigateToLanguagePage()); | |
| 168 | |
| 169 // verify that the list is focused by default | |
| 170 std::string original_id; | |
| 171 ASSERT_TRUE(GetActiveElementId(&original_id)); | |
| 172 EXPECT_EQ("language-options-list", original_id); | |
| 173 | |
| 174 // press tab to select the next element | |
| 175 ASSERT_TRUE(PressKey(ui::VKEY_TAB)); | |
| 176 | |
| 177 // 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
| |
| 178 std::string new_id; | |
| 179 ASSERT_TRUE(GetActiveElementId(&new_id)); | |
| 180 EXPECT_EQ("language-options-add-button", new_id); | |
| 181 } | |
| 182 | |
| 183 } // namespace language_options_ui_test | |
| OLD | NEW |