Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / bookmarks_ui_browsertest.cc
blobfd0161c67f94e9dd64baa98795a11a653fca39a2
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 "chrome/test/ui/ui_test.h"
7 #include "base/test/test_timeouts.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/chrome_pages.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "content/public/test/test_navigation_observer.h"
19 class BookmarksTest : public InProcessBrowserTest {
20 public:
21 BookmarksTest() {}
23 void OpenBookmarksManager() {
24 content::TestNavigationObserver navigation_observer(
25 browser()->tab_strip_model()->GetActiveWebContents(), 2);
26 navigation_observer.StartWatchingNewWebContents();
28 // Bring up the bookmarks manager tab.
29 chrome::ShowBookmarkManager(browser());
30 navigation_observer.Wait();
33 void AssertIsBookmarksPage(content::WebContents* tab) {
34 GURL url;
35 std::string out;
36 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
37 tab,
38 "domAutomationController.send(location.protocol)",
39 &out));
40 ASSERT_EQ("chrome-extension:", out);
41 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
42 tab,
43 "domAutomationController.send(location.pathname)",
44 &out));
45 ASSERT_EQ("/main.html", out);
49 IN_PROC_BROWSER_TEST_F(BookmarksTest, ShouldRedirectToExtension) {
50 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL));
51 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());
54 IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandOpensBookmarksTab) {
55 ASSERT_EQ(1, browser()->tab_strip_model()->count());
57 // Bring up the bookmarks manager tab.
58 OpenBookmarksManager();
59 ASSERT_EQ(1, browser()->tab_strip_model()->count());
60 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());
63 // TODO(linux_aura) http://crbug.com/163931
64 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
65 #define MAYBE_CommandAgainGoesBackToBookmarksTab DISABLED_CommandAgainGoesBackToBookmarksTab
66 #else
67 #define MAYBE_CommandAgainGoesBackToBookmarksTab CommandAgainGoesBackToBookmarksTab
68 #endif
70 // If this flakes on Mac, use: http://crbug.com/87200
71 IN_PROC_BROWSER_TEST_F(BookmarksTest,
72 MAYBE_CommandAgainGoesBackToBookmarksTab) {
73 ui_test_utils::NavigateToURL(
74 browser(),
75 ui_test_utils::GetTestUrl(base::FilePath(),
76 base::FilePath().AppendASCII("simple.html")));
77 ASSERT_EQ(1, browser()->tab_strip_model()->count());
79 // Bring up the bookmarks manager tab.
80 OpenBookmarksManager();
81 ASSERT_EQ(2, browser()->tab_strip_model()->count());
83 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());
85 // Switch to first tab and run command again.
86 browser()->tab_strip_model()->ActivateTabAt(0, true);
87 chrome::ShowBookmarkManager(browser());
89 // Ensure the bookmarks ui tab is active.
90 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
91 ASSERT_EQ(2, browser()->tab_strip_model()->count());
94 IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) {
95 content::TestNavigationObserver navigation_observer(
96 browser()->tab_strip_model()->GetActiveWebContents());
97 chrome::ShowBookmarkManager(browser());
98 chrome::ShowBookmarkManager(browser());
99 navigation_observer.Wait();
101 ASSERT_EQ(1, browser()->tab_strip_model()->count());
104 IN_PROC_BROWSER_TEST_F(BookmarksTest, BookmarksLoaded) {
105 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL));
106 ASSERT_EQ(1, browser()->tab_strip_model()->count());
107 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents());