| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chrome/test/ui/ui_test.h" |
| |
| #include "base/test/test_timeouts.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/test/test_navigation_observer.h" |
| |
| class BookmarksTest : public InProcessBrowserTest { |
| public: |
| BookmarksTest() { |
| EnableDOMAutomation(); |
| } |
| |
| void OpenBookmarksManager() { |
| TestNavigationObserver navigation_observer( |
| content::NotificationService::AllSources(), NULL, 2); |
| |
| // Bring up the bookmarks manager tab. |
| browser()->OpenBookmarkManager(); |
| navigation_observer.Wait(); |
| } |
| |
| void AssertIsBookmarksPage(content::WebContents* tab) { |
| GURL url; |
| std::string out; |
| ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| tab->GetRenderViewHost(), L"", |
| L"domAutomationController.send(location.protocol)", &out)); |
| ASSERT_EQ("chrome-extension:", out); |
| ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| tab->GetRenderViewHost(), L"", |
| L"domAutomationController.send(location.pathname)", &out)); |
| ASSERT_EQ("/main.html", out); |
| } |
| }; |
| |
| IN_PROC_BROWSER_TEST_F(BookmarksTest, ShouldRedirectToExtension) { |
| ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL)); |
| AssertIsBookmarksPage(browser()->GetSelectedWebContents()); |
| } |
| |
| IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandOpensBookmarksTab) { |
| ASSERT_EQ(1, browser()->tab_count()); |
| |
| // Bring up the bookmarks manager tab. |
| OpenBookmarksManager(); |
| ASSERT_EQ(1, browser()->tab_count()); |
| AssertIsBookmarksPage(browser()->GetSelectedWebContents()); |
| } |
| |
| // If this flakes on Mac, use: http://crbug.com/87200 |
| IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandAgainGoesBackToBookmarksTab) { |
| ui_test_utils::NavigateToURL( |
| browser(), |
| ui_test_utils::GetTestUrl(FilePath(), |
| FilePath().AppendASCII("simple.html"))); |
| ASSERT_EQ(1, browser()->tab_count()); |
| |
| // Bring up the bookmarks manager tab. |
| OpenBookmarksManager(); |
| ASSERT_EQ(2, browser()->tab_count()); |
| |
| AssertIsBookmarksPage(browser()->GetSelectedWebContents()); |
| |
| // Switch to first tab and run command again. |
| browser()->ActivateTabAt(0, true); |
| browser()->OpenBookmarkManager(); |
| |
| // Ensure the bookmarks ui tab is active. |
| ASSERT_EQ(1, browser()->active_index()); |
| ASSERT_EQ(2, browser()->tab_count()); |
| } |
| |
| IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) { |
| TestNavigationObserver navigation_observer( |
| content::NotificationService::AllSources()); |
| browser()->OpenBookmarkManager(); |
| browser()->OpenBookmarkManager(); |
| navigation_observer.Wait(); |
| |
| ASSERT_EQ(1, browser()->tab_count()); |
| } |
| |
| IN_PROC_BROWSER_TEST_F(BookmarksTest, BookmarksLoaded) { |
| ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL)); |
| ASSERT_EQ(1, browser()->tab_count()); |
| AssertIsBookmarksPage(browser()->GetSelectedWebContents()); |
| } |