Chromium Code Reviews| Index: chrome/browser/ui/webui/options/language_options_interactive_uitest.cc |
| diff --git a/chrome/browser/ui/webui/options/language_options_interactive_uitest.cc b/chrome/browser/ui/webui/options/language_options_interactive_uitest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6339a54b5891b5e23e25c34d361fe444aa33bc81 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/options/language_options_interactive_uitest.cc |
| @@ -0,0 +1,135 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/prefs/pref_service.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/chrome_pages.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/interactive_test_utils.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace language_options_ui_test { |
| + |
| +namespace { |
| + |
| +// This class will test the language options settings. |
| +// We need to emulate button pushing because we are testing accessibility, |
| +// this means that this is part of interactive_ui_tests. |
| +class LanguageOptionsWebUITest : public InProcessBrowserTest { |
| + public: |
| + LanguageOptionsWebUITest() {} |
| + |
| + // This method will navigate to the language settings page and show |
| + // a subset of languages from the list of available languages. |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + // This constant is different for Chrome OS and everything else |
| +#ifdef OS_CHROMEOS |
| + auto setting_name = prefs::kLanguagePreferredLanguages; |
| +#else |
| + auto setting_name = prefs::kAcceptLanguages; |
| +#endif |
| + |
| + const GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage); |
| + ui_test_utils::NavigateToURL(browser(), url); |
| + browser()->profile()->GetPrefs()->SetString( |
| + setting_name, |
| + "en-US,es,fr"); |
| + } |
| + |
| + protected: |
| + // Will get the id of the element in the UI that has focus. |
| + std::string GetActiveElementId() { |
| + std::string element_id; |
| + if (content::ExecuteScriptAndExtractString( |
| + GetActiveFrame(), |
| + "domAutomationController.send(document.activeElement.id);", |
| + &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.
|
| + return element_id; |
| + |
| + return ""; |
| + } |
| + |
| + content::RenderFrameHost* GetActiveFrame() { |
| + return GetActiveWebContents()->GetFocusedFrame(); |
| + } |
| + |
| + content::WebContents* GetActiveWebContents() { |
| + return browser()->tab_strip_model()->GetActiveWebContents(); |
| + } |
| + |
| + // Press and release a key in a particular window. Returns false on error. |
| + bool PressKey(ui::KeyboardCode key_code) { |
| + return ui_test_utils::SendKeyPressSync(browser(), key_code, |
| + false, false, false, false); |
|
stevenjb
2014/08/18 16:05:06
align args
hcarmona
2014/08/18 20:59:27
Done.
|
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LanguageOptionsWebUITest); |
| +}; |
| + |
| +} // namespace |
| + |
| +// This test will verify that the appropriate languages are available. |
| +// This test will also fail if the language page is not loaded because a random |
| +// page will not have the language list. |
| +// Test assumes that the default active element is the list of languages. |
| +IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestAvailableLanguages) { |
| + // Verify that the language list is focused by default. |
| + std::string original_id = GetActiveElementId(); |
| + EXPECT_EQ("language-options-list", original_id); |
| + |
| + content::RenderFrameHost* active_frame = GetActiveFrame(); |
| + |
| + // Count the number of languages in the list. |
| + int language_count = 0; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| + active_frame, |
| + "var count = 0;" |
| + "for (var i = 0; i < document.activeElement.childElementCount; ++i) {" |
| + " if (document.activeElement.children[i].className == 'deletable-item')" |
| + " ++count;" |
| + "}" |
| + "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.
|
| + &language_count)); |
| + EXPECT_EQ(3, language_count); |
| + |
| + // Verify that the correct languages are added to the list. |
| + std::string languages = ""; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + active_frame, |
| + "domAutomationController.send(document.activeElement.textContent);", |
|
stevenjb
2014/08/18 16:05:05
ditto
hcarmona
2014/08/18 20:59:27
Done.
|
| + &languages)); |
| + EXPECT_EQ("English (United States)SpanishFrench", languages); |
| +} |
| + |
| +// This test will validate that the language webui is accessible through |
| +// the keyboard. |
| +// This test must be updated if the tab order of the elements on this page |
| +// is chagned. |
| +IN_PROC_BROWSER_TEST_F(LanguageOptionsWebUITest, TestListTabAccessibility) { |
| + // Verify that the language list is focused by default. |
| + std::string original_id = GetActiveElementId(); |
| + EXPECT_EQ("language-options-list", original_id); |
| + |
| + // Press tab to select the next element. |
| + ASSERT_TRUE(PressKey(ui::VKEY_TAB)); |
| + |
| + // Make sure that the element is now the button that is next in the tab order. |
| + // Checking that the list is not selected is not sufficient to validate this |
| + // use case because we will still want to have a failure if an item inside the |
| + // list is selected. |
| + std::string new_id = GetActiveElementId(); |
| + EXPECT_EQ("language-options-add-button", new_id); |
| +} |
| + |
| +} // namespace language_options_ui_test |
| + |