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
38// Flaky: http://crbug.com/77375
39TEST_F(OptionsUITest, FLAKY_LoadOptionsByURL) {
40  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
41  ASSERT_TRUE(browser.get());
42
43  scoped_refptr<TabProxy> tab = browser->GetActiveTab();
44  ASSERT_TRUE(tab.get());
45
46  // Go to the options tab via URL.
47  NavigateToURL(GURL(chrome::kChromeUISettingsURL));
48  AssertIsOptionsPage(tab);
49}
50
51// Flaky, and takes very long to fail. http://crbug.com/64619.
52TEST_F(OptionsUITest, DISABLED_CommandOpensOptionsTab) {
53  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
54  ASSERT_TRUE(browser.get());
55
56  int tab_count = -1;
57  ASSERT_TRUE(browser->GetTabCount(&tab_count));
58  ASSERT_EQ(1, tab_count);
59
60  // Bring up the options tab via command.
61  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
62  ASSERT_TRUE(browser->GetTabCount(&tab_count));
63  ASSERT_EQ(2, tab_count);
64
65  scoped_refptr<TabProxy> tab = browser->GetActiveTab();
66  ASSERT_TRUE(tab.get());
67  AssertIsOptionsPage(tab);
68}
69
70// Flaky, and takes very long to fail. http://crbug.com/48521
71TEST_F(OptionsUITest, DISABLED_CommandAgainGoesBackToOptionsTab) {
72  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
73  ASSERT_TRUE(browser.get());
74
75  int tab_count = -1;
76  ASSERT_TRUE(browser->GetTabCount(&tab_count));
77  ASSERT_EQ(1, tab_count);
78
79  // Bring up the options tab via command.
80  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
81  ASSERT_TRUE(browser->GetTabCount(&tab_count));
82  ASSERT_EQ(2, tab_count);
83
84  scoped_refptr<TabProxy> tab = browser->GetActiveTab();
85  ASSERT_TRUE(tab.get());
86  AssertIsOptionsPage(tab);
87
88  // Switch to first tab and run command again.
89  ASSERT_TRUE(browser->ActivateTab(0));
90  ASSERT_TRUE(browser->WaitForTabToBecomeActive(
91      0, TestTimeouts::action_max_timeout_ms()));
92  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
93
94  // Ensure the options ui tab is active.
95  ASSERT_TRUE(browser->WaitForTabToBecomeActive(
96      1, TestTimeouts::action_max_timeout_ms()));
97  ASSERT_TRUE(browser->GetTabCount(&tab_count));
98  ASSERT_EQ(2, tab_count);
99}
100
101// Flaky, and takes very long to fail. http://crbug.com/48521
102TEST_F(OptionsUITest, DISABLED_TwoCommandsOneTab) {
103  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
104  ASSERT_TRUE(browser.get());
105
106  int tab_count = -1;
107  ASSERT_TRUE(browser->GetTabCount(&tab_count));
108  ASSERT_EQ(1, tab_count);
109
110  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
111  ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS));
112  ASSERT_TRUE(browser->GetTabCount(&tab_count));
113  ASSERT_EQ(2, tab_count);
114}
115
116}  // namespace
117