[email protected] | ef6200ad | 2011-01-12 12:02:45 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 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 | |
[email protected] | ef6200ad | 2011-01-12 12:02:45 | [diff] [blame] | 7 | #include "base/test/test_timeouts.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 8 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 9 | #include "chrome/common/url_constants.h" |
[email protected] | 6f87032 | 2011-06-27 23:07:09 | [diff] [blame] | 10 | #include "chrome/test/automation/automation_proxy.h" |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 11 | #include "chrome/test/automation/browser_proxy.h" |
| 12 | #include "chrome/test/automation/tab_proxy.h" |
| 13 | #include "chrome/test/automation/window_proxy.h" |
| 14 | |
| 15 | class 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] | ef6200ad | 2011-01-12 12:02:45 | [diff] [blame] | 26 | TestTimeouts::huge_test_timeout_ms()); |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 27 | } |
| 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] | 9db5f4e | 2010-03-26 00:36:06 | [diff] [blame] | 38 | bool success = tab->NavigateToURL(GURL(chrome::kChromeUIBookmarksURL)); |
| 39 | EXPECT_TRUE(success); |
| 40 | if (!success) |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 41 | return NULL; |
[email protected] | 9db5f4e | 2010-03-26 00:36:06 | [diff] [blame] | 42 | success = WaitForBookmarksUI(tab); |
| 43 | EXPECT_TRUE(success); |
| 44 | if (!success) |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 45 | 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] | a771dc3f | 2011-02-08 19:56:14 | [diff] [blame] | 52 | 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] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 59 | } |
| 60 | }; |
| 61 | |
[email protected] | 6556715 | 2010-03-26 22:56:32 | [diff] [blame] | 62 | // http://code.google.com/p/chromium/issues/detail?id=39532 |
[email protected] | 81c4864 | 2010-06-24 07:01:19 | [diff] [blame] | 63 | TEST_F(BookmarksUITest, FLAKY_ShouldRedirectToExtension) { |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 64 | 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 | |
| 84 | TEST_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] | 215b428 | 2011-07-13 01:03:28 | [diff] [blame^] | 95 | ASSERT_EQ(1, tab_count); |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 96 | |
| 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] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 105 | TEST_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] | 215b428 | 2011-07-13 01:03:28 | [diff] [blame^] | 111 | NavigateToURL(GURL("http://www.google.com/")); |
[email protected] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 112 | ASSERT_EQ(1, tab_count); |
| 113 | |
| 114 | // Bring up the bookmarks manager tab. |
| 115 | ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER)); |
[email protected] | d6429593 | 2011-01-19 22:37:31 | [diff] [blame] | 116 | ASSERT_TRUE(browser->WaitForTabToBecomeActive( |
| 117 | 1, TestTimeouts::action_max_timeout_ms())); |
[email protected] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 118 | 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] | d6429593 | 2011-01-19 22:37:31 | [diff] [blame] | 128 | ASSERT_TRUE(browser->WaitForTabToBecomeActive( |
| 129 | 0, TestTimeouts::action_max_timeout_ms())); |
[email protected] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 130 | ASSERT_TRUE(browser->RunCommand(IDC_SHOW_BOOKMARK_MANAGER)); |
| 131 | |
| 132 | // Ensure the bookmarks ui tab is active. |
[email protected] | d6429593 | 2011-01-19 22:37:31 | [diff] [blame] | 133 | ASSERT_TRUE(browser->WaitForTabToBecomeActive( |
| 134 | 1, TestTimeouts::action_max_timeout_ms())); |
[email protected] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 135 | ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| 136 | ASSERT_EQ(2, tab_count); |
| 137 | } |
| 138 | |
| 139 | TEST_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] | 215b428 | 2011-07-13 01:03:28 | [diff] [blame^] | 150 | ASSERT_EQ(1, tab_count); |
[email protected] | 1518b0d | 2010-04-02 18:38:53 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | 3b5f702 | 2010-03-25 20:37:40 | [diff] [blame] | 153 | TEST_F(BookmarksUITest, BookmarksLoaded) { |
| 154 | scoped_refptr<TabProxy> tab = GetBookmarksUITab(); |
| 155 | ASSERT_TRUE(tab.get()); |
| 156 | } |