| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/extensions/test_extension_service.h" | 13 #include "chrome/browser/extensions/test_extension_service.h" |
| 14 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/browser_navigator_params.h" | 17 #include "chrome/browser/ui/browser_navigator_params.h" |
| 18 #include "chrome/browser/ui/singleton_tabs.h" | 18 #include "chrome/browser/ui/singleton_tabs.h" |
| 19 #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" | 19 #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | |
| 22 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 25 #include "components/signin/core/common/profile_management_switches.h" | 24 #include "components/signin/core/common/profile_management_switches.h" |
| 26 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 28 #include "ui/events/event_constants.h" | 27 #include "ui/events/event_constants.h" |
| 29 #include "ui/gfx/range/range.h" | 28 #include "ui/gfx/range/range.h" |
| 30 | 29 |
| 31 #if defined(OS_CHROMEOS) | 30 #if !defined(OS_CHROMEOS) |
| 32 const bool kHasProfileChooser = false; | 31 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 33 #else | |
| 34 const bool kHasProfileChooser = true; | |
| 35 #endif | 32 #endif |
| 36 | 33 |
| 37 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { | 34 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { |
| 38 public: | 35 public: |
| 39 BookmarkBubbleSignInDelegateTest() {} | 36 BookmarkBubbleSignInDelegateTest() {} |
| 40 | 37 |
| 41 Profile* profile() { return browser()->profile(); } | 38 Profile* profile() { return browser()->profile(); } |
| 42 | 39 |
| 43 void ReplaceBlank(Browser* browser); | 40 void ReplaceBlank(Browser* browser); |
| 44 | 41 |
| 42 void SignInBrowser(Browser* browser); |
| 43 |
| 45 private: | 44 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); | 45 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 // The default browser created for tests start with one tab open on | 48 // The default browser created for tests start with one tab open on |
| 50 // about:blank. The sign-in page is a singleton that will | 49 // about:blank. The sign-in page is a singleton that will |
| 51 // replace this tab. This function replaces about:blank with another URL | 50 // replace this tab. This function replaces about:blank with another URL |
| 52 // so that the sign in page goes into a new tab. | 51 // so that the sign in page goes into a new tab. |
| 53 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { | 52 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { |
| 54 chrome::NavigateParams params( | 53 chrome::NavigateParams params( |
| 55 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version"))); | 54 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version"))); |
| 56 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; | 55 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 57 chrome::ShowSingletonTabOverwritingNTP(browser, params); | 56 chrome::ShowSingletonTabOverwritingNTP(browser, params); |
| 58 } | 57 } |
| 59 | 58 |
| 59 void BookmarkBubbleSignInDelegateTest::SignInBrowser(Browser* browser) { |
| 60 std::unique_ptr<BubbleSyncPromoDelegate> delegate; |
| 61 delegate.reset(new BookmarkBubbleSignInDelegate(browser)); |
| 62 delegate->OnSignInLinkClicked(); |
| 63 } |
| 64 |
| 60 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | 65 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { |
| 61 ReplaceBlank(browser()); | 66 ReplaceBlank(browser()); |
| 62 int starting_tab_count = browser()->tab_strip_model()->count(); | 67 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 68 SignInBrowser(browser()); |
| 63 | 69 |
| 64 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 70 #if !defined(OS_CHROMEOS) |
| 65 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 71 if (switches::UsePasswordSeparatedSigninFlow()) |
| 72 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); |
| 73 else |
| 74 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
| 66 | 75 |
| 67 delegate->OnSignInLinkClicked(); | 76 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
| 68 | 77 #else |
| 69 if (kHasProfileChooser) { | 78 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); |
| 70 if (switches::UsePasswordSeparatedSigninFlow()) { | 79 #endif |
| 71 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); | |
| 72 } else { | |
| 73 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 74 } | |
| 75 | |
| 76 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
| 77 } else { | |
| 78 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); | |
| 79 } | |
| 80 } | 80 } |
| 81 | 81 |
| 82 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 82 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
| 83 OnSignInLinkClickedReusesBlank) { | 83 OnSignInLinkClickedReusesBlank) { |
| 84 int starting_tab_count = browser()->tab_strip_model()->count(); | 84 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 85 SignInBrowser(browser()); |
| 85 | 86 |
| 86 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 87 #if !defined(OS_CHROMEOS) |
| 87 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 88 if (switches::UsePasswordSeparatedSigninFlow()) |
| 88 | 89 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); |
| 89 delegate->OnSignInLinkClicked(); | 90 else |
| 90 | 91 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
| 91 if (kHasProfileChooser) { | 92 #endif |
| 92 if (switches::UsePasswordSeparatedSigninFlow()) { | 93 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
| 93 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); | |
| 94 } else { | |
| 95 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 96 } | |
| 97 | |
| 98 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
| 99 } else { | |
| 100 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
| 101 } | |
| 102 } | 94 } |
| 103 | 95 |
| 104 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 96 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
| 105 OnSignInLinkClickedIncognito) { | 97 OnSignInLinkClickedIncognito) { |
| 106 ReplaceBlank(browser()); | 98 ReplaceBlank(browser()); |
| 107 Browser* incognito_browser = CreateIncognitoBrowser(); | 99 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 108 | |
| 109 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | 100 int starting_tab_count_normal = browser()->tab_strip_model()->count(); |
| 110 int starting_tab_count_incognito = | 101 int starting_tab_count_incognito = |
| 111 incognito_browser->tab_strip_model()->count(); | 102 incognito_browser->tab_strip_model()->count(); |
| 112 | 103 |
| 113 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 104 SignInBrowser(incognito_browser); |
| 114 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | |
| 115 | 105 |
| 116 delegate->OnSignInLinkClicked(); | 106 int tab_count_normal = browser()->tab_strip_model()->count(); |
| 117 | 107 #if !defined(OS_CHROMEOS) |
| 118 if (kHasProfileChooser) { | 108 // ProfileChooser doesn't show in an incognito window. |
| 119 // ProfileChooser doesn't show in an incognito window. | 109 EXPECT_FALSE(ProfileChooserView::IsShowing()); |
| 120 EXPECT_FALSE(ProfileChooserView::IsShowing()); | 110 #endif |
| 121 } else { | 111 // A new tab should have been opened in the normal browser, which should be |
| 122 // A new tab should have been opened in the normal browser, which should be | 112 // visible. |
| 123 // visible. | 113 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); |
| 124 int tab_count_normal = browser()->tab_strip_model()->count(); | |
| 125 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | |
| 126 } | |
| 127 // No effect is expected on the incognito browser. | 114 // No effect is expected on the incognito browser. |
| 128 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | 115 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); |
| 129 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | 116 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); |
| 130 } | 117 } |
| 131 | 118 |
| 132 // Verifies that the sign in page can be loaded in a different browser | 119 // Verifies that the sign in page can be loaded in a different browser |
| 133 // if the provided browser is invalidated. | 120 // if the provided browser is invalidated. |
| 134 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | 121 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { |
| 135 // Create an extra browser. | 122 // Create an extra browser. |
| 136 Browser* extra_browser = CreateBrowser(profile()); | 123 Browser* extra_browser = CreateBrowser(profile()); |
| 137 ReplaceBlank(extra_browser); | 124 ReplaceBlank(extra_browser); |
| 138 | 125 |
| 139 int starting_tab_count = extra_browser->tab_strip_model()->count(); | 126 int starting_tab_count = extra_browser->tab_strip_model()->count(); |
| 140 | 127 |
| 141 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 128 std::unique_ptr<BubbleSyncPromoDelegate> delegate; |
| 142 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 129 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
| 143 | 130 |
| 144 BrowserList::SetLastActive(extra_browser); | 131 BrowserList::SetLastActive(extra_browser); |
| 145 | 132 |
| 146 // Close all tabs in the original browser. Run all pending messages | 133 // Close all tabs in the original browser. Run all pending messages |
| 147 // to make sure the browser window closes before continuing. | 134 // to make sure the browser window closes before continuing. |
| 148 browser()->tab_strip_model()->CloseAllTabs(); | 135 browser()->tab_strip_model()->CloseAllTabs(); |
| 149 content::RunAllPendingInMessageLoop(); | 136 content::RunAllPendingInMessageLoop(); |
| 150 | 137 |
| 151 delegate->OnSignInLinkClicked(); | 138 delegate->OnSignInLinkClicked(); |
| 152 | 139 |
| 153 if (kHasProfileChooser) { | 140 int tab_count = extra_browser->tab_strip_model()->count(); |
| 154 if (switches::UsePasswordSeparatedSigninFlow()) { | 141 #if !defined(OS_CHROMEOS) |
| 155 EXPECT_TRUE(extra_browser->signin_view_controller()->delegate()); | 142 if (switches::UsePasswordSeparatedSigninFlow()) |
| 156 } else { | 143 EXPECT_TRUE(extra_browser->signin_view_controller()->delegate()); |
| 157 EXPECT_TRUE(ProfileChooserView::IsShowing()); | 144 else |
| 158 } | 145 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
| 159 } else { | 146 EXPECT_EQ(starting_tab_count, tab_count); |
| 160 // A new tab should have been opened in the extra browser, which should be | 147 #else |
| 161 // visible. | 148 // A new tab should have been opened in the extra browser, which should be |
| 162 int tab_count = extra_browser->tab_strip_model()->count(); | 149 // visible. |
| 163 EXPECT_EQ(starting_tab_count + 1, tab_count); | 150 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 164 } | 151 #endif |
| 165 } | 152 } |
| OLD | NEW |