blob: 26a16bb791ba317dfc87bc0d70e8b51503b436b3 [file] [log] [blame]
[email protected]ef6200ad2011-01-12 12:02:451// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]3b5f7022010-03-25 20:37:402// 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/test/ui/ui_test.h"
6
[email protected]ef6200ad2011-01-12 12:02:457#include "base/test/test_timeouts.h"
[email protected]1a3aba82010-11-08 23:52:548#include "chrome/app/chrome_command_ids.h"
[email protected]3b5f7022010-03-25 20:37:409#include "chrome/common/url_constants.h"
[email protected]6f870322011-06-27 23:07:0910#include "chrome/test/automation/automation_proxy.h"
[email protected]3b5f7022010-03-25 20:37:4011#include "chrome/test/automation/browser_proxy.h"
12#include "chrome/test/automation/tab_proxy.h"
13#include "chrome/test/automation/window_proxy.h"
14
15class BookmarksUITest : public UITest {
16 public:
17 BookmarksUITest() {
18 dom_automation_enabled_ = true;
19 }
20
21 bool WaitForBookmarksUI(TabProxy* tab) {
22 return WaitUntilJavaScriptCondition(tab, L"",
23 L"domAutomationController.send("
24 L" location.protocol == 'chrome-extension:' && "
25 L" document.readyState == 'complete')",
[email protected]ef6200ad2011-01-12 12:02:4526 TestTimeouts::huge_test_timeout_ms());
[email protected]3b5f7022010-03-25 20:37:4027 }
28
29 scoped_refptr<TabProxy> GetBookmarksUITab() {
30 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
31 EXPECT_TRUE(browser.get());
32 if (!browser.get())
33 return NULL;
34 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
35 EXPECT_TRUE(tab.get());
36 if (!tab.get())
37 return NULL;
[email protected]9db5f4e2010-03-26 00:36:0638 bool success = tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL));
39 EXPECT_TRUE(success);
40 if (!success)
[email protected]3b5f7022010-03-25 20:37:4041 return NULL;
[email protected]9db5f4e2010-03-26 00:36:0642 success = WaitForBookmarksUI(tab);
43 EXPECT_TRUE(success);
44 if (!success)
[email protected]3b5f7022010-03-25 20:37:4045 return NULL;
46 return tab;
47 }
48
49 void AssertIsBookmarksPage(TabProxy* tab) {
50 // tab->GetCurrentURL is not up to date.
51 GURL url;
[email protected]a771dc3f2011-02-08 19:56:1452 std::wstring out;
53 ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
54 L"domAutomationController.send(location.protocol)", &out));
55 ASSERT_EQ(L"chrome-extension:", out);
56 ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
57 L"domAutomationController.send(location.pathname)", &out));
58 ASSERT_EQ(L"/main.html", out);
[email protected]3b5f7022010-03-25 20:37:4059 }
60};
61
[email protected]65567152010-03-26 22:56:3262// http://code.google.com/p/chromium/issues/detail?id=39532
[email protected]81c48642010-06-24 07:01:1963TEST_F(BookmarksUITest, FLAKY_ShouldRedirectToExtension) {
[email protected]3b5f7022010-03-25 20:37:4064 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
65 ASSERT_TRUE(browser.get());
66
67 int tab_count = -1;
68 ASSERT_TRUE(browser->GetTabCount(&tab_count));
69 ASSERT_EQ(1, tab_count);
70
71 // Navigate to chrome
72 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
73 ASSERT_TRUE(tab.get());
74
75 ASSERT_TRUE(tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL)));
76
77 // At this point the URL is chrome://bookmarks. We need to wait for the
78 // redirect to happen.
79 ASSERT_TRUE(WaitForBookmarksUI(tab));
80
81 AssertIsBookmarksPage(tab);
82}
83
84TEST_F(BookmarksUITest, CommandOpensBookmarksTab) {
85 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
86 ASSERT_TRUE(browser.get());
87
88 int tab_count = -1;
89 ASSERT_TRUE(browser->GetTabCount(&tab_count));
90 ASSERT_EQ(1, tab_count);
91
92 // Bring up the bookmarks manager tab.
93 ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
94 ASSERT_TRUE(browser->GetTabCount(&tab_count));
[email protected]215b4282011-07-13 01:03:2895 ASSERT_EQ(1, tab_count);
[email protected]3b5f7022010-03-25 20:37:4096
97 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
98 ASSERT_TRUE(tab.get());
99
100 ASSERT_TRUE(WaitForBookmarksUI(tab));
101
102 AssertIsBookmarksPage(tab);
103}
104
[email protected]1518b0d2010-04-02 18:38:53105TEST_F(BookmarksUITest, CommandAgainGoesBackToBookmarksTab) {
106 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
107 ASSERT_TRUE(browser.get());
108
109 int tab_count = -1;
110 ASSERT_TRUE(browser->GetTabCount(&tab_count));
[email protected]215b4282011-07-13 01:03:28111 NavigateToURL(GURL("http://www.google.com/"));
[email protected]1518b0d2010-04-02 18:38:53112 ASSERT_EQ(1, tab_count);
113
114 // Bring up the bookmarks manager tab.
115 ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
[email protected]d64295932011-01-19 22:37:31116 ASSERT_TRUE(browser->WaitForTabToBecomeActive(
117 1, TestTimeouts::action_max_timeout_ms()));
[email protected]1518b0d2010-04-02 18:38:53118 ASSERT_TRUE(browser->GetTabCount(&tab_count));
119 ASSERT_EQ(2, tab_count);
120
121 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
122 ASSERT_TRUE(tab.get());
123 ASSERT_TRUE(WaitForBookmarksUI(tab));
124 AssertIsBookmarksPage(tab);
125
126 // Switch to first tab and run command again.
127 ASSERT_TRUE(browser->ActivateTab(0));
[email protected]d64295932011-01-19 22:37:31128 ASSERT_TRUE(browser->WaitForTabToBecomeActive(
129 0, TestTimeouts::action_max_timeout_ms()));
[email protected]1518b0d2010-04-02 18:38:53130 ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
131
132 // Ensure the bookmarks ui tab is active.
[email protected]d64295932011-01-19 22:37:31133 ASSERT_TRUE(browser->WaitForTabToBecomeActive(
134 1, TestTimeouts::action_max_timeout_ms()));
[email protected]1518b0d2010-04-02 18:38:53135 ASSERT_TRUE(browser->GetTabCount(&tab_count));
136 ASSERT_EQ(2, tab_count);
137}
138
139TEST_F(BookmarksUITest, TwoCommandsOneTab) {
140 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
141 ASSERT_TRUE(browser.get());
142
143 int tab_count = -1;
144 ASSERT_TRUE(browser->GetTabCount(&tab_count));
145 ASSERT_EQ(1, tab_count);
146
147 ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
148 ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
149 ASSERT_TRUE(browser->GetTabCount(&tab_count));
[email protected]215b4282011-07-13 01:03:28150 ASSERT_EQ(1, tab_count);
[email protected]1518b0d2010-04-02 18:38:53151}
152
[email protected]3b5f7022010-03-25 20:37:40153TEST_F(BookmarksUITest, BookmarksLoaded) {
154 scoped_refptr<TabProxy> tab = GetBookmarksUITab();
155 ASSERT_TRUE(tab.get());
156}