OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "chrome/test/automation/browser_proxy.h" | 12 #include "chrome/test/automation/browser_proxy.h" |
13 #include "chrome/test/automation/tab_proxy.h" | 13 #include "chrome/test/automation/tab_proxy.h" |
14 #include "chrome/test/automation/window_proxy.h" | 14 #include "chrome/test/automation/window_proxy.h" |
15 #include "chrome/test/ui/ui_test.h" | 15 #include "chrome/test/ui/ui_test.h" |
16 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class OptionsUITest : public UITest { | 22 class OptionsUITest : public UITest { |
23 public: | 23 public: |
24 OptionsUITest() { | 24 OptionsUITest() { |
25 dom_automation_enabled_ = true; | 25 dom_automation_enabled_ = true; |
26 } | 26 } |
27 | 27 |
| 28 bool WaitForOptionsUI(TabProxy* tab) { |
| 29 return WaitUntilJavaScriptCondition(tab, L"", |
| 30 L"domAutomationController.send(" |
| 31 L" location.protocol == 'chrome:' && " |
| 32 L" document.readyState == 'complete')", |
| 33 TestTimeouts::huge_test_timeout_ms()); |
| 34 } |
| 35 |
| 36 scoped_refptr<TabProxy> GetOptionsUITab() { |
| 37 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 38 EXPECT_TRUE(browser.get()); |
| 39 if (!browser.get()) |
| 40 return NULL; |
| 41 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); |
| 42 EXPECT_TRUE(tab.get()); |
| 43 if (!tab.get()) |
| 44 return NULL; |
| 45 bool success = tab->NavigateToURL(GURL(chrome::kChromeUISettingsURL)); |
| 46 EXPECT_TRUE(success); |
| 47 if (!success) |
| 48 return NULL; |
| 49 success = WaitForOptionsUI(tab); |
| 50 EXPECT_TRUE(success); |
| 51 if (!success) |
| 52 return NULL; |
| 53 return tab; |
| 54 } |
| 55 |
28 void AssertIsOptionsPage(TabProxy* tab) { | 56 void AssertIsOptionsPage(TabProxy* tab) { |
29 std::wstring title; | 57 std::wstring title; |
30 ASSERT_TRUE(tab->GetTabTitle(&title)); | 58 ASSERT_TRUE(tab->GetTabTitle(&title)); |
31 string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE); | 59 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 | 60 // The only guarantee we can make about the title of a settings tab is that |
33 // it should contain IDS_SETTINGS_TITLE somewhere. | 61 // it should contain IDS_SETTINGS_TITLE somewhere. |
34 ASSERT_FALSE(WideToUTF16Hack(title).find(expected_title) == string16::npos); | 62 ASSERT_FALSE(WideToUTF16Hack(title).find(expected_title) == string16::npos); |
35 } | 63 } |
36 }; | 64 }; |
37 | 65 |
38 // Flaky: http://crbug.com/77375 | 66 TEST_F(OptionsUITest, LoadOptionsByURL) { |
39 TEST_F(OptionsUITest, FLAKY_LoadOptionsByURL) { | 67 scoped_refptr<TabProxy> tab = GetOptionsUITab(); |
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()); | 68 ASSERT_TRUE(tab.get()); |
45 | |
46 // Go to the options tab via URL. | |
47 NavigateToURL(GURL(chrome::kChromeUISettingsURL)); | |
48 AssertIsOptionsPage(tab); | 69 AssertIsOptionsPage(tab); |
49 } | 70 } |
50 | 71 |
51 // Flaky, and takes very long to fail. http://crbug.com/64619. | 72 // Flaky, and takes very long to fail. http://crbug.com/64619. |
52 TEST_F(OptionsUITest, DISABLED_CommandOpensOptionsTab) { | 73 TEST_F(OptionsUITest, DISABLED_CommandOpensOptionsTab) { |
53 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 74 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
54 ASSERT_TRUE(browser.get()); | 75 ASSERT_TRUE(browser.get()); |
55 | 76 |
56 int tab_count = -1; | 77 int tab_count = -1; |
57 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | 78 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 int tab_count = -1; | 127 int tab_count = -1; |
107 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | 128 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
108 ASSERT_EQ(1, tab_count); | 129 ASSERT_EQ(1, tab_count); |
109 | 130 |
110 ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS)); | 131 ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS)); |
111 ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS)); | 132 ASSERT_TRUE(browser->RunCommand(IDC_OPTIONS)); |
112 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | 133 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
113 ASSERT_EQ(2, tab_count); | 134 ASSERT_EQ(2, tab_count); |
114 } | 135 } |
115 | 136 |
| 137 // Navigates to settings page and do sanity check on settings sections. |
| 138 TEST_F(OptionsUITest, NavBarCheck) { |
| 139 scoped_refptr<TabProxy> tab = GetOptionsUITab(); |
| 140 ASSERT_TRUE(tab.get()); |
| 141 AssertIsOptionsPage(tab); |
| 142 |
| 143 // Check navbar's existence. |
| 144 bool navbar_exist = false; |
| 145 ASSERT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 146 L"domAutomationController.send(" |
| 147 L"!!document.getElementById('navbar'))", &navbar_exist)); |
| 148 ASSERT_EQ(true, navbar_exist); |
| 149 |
| 150 // Check section headers in navbar. |
| 151 // For ChromeOS, there should be 1 + 6: |
| 152 // search, basics, personal, systerm, internet, under the hood and users |
| 153 // For other platforms, there should 1 + 3: |
| 154 // search, basics, personal and under the hood. |
| 155 #if defined(OS_CHROMEOS) |
| 156 const int kExpectedSections = 1 + 6; |
| 157 #else |
| 158 const int kExpectedSections = 1 + 3; |
| 159 #endif |
| 160 int num_of_sections = 0; |
| 161 ASSERT_TRUE(tab->ExecuteAndExtractInt(L"", |
| 162 L"domAutomationController.send(" |
| 163 L"document.getElementById('navbar').children.length)", &num_of_sections)); |
| 164 ASSERT_EQ(kExpectedSections, num_of_sections); |
| 165 } |
| 166 |
116 } // namespace | 167 } // namespace |
OLD | NEW |