| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/test/test_timeouts.h" | 5 #include "base/test/test_timeouts.h" |
| 6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/chrome_pages.h" | 8 #include "chrome/browser/ui/chrome_pages.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.h" |
| 10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/test_navigation_observer.h" | 17 #include "content/public/test/test_navigation_observer.h" |
| 17 | 18 |
| 18 class BookmarksTest : public InProcessBrowserTest { | 19 class BookmarksTest : public InProcessBrowserTest { |
| 19 public: | 20 public: |
| 20 BookmarksTest() {} | 21 BookmarksTest() {} |
| 21 | 22 |
| 22 void SetUpOnMainThread() override { | 23 void SetUpOnMainThread() override { |
| 23 InProcessBrowserTest::SetUpOnMainThread(); | 24 InProcessBrowserTest::SetUpOnMainThread(); |
| 24 | 25 |
| 25 // Re-enable accessibility checks when audit failures are resolved. | 26 // Re-enable accessibility checks when audit failures are resolved. |
| 26 // AX_TEXT_01: http://crbug.com/559201 | 27 // AX_TEXT_01: http://crbug.com/559201 |
| 27 // AX_ARIA_08: http://crbug.com/559202 | 28 // AX_ARIA_08: http://crbug.com/559202 |
| 28 // EnableAccessibilityChecksForTestCase(true); | 29 // EnableAccessibilityChecksForTestCase(true); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void OpenBookmarksManager() { | 32 void OpenBookmarksManager() { |
| 32 content::TestNavigationObserver navigation_observer( | 33 content::TestNavigationObserver navigation_observer( |
| 33 browser()->tab_strip_model()->GetActiveWebContents(), 2); | 34 browser()->tab_strip_model()->GetActiveWebContents(), |
| 35 MdBookmarksUI::IsEnabled() ? 1 : 2); |
| 34 navigation_observer.StartWatchingNewWebContents(); | 36 navigation_observer.StartWatchingNewWebContents(); |
| 35 | 37 |
| 36 // Bring up the bookmarks manager tab. | 38 // Bring up the bookmarks manager tab. |
| 37 chrome::ShowBookmarkManager(browser()); | 39 chrome::ShowBookmarkManager(browser()); |
| 38 navigation_observer.Wait(); | 40 navigation_observer.Wait(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void AssertIsBookmarksPage(content::WebContents* tab) { | 43 void AssertIsBookmarksPage(content::WebContents* tab) { |
| 42 GURL url; | 44 GURL url; |
| 43 std::string out; | 45 std::string out; |
| 46 |
| 47 if (MdBookmarksUI::IsEnabled()) { |
| 48 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 49 tab, "domAutomationController.send(location.href)", &out)); |
| 50 ASSERT_EQ("chrome://bookmarks/?id=1", out); |
| 51 return; |
| 52 } |
| 53 |
| 44 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 54 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 45 tab, | 55 tab, |
| 46 "domAutomationController.send(location.protocol)", | 56 "domAutomationController.send(location.protocol)", |
| 47 &out)); | 57 &out)); |
| 48 ASSERT_EQ("chrome-extension:", out); | 58 ASSERT_EQ("chrome-extension:", out); |
| 49 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 59 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 50 tab, | 60 tab, |
| 51 "domAutomationController.send(location.pathname)", | 61 "domAutomationController.send(location.pathname)", |
| 52 &out)); | 62 &out)); |
| 53 ASSERT_EQ("/main.html", out); | 63 ASSERT_EQ("/main.html", out); |
| 54 } | 64 } |
| 55 }; | 65 }; |
| 56 | 66 |
| 57 IN_PROC_BROWSER_TEST_F(BookmarksTest, ShouldRedirectToExtension) { | |
| 58 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL)); | |
| 59 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); | |
| 60 } | |
| 61 | |
| 62 IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandOpensBookmarksTab) { | 67 IN_PROC_BROWSER_TEST_F(BookmarksTest, CommandOpensBookmarksTab) { |
| 63 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 68 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 64 | 69 |
| 65 // Bring up the bookmarks manager tab. | 70 // Bring up the bookmarks manager tab. |
| 66 OpenBookmarksManager(); | 71 OpenBookmarksManager(); |
| 67 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 72 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 68 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); | 73 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); |
| 69 } | 74 } |
| 70 | 75 |
| 71 // Flaky on Mac: https://crbug.com/524216 | 76 // Flaky on Mac: https://crbug.com/524216 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 85 base::FilePath().AppendASCII("simple.html"))); | 90 base::FilePath().AppendASCII("simple.html"))); |
| 86 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 91 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 87 | 92 |
| 88 // Bring up the bookmarks manager tab. | 93 // Bring up the bookmarks manager tab. |
| 89 OpenBookmarksManager(); | 94 OpenBookmarksManager(); |
| 90 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 95 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 91 | 96 |
| 92 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); | 97 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); |
| 93 | 98 |
| 94 // Switch to first tab and run command again. | 99 // Switch to first tab and run command again. |
| 95 browser()->tab_strip_model()->ActivateTabAt(0, true); | 100 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 96 chrome::ShowBookmarkManager(browser()); | 101 chrome::ShowBookmarkManager(browser()); |
| 97 | 102 |
| 98 // Ensure the bookmarks ui tab is active. | 103 // Ensure the bookmarks ui tab is active. |
| 99 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); | 104 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 100 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 105 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 101 } | 106 } |
| 102 | 107 |
| 103 IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) { | 108 IN_PROC_BROWSER_TEST_F(BookmarksTest, TwoCommandsOneTab) { |
| 104 content::TestNavigationObserver navigation_observer( | 109 content::TestNavigationObserver navigation_observer( |
| 105 browser()->tab_strip_model()->GetActiveWebContents()); | 110 browser()->tab_strip_model()->GetActiveWebContents()); |
| 106 chrome::ShowBookmarkManager(browser()); | 111 chrome::ShowBookmarkManager(browser()); |
| 107 chrome::ShowBookmarkManager(browser()); | 112 chrome::ShowBookmarkManager(browser()); |
| 108 navigation_observer.Wait(); | 113 navigation_observer.Wait(); |
| 109 | 114 |
| 110 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 115 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 111 } | 116 } |
| 112 | 117 |
| 113 IN_PROC_BROWSER_TEST_F(BookmarksTest, BookmarksLoaded) { | 118 IN_PROC_BROWSER_TEST_F(BookmarksTest, BookmarksLoaded) { |
| 114 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL)); | 119 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIBookmarksURL)); |
| 115 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 120 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 116 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); | 121 AssertIsBookmarksPage(browser()->tab_strip_model()->GetActiveWebContents()); |
| 117 } | 122 } |
| OLD | NEW |