options_ui_browsertest.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
1// Copyright (c) 2012 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 "chrome/browser/ui/webui/options/options_ui_browsertest.h" 6 7#include "base/strings/string16.h" 8#include "base/strings/utf_string_conversions.h" 9#include "chrome/browser/ui/browser.h" 10#include "chrome/browser/ui/tabs/tab_strip_model.h" 11#include "chrome/common/url_constants.h" 12#include "chrome/test/base/ui_test_utils.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 18#if !defined(OS_CHROMEOS) 19#include <string> 20 21#include "base/basictypes.h" 22#include "base/bind.h" 23#include "base/callback.h" 24#include "base/files/file_path.h" 25#include "base/run_loop.h" 26#include "chrome/browser/browser_process.h" 27#include "chrome/browser/profiles/profile.h" 28#include "chrome/browser/profiles/profile_manager.h" 29#include "chrome/browser/ui/browser_commands.h" 30#include "content/public/test/test_navigation_observer.h" 31#include "ui/base/window_open_disposition.h" 32#include "url/gurl.h" 33#endif 34 35namespace options { 36 37namespace { 38 39#if !defined(OS_CHROMEOS) 40void RunClosureWhenProfileInitialized(const base::Closure& closure, 41 Profile* profile, 42 Profile::CreateStatus status) { 43 if (status == Profile::CREATE_STATUS_INITIALIZED) 44 closure.Run(); 45} 46#endif 47 48} // namespace 49 50OptionsUIBrowserTest::OptionsUIBrowserTest() { 51} 52 53void OptionsUIBrowserTest::NavigateToSettings() { 54 const GURL& url = GURL(chrome::kChromeUISettingsURL); 55 ui_test_utils::NavigateToURL(browser(), url); 56} 57 58void OptionsUIBrowserTest::VerifyNavbar() { 59 bool navbar_exist = false; 60 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 61 browser()->tab_strip_model()->GetActiveWebContents(), 62 "domAutomationController.send(" 63 " !!document.getElementById('navigation'))", 64 &navbar_exist)); 65 EXPECT_EQ(true, navbar_exist); 66} 67 68void OptionsUIBrowserTest::VerifyTitle() { 69 string16 title = 70 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle(); 71 string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE); 72 EXPECT_NE(title.find(expected_title), string16::npos); 73} 74 75// Flaky, see http://crbug.com/119671. 76IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, DISABLED_LoadOptionsByURL) { 77 NavigateToSettings(); 78 VerifyTitle(); 79 VerifyNavbar(); 80} 81 82#if !defined(OS_CHROMEOS) 83// Regression test for http://crbug.com/301436, excluded on Chrome OS because 84// profile management in the settings UI exists on desktop platforms only. 85IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, NavigateBackFromOverlayDialog) { 86 // Navigate to the settings page. 87 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings-frame")); 88 89 // Click a button that opens an overlay dialog. 90 content::WebContents* contents = 91 browser()->tab_strip_model()->GetActiveWebContents(); 92 ASSERT_TRUE(content::ExecuteScript( 93 contents, "$('manage-default-search-engines').click();")); 94 95 // Go back to the settings page. 96 content::TestNavigationObserver observer(contents); 97 chrome::GoBack(browser(), CURRENT_TAB); 98 observer.Wait(); 99 100 // Verify that the settings page lists one profile. 101 const char javascript[] = 102 "domAutomationController.send(" 103 " document.querySelectorAll('list#profiles-list > div[role=listitem]')" 104 " .length);"; 105 int profiles; 106 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 107 contents, javascript, &profiles)); 108 EXPECT_EQ(1, profiles); 109 110 // Create a second profile. 111 ProfileManager* profile_manager = g_browser_process->profile_manager(); 112 const base::FilePath profile_path = 113 profile_manager->GenerateNextProfileDirectoryPath(); 114 115 base::RunLoop run_loop; 116 profile_manager->CreateProfileAsync( 117 profile_manager->GenerateNextProfileDirectoryPath(), 118 base::Bind(&RunClosureWhenProfileInitialized, 119 run_loop.QuitClosure()), 120 string16(), 121 string16(), 122 std::string()); 123 run_loop.Run(); 124 125 // Verify that the settings page has updated and lists two profiles. 126 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 127 contents, javascript, &profiles)); 128 EXPECT_EQ(2, profiles); 129} 130#endif 131 132} // namespace options 133