blob: 9daa7a9c85ace0f74cb108dbc6144a3bf958a536 [file] [log] [blame]
[email protected]3b5f7022010-03-25 20:37:401// Copyright (c) 2010 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/test/ui/ui_test.h"
6
7#include "chrome/app/chrome_dll_resource.h"
8#include "chrome/common/url_constants.h"
9#include "chrome/test/automation/browser_proxy.h"
10#include "chrome/test/automation/tab_proxy.h"
11#include "chrome/test/automation/window_proxy.h"
12
13class BookmarksUITest : public UITest {
14 public:
15 BookmarksUITest() {
16 dom_automation_enabled_ = true;
17 }
18
19 bool WaitForBookmarksUI(TabProxy* tab) {
20 return WaitUntilJavaScriptCondition(tab, L"",
21 L"domAutomationController.send("
22 L" location.protocol == 'chrome-extension:' && "
23 L" document.readyState == 'complete')",
24 100, UITest::test_timeout_ms());
25 }
26
27 scoped_refptr<TabProxy> GetBookmarksUITab() {
28 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
29 EXPECT_TRUE(browser.get());
30 if (!browser.get())
31 return NULL;
32 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
33 EXPECT_TRUE(tab.get());
34 if (!tab.get())
35 return NULL;
36 if (!tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL)))
37 return NULL;
38 if (!WaitForBookmarksUI(tab))
39 return NULL;
40 return tab;
41 }
42
43 void AssertIsBookmarksPage(TabProxy* tab) {
44 // tab->GetCurrentURL is not up to date.
45 GURL url;
46 std::wstring out;
47 ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
48 L"domAutomationController.send(location.protocol)", &out));
49 ASSERT_EQ(L"chrome-extension:", out);
50 ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
51 L"domAutomationController.send(location.pathname)", &out));
52 ASSERT_EQ(L"/main.html", out);
53 }
54};
55
56TEST_F(BookmarksUITest, ShouldRedirectToExtension) {
57 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
58 ASSERT_TRUE(browser.get());
59
60 int tab_count = -1;
61 ASSERT_TRUE(browser->GetTabCount(&tab_count));
62 ASSERT_EQ(1, tab_count);
63
64 // Navigate to chrome
65 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
66 ASSERT_TRUE(tab.get());
67
68 ASSERT_TRUE(tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL)));
69
70 // At this point the URL is chrome://bookmarks. We need to wait for the
71 // redirect to happen.
72 ASSERT_TRUE(WaitForBookmarksUI(tab));
73
74 AssertIsBookmarksPage(tab);
75}
76
77TEST_F(BookmarksUITest, CommandOpensBookmarksTab) {
78 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
79 ASSERT_TRUE(browser.get());
80
81 int tab_count = -1;
82 ASSERT_TRUE(browser->GetTabCount(&tab_count));
83 ASSERT_EQ(1, tab_count);
84
85 // Bring up the bookmarks manager tab.
86 ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER));
87 ASSERT_TRUE(browser->GetTabCount(&tab_count));
88 ASSERT_EQ(2, tab_count);
89
90 scoped_refptr<TabProxy> tab = browser->GetActiveTab();
91 ASSERT_TRUE(tab.get());
92
93 ASSERT_TRUE(WaitForBookmarksUI(tab));
94
95 AssertIsBookmarksPage(tab);
96}
97
98TEST_F(BookmarksUITest, BookmarksLoaded) {
99 scoped_refptr<TabProxy> tab = GetBookmarksUITab();
100 ASSERT_TRUE(tab.get());
101}