Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / webui / bookmarks_ui_browsertest.cc
blob8560489a079a493ad5eb634071d7a1c0b9510ac0
1 // Copyright (c) 2012 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.
5 #include "base/test/test_timeouts.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/chrome_pages.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/test_navigation_observer.h"
17 class BookmarksTest : public InProcessBrowserTest {
18 public:
19 BookmarksTest() {}
21 void SetUpOnMainThread() override {
22 InProcessBrowserTest::SetUpOnMainThread();
23 EnableAccessibilityChecksForTestCase(true);
26 void OpenBookmarksManager() {
27 content::TestNavigationObserver navigation_observer(
28 browser()->tab_strip_model()->GetActiveWebContents(), 2);
29 navigation_observer.StartWatchingNewWebContents();
31 // Bring up the bookmarks manager tab.
32 chrome::ShowBookmarkManager(browser());
33 navigation_observer.Wait();
36 void AssertIsBookmarksPage(content::WebContents* tab) {
37 GURL url;
38 std::string out;
39 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
40 tab,
41 "domAutomationController.send(location.protocol)",
42 &out));
43 ASSERT_EQ("chrome-extension:", out);
44 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
45 tab,
46 "domAutomationController.send(location.pathname)",
47 &out));
48 ASSERT_EQ("/main.html", out);
52 IN_PROC_BROWSER_TEST_F(BookmarksTest, ShouldRedirectToExtension) {
53 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL));
54 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());
57 IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandOpensBookmarksTab) {
58 ASSERT_EQ(1, browser()->tab_strip_model()->count());
60 // Bring up the bookmarks manager tab.
61 OpenBookmarksManager();
62 ASSERT_EQ(1, browser()->tab_strip_model()->count());
63 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());
66 // Flaky on Mac: https://crbug.com/524216
67 #if defined(OS_MACOSX) || defined(OS_LINUX)
68 #define MAYBE_CommandAgainGoesBackToBookmarksTab \
69 DISABLED_CommandAgainGoesBackToBookmarksTab
70 #else
71 #define MAYBE_CommandAgainGoesBackToBookmarksTab \
72 CommandAgainGoesBackToBookmarksTab
73 #endif
75 IN_PROC_BROWSER_TEST_F(BookmarksTest,
76 MAYBE_CommandAgainGoesBackToBookmarksTab) {
77 ui_test_utils::NavigateToURL(
78 browser(),
79 ui_test_utils::GetTestUrl(base::FilePath(),
80 base::FilePath().AppendASCII("simple.html")));
81 ASSERT_EQ(1, browser()->tab_strip_model()->count());
83 // Bring up the bookmarks manager tab.
84 OpenBookmarksManager();
85 ASSERT_EQ(2, browser()->tab_strip_model()->count());
87 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());
89 // Switch to first tab and run command again.
90 browser()->tab_strip_model()->ActivateTabAt(0, true);
91 chrome::ShowBookmarkManager(browser());
93 // Ensure the bookmarks ui tab is active.
94 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
95 ASSERT_EQ(2, browser()->tab_strip_model()->count());
98 IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) {
99 content::TestNavigationObserver navigation_observer(
100 browser()->tab_strip_model()->GetActiveWebContents());
101 chrome::ShowBookmarkManager(browser());
102 chrome::ShowBookmarkManager(browser());
103 navigation_observer.Wait();
105 ASSERT_EQ(1, browser()->tab_strip_model()->count());
108 IN_PROC_BROWSER_TEST_F(BookmarksTest, BookmarksLoaded) {
109 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL));
110 ASSERT_EQ(1, browser()->tab_strip_model()->count());
111 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());