Chromium Code Reviews| 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()) |
| 89 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); | |
| 90 else | |
| 91 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 88 | 92 |
| 89 delegate->OnSignInLinkClicked(); | 93 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
|
msw
2016/07/19 21:42:04
optional nit: move this and line 95 outside the pr
Jane
2016/07/19 23:15:11
Done.
| |
| 90 | 94 #else |
| 91 if (kHasProfileChooser) { | 95 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
| 92 if (switches::UsePasswordSeparatedSigninFlow()) { | 96 #endif |
| 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 } | 97 } |
| 103 | 98 |
| 104 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 99 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
| 105 OnSignInLinkClickedIncognito) { | 100 OnSignInLinkClickedIncognito) { |
| 106 ReplaceBlank(browser()); | 101 ReplaceBlank(browser()); |
| 107 Browser* incognito_browser = CreateIncognitoBrowser(); | 102 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 108 | |
| 109 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | 103 int starting_tab_count_normal = browser()->tab_strip_model()->count(); |
| 110 int starting_tab_count_incognito = | 104 int starting_tab_count_incognito = |
| 111 incognito_browser->tab_strip_model()->count(); | 105 incognito_browser->tab_strip_model()->count(); |
| 112 | 106 |
| 113 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 107 SignInBrowser(incognito_browser); |
| 114 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | |
| 115 | 108 |
| 116 delegate->OnSignInLinkClicked(); | 109 int tab_count_normal = browser()->tab_strip_model()->count(); |
| 117 | 110 #if !defined(OS_CHROMEOS) |
| 118 if (kHasProfileChooser) { | 111 // ProfileChooser doesn't show in an incognito window. |
| 119 // ProfileChooser doesn't show in an incognito window. | 112 EXPECT_FALSE(ProfileChooserView::IsShowing()); |
| 120 EXPECT_FALSE(ProfileChooserView::IsShowing()); | 113 // No new tab should have been opened in the normal browser. |
| 121 } else { | 114 EXPECT_EQ(starting_tab_count_normal, tab_count_normal); |
| 122 // A new tab should have been opened in the normal browser, which should be | 115 #else |
| 123 // visible. | 116 // A new tab should have been opened in the normal browser, which should be |
| 124 int tab_count_normal = browser()->tab_strip_model()->count(); | 117 // visible. |
| 125 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | 118 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); |
| 126 } | 119 #endif |
| 127 // No effect is expected on the incognito browser. | 120 // No effect is expected on the incognito browser. |
| 128 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | 121 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); |
| 129 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | 122 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); |
| 130 } | 123 } |
| 131 | 124 |
| 132 // Verifies that the sign in page can be loaded in a different browser | 125 // Verifies that the sign in page can be loaded in a different browser |
| 133 // if the provided browser is invalidated. | 126 // if the provided browser is invalidated. |
| 134 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | 127 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { |
| 135 // Create an extra browser. | 128 // Create an extra browser. |
| 136 Browser* extra_browser = CreateBrowser(profile()); | 129 Browser* extra_browser = CreateBrowser(profile()); |
| 137 ReplaceBlank(extra_browser); | 130 ReplaceBlank(extra_browser); |
| 138 | 131 |
| 139 int starting_tab_count = extra_browser->tab_strip_model()->count(); | 132 int starting_tab_count = extra_browser->tab_strip_model()->count(); |
| 140 | 133 |
| 141 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 134 std::unique_ptr<BubbleSyncPromoDelegate> delegate; |
| 142 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 135 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
| 143 | 136 |
| 144 BrowserList::SetLastActive(extra_browser); | 137 BrowserList::SetLastActive(extra_browser); |
| 145 | 138 |
| 146 // Close all tabs in the original browser. Run all pending messages | 139 // Close all tabs in the original browser. Run all pending messages |
| 147 // to make sure the browser window closes before continuing. | 140 // to make sure the browser window closes before continuing. |
| 148 browser()->tab_strip_model()->CloseAllTabs(); | 141 browser()->tab_strip_model()->CloseAllTabs(); |
| 149 content::RunAllPendingInMessageLoop(); | 142 content::RunAllPendingInMessageLoop(); |
| 150 | 143 |
| 151 delegate->OnSignInLinkClicked(); | 144 delegate->OnSignInLinkClicked(); |
| 152 | 145 |
| 153 if (kHasProfileChooser) { | 146 int tab_count = extra_browser->tab_strip_model()->count(); |
| 154 if (switches::UsePasswordSeparatedSigninFlow()) { | 147 #if !defined(OS_CHROMEOS) |
| 155 EXPECT_TRUE(extra_browser->signin_view_controller()->delegate()); | 148 if (switches::UsePasswordSeparatedSigninFlow()) |
| 156 } else { | 149 EXPECT_TRUE(extra_browser->signin_view_controller()->delegate()); |
| 157 EXPECT_TRUE(ProfileChooserView::IsShowing()); | 150 else |
| 158 } | 151 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
| 159 } else { | 152 EXPECT_EQ(starting_tab_count, tab_count); |
| 160 // A new tab should have been opened in the extra browser, which should be | 153 #else |
| 161 // visible. | 154 // A new tab should have been opened in the extra browser, which should be |
| 162 int tab_count = extra_browser->tab_strip_model()->count(); | 155 // visible. |
| 163 EXPECT_EQ(starting_tab_count + 1, tab_count); | 156 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 164 } | 157 #endif |
| 165 } | 158 } |
| OLD | NEW |