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/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, | |
| 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 | |
| 35 #ifdef 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( | |
| 44 setting_name, | |
| 45 "en-US,es,fr"); | |
| 46 } | |
| 47 | |
| 48 protected: | |
| 49 // Will get the id of the element in the UI that has focus. | |
| 50 std::string GetActiveElementId() { | |
| 51 std::string element_id; | |
| 52 if (content::ExecuteScriptAndExtractString( | |
| 53 GetActiveFrame(), | |
| 54 "domAutomationController.send(document.activeElement.id);", | |
| 55 &element_id)) | |
|
stevenjb
2014/08/18 16:05:06
nit: Unless we want to log a warning here, the if(
hcarmona
2014/08/18 20:59:27
Done.
| |
| 56 return element_id; | |
| 57 | |
| 58 return ""; | |
| 59 } | |
| 60 | |
| 61 content::RenderFrameHost* GetActiveFrame() { | |
| 62 return GetActiveWebContents()->GetFocusedFrame(); | |
| 63 } | |
| 64 | |
| 65 content::WebContents* GetActiveWebContents() { | |
| 66 return browser()->tab_strip_model()->GetActiveWebContents(); | |
| 67 } | |
| 68 | |
| 69 // Press and release a key in a particular window. Returns false on error. | |
| 70 bool PressKey(ui::KeyboardCode key_code) { | |
| 71 return ui_test_utils::SendKeyPressSync(browser(), key_code, | |
| 72 false, false, false, false); | |
|
stevenjb
2014/08/18 16:05:06
align args
hcarmona
2014/08/18 20:59:27
Done.
| |
| 73 } | |
| 74 | |
| 75 private: | |
| 76 DISALLOW_COPY_AND_ASSIGN(LanguageOptionsWebUITest); | |
| 77 }; | |
| 78 | |
| 79 } // namespace | |
| 80 | |
| 81 // This test will verify that the appropriate languages are available. | |
| 82 // This test will also fail if the language page is not loaded because a random | |
| 83 // page will not have the language list. | |
| 84 // Test assumes that the default active element is the list of languages. | |
| 85 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestAvailableLanguages) { | |
| 86 // Verify that the language list is focused by default. | |
| 87 std::string original_id = GetActiveElementId(); | |
| 88 EXPECT_EQ("language-options-list", original_id); | |
| 89 | |
| 90 content::RenderFrameHost* active_frame = GetActiveFrame(); | |
| 91 | |
| 92 // Count the number of languages in the list. | |
| 93 int language_count = 0; | |
| 94 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 95 active_frame, | |
| 96 "var count = 0;" | |
| 97 "for (var i = 0; i < document.activeElement.childElementCount; ++i) {" | |
| 98 " if (document.activeElement.children[i].className == 'deletable-item')" | |
| 99 " ++count;" | |
| 100 "}" | |
| 101 "domAutomationController.send(count);", | |
|
stevenjb
2014/08/18 16:05:06
We should define this test string separately. Embe
hcarmona
2014/08/18 20:59:27
Done.
| |
| 102 &language_count)); | |
| 103 EXPECT_EQ(3, language_count); | |
| 104 | |
| 105 // Verify that the correct languages are added to the list. | |
| 106 std::string languages = ""; | |
| 107 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
| 108 active_frame, | |
| 109 "domAutomationController.send(document.activeElement.textContent);", | |
|
stevenjb
2014/08/18 16:05:05
ditto
hcarmona
2014/08/18 20:59:27
Done.
| |
| 110 &languages)); | |
| 111 EXPECT_EQ("English (United States)SpanishFrench", languages); | |
| 112 } | |
| 113 | |
| 114 // This test will validate that the language webui is accessible through | |
| 115 // the keyboard. | |
| 116 // This test must be updated if the tab order of the elements on this page | |
| 117 // is chagned. | |
| 118 IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestListTabAccessibility) { | |
| 119 // Verify that the language list is focused by default. | |
| 120 std::string original_id = GetActiveElementId(); | |
| 121 EXPECT_EQ("language-options-list", original_id); | |
| 122 | |
| 123 // Press tab to select the next element. | |
| 124 ASSERT_TRUE(PressKey(ui::VKEY_TAB)); | |
| 125 | |
| 126 // Make sure that the element is now the button that is next in the tab order. | |
| 127 // Checking that the list is not selected is not sufficient to validate this | |
| 128 // use case because we will still want to have a failure if an item inside the | |
| 129 // list is selected. | |
| 130 std::string new_id = GetActiveElementId(); | |
| 131 EXPECT_EQ("language-options-add-button", new_id); | |
| 132 } | |
| 133 | |
| 134 } // namespace language_options_ui_test | |
| 135 | |
| OLD | NEW |