options_ui_uitest.cc revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 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/command_line.h"
6#include "base/string16.h"
7#include "base/test/test_timeouts.h"
8#include "base/utf_string_conversions.h"
9#include "chrome/app/chrome_command_ids.h"
10#include "chrome/common/chrome_switches.h"
11#include "chrome/common/url_constants.h"
12#include "chrome/test/automation/browser_proxy.h"
13#include "chrome/test/automation/tab_proxy.h"
14#include "chrome/test/automation/window_proxy.h"
15#include "chrome/test/ui/ui_test.h"
16#include "grit/chromium_strings.h"
17#include "grit/generated_resources.h"
18#include "ui/base/l10n/l10n_util.h"
19
20namespace {
21
22class OptionsUITest : public UITest {
23 public:
24  OptionsUITest() {
25    dom_automation_enabled_ = true;
26  }
27
28  void AssertIsOptionsPage(TabProxy* tab) {
29    std::wstring title;
30    ASSERT_TRUE(tab->GetTabTitle(&title));
31    string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE);
32    // The only guarantee we can make about the title of a settings tab is that
33    // it should contain IDS_SETTINGS_TITLE somewhere.
34    ASSERT_FALSE(WideToUTF16Hack(title).find(expected_title) == string16::npos);
35  }
36};
37
38TEST_F(OptionsUITest, LoadOptionsByURL) {
39  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
40  ASSERT_TRUE(browser.get());
41
42  scoped_refptr<TabProxy> tab = browser->GetActiveTab();
43  ASSERT_TRUE(tab.get());
44
45  // Go to the options tab via URL.
46  NavigateToURL(GURL(chrome::kChromeUISettingsURL));
47  AssertIsOptionsPage(tab);
48}
49
50// Flaky, and takes very long to fail. http://crbug.com/64619.
51TEST_F(OptionsUITest, DISABLED_CommandOpensOptionsTab) {
52  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
53  ASSERT_TRUE(browser.get());
54
55  int tab_count = -1;
56  ASSERT_TRUE(browser->GetTabCount(&tab_count));
57  ASSERT_EQ(1, tab_count);
58
59  // Bring up the options tab via command.
60  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
61  ASSERT_TRUE(browser->GetTabCount(&tab_count));
62  ASSERT_EQ(2, tab_count);
63
64  scoped_refptr<TabProxy> tab = browser->GetActiveTab();
65  ASSERT_TRUE(tab.get());
66  AssertIsOptionsPage(tab);
67}
68
69// Flaky, and takes very long to fail. http://crbug.com/48521
70TEST_F(OptionsUITest, DISABLED_CommandAgainGoesBackToOptionsTab) {
71  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
72  ASSERT_TRUE(browser.get());
73
74  int tab_count = -1;
75  ASSERT_TRUE(browser->GetTabCount(&tab_count));
76  ASSERT_EQ(1, tab_count);
77
78  // Bring up the options tab via command.
79  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
80  ASSERT_TRUE(browser->GetTabCount(&tab_count));
81  ASSERT_EQ(2, tab_count);
82
83  scoped_refptr<TabProxy> tab = browser->GetActiveTab();
84  ASSERT_TRUE(tab.get());
85  AssertIsOptionsPage(tab);
86
87  // Switch to first tab and run command again.
88  ASSERT_TRUE(browser->ActivateTab(0));
89  ASSERT_TRUE(browser->WaitForTabToBecomeActive(
90      0, TestTimeouts::action_max_timeout_ms()));
91  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
92
93  // Ensure the options ui tab is active.
94  ASSERT_TRUE(browser->WaitForTabToBecomeActive(
95      1, TestTimeouts::action_max_timeout_ms()));
96  ASSERT_TRUE(browser->GetTabCount(&tab_count));
97  ASSERT_EQ(2, tab_count);
98}
99
100// Flaky, and takes very long to fail. http://crbug.com/48521
101TEST_F(OptionsUITest, DISABLED_TwoCommandsOneTab) {
102  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
103  ASSERT_TRUE(browser.get());
104
105  int tab_count = -1;
106  ASSERT_TRUE(browser->GetTabCount(&tab_count));
107  ASSERT_EQ(1, tab_count);
108
109  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
110  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
111  ASSERT_TRUE(browser->GetTabCount(&tab_count));
112  ASSERT_EQ(2, tab_count);
113}
114
115}  // namespace
116