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 void CreateRemoveSigninBrowser(Browser* last_active); | |
|
msw
2016/07/19 18:51:04
This name is a bit confusing, and it seems like yo
Jane
2016/07/19 21:29:56
Done. Removed this and put the code back.
| |
| 44 | |
| 45 private: | 45 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); | 46 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // The default browser created for tests start with one tab open on | 49 // The default browser created for tests start with one tab open on |
| 50 // about:blank. The sign-in page is a singleton that will | 50 // about:blank. The sign-in page is a singleton that will |
| 51 // replace this tab. This function replaces about:blank with another URL | 51 // replace this tab. This function replaces about:blank with another URL |
| 52 // so that the sign in page goes into a new tab. | 52 // so that the sign in page goes into a new tab. |
| 53 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { | 53 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { |
| 54 chrome::NavigateParams params( | 54 chrome::NavigateParams params( |
| 55 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version"))); | 55 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version"))); |
| 56 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; | 56 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 57 chrome::ShowSingletonTabOverwritingNTP(browser, params); | 57 chrome::ShowSingletonTabOverwritingNTP(browser, params); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void BookmarkBubbleSignInDelegateTest::SignInBrowser(Browser* browser) { | |
| 61 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | |
| 62 delegate.reset(new BookmarkBubbleSignInDelegate(browser)); | |
| 63 delegate->OnSignInLinkClicked(); | |
| 64 } | |
| 65 | |
| 66 void BookmarkBubbleSignInDelegateTest::CreateRemoveSigninBrowser( | |
| 67 Browser* last_active) { | |
| 68 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | |
| 69 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
| 70 | |
| 71 BrowserList::SetLastActive(last_active); | |
| 72 | |
| 73 // Close all tabs in the original browser. Run all pending messages to make | |
| 74 // sure the browser window closes before continuing. | |
| 75 browser()->tab_strip_model()->CloseAllTabs(); | |
| 76 content::RunAllPendingInMessageLoop(); | |
| 77 | |
| 78 delegate->OnSignInLinkClicked(); | |
| 79 } | |
| 80 | |
| 60 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | 81 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { |
| 61 ReplaceBlank(browser()); | 82 ReplaceBlank(browser()); |
| 62 int starting_tab_count = browser()->tab_strip_model()->count(); | 83 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 84 SignInBrowser(browser()); | |
| 63 | 85 |
| 64 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 86 #if !defined(OS_CHROMEOS) |
| 65 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 87 if (switches::UsePasswordSeparatedSigninFlow()) { |
|
msw
2016/07/19 18:51:04
optional nit: drop all these unnecessary curly bra
Jane
2016/07/19 21:29:56
Done.
| |
| 88 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); | |
| 89 } else { | |
| 90 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 91 } | |
| 66 | 92 |
| 67 delegate->OnSignInLinkClicked(); | 93 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
| 68 | 94 #else |
| 69 if (kHasProfileChooser) { | 95 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); |
| 70 if (switches::UsePasswordSeparatedSigninFlow()) { | 96 #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 } | 97 } |
| 81 | 98 |
| 82 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 99 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
| 83 OnSignInLinkClickedReusesBlank) { | 100 OnSignInLinkClickedReusesBlank) { |
| 84 int starting_tab_count = browser()->tab_strip_model()->count(); | 101 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 102 SignInBrowser(browser()); | |
| 85 | 103 |
| 86 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 104 #if !defined(OS_CHROMEOS) |
| 87 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 105 if (switches::UsePasswordSeparatedSigninFlow()) { |
| 106 EXPECT_TRUE(browser()->signin_view_controller()->delegate()); | |
| 107 } else { | |
| 108 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 109 } | |
| 88 | 110 |
| 89 delegate->OnSignInLinkClicked(); | 111 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
| 90 | 112 #else |
| 91 if (kHasProfileChooser) { | 113 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
| 92 if (switches::UsePasswordSeparatedSigninFlow()) { | 114 #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 } | 115 } |
| 103 | 116 |
| 104 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 117 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
| 105 OnSignInLinkClickedIncognito) { | 118 OnSignInLinkClickedIncognito) { |
| 106 ReplaceBlank(browser()); | 119 ReplaceBlank(browser()); |
| 107 Browser* incognito_browser = CreateIncognitoBrowser(); | 120 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 108 | |
| 109 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | |
| 110 int starting_tab_count_incognito = | 121 int starting_tab_count_incognito = |
| 111 incognito_browser->tab_strip_model()->count(); | 122 incognito_browser->tab_strip_model()->count(); |
| 112 | 123 |
| 113 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 124 #if !defined(OS_CHROMEOS) |
| 114 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | 125 SignInBrowser(incognito_browser); |
| 126 // ProfileChooser doesn't show in an incognito window. | |
| 127 EXPECT_FALSE(ProfileChooserView::IsShowing()); | |
| 128 #else | |
| 129 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | |
|
msw
2016/07/19 18:51:04
Leave this above, with the call to SignInBrowser,
Jane
2016/07/19 21:29:56
Done.
| |
| 130 SignInBrowser(incognito_browser); | |
| 115 | 131 |
| 116 delegate->OnSignInLinkClicked(); | 132 // A new tab should have been opened in the normal browser, which should be |
| 117 | 133 // visible. |
| 118 if (kHasProfileChooser) { | 134 int tab_count_normal = browser()->tab_strip_model()->count(); |
| 119 // ProfileChooser doesn't show in an incognito window. | 135 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); |
| 120 EXPECT_FALSE(ProfileChooserView::IsShowing()); | 136 #endif |
| 121 } else { | |
| 122 // A new tab should have been opened in the normal browser, which should be | |
| 123 // visible. | |
| 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. | 137 // No effect is expected on the incognito browser. |
| 128 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | 138 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); |
| 129 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | 139 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); |
| 130 } | 140 } |
| 131 | 141 |
| 132 // Verifies that the sign in page can be loaded in a different browser | 142 // Verifies that the sign in page can be loaded in a different browser |
| 133 // if the provided browser is invalidated. | 143 // if the provided browser is invalidated. |
| 134 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | 144 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { |
| 135 // Create an extra browser. | 145 // Create an extra browser. |
| 136 Browser* extra_browser = CreateBrowser(profile()); | 146 Browser* extra_browser = CreateBrowser(profile()); |
| 137 ReplaceBlank(extra_browser); | 147 ReplaceBlank(extra_browser); |
| 138 | 148 |
| 149 #if !defined(OS_CHROMEOS) | |
| 150 CreateRemoveSigninBrowser(extra_browser); | |
| 151 if (switches::UsePasswordSeparatedSigninFlow()) { | |
| 152 EXPECT_TRUE(extra_browser->signin_view_controller()->delegate()); | |
| 153 } else { | |
| 154 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 155 } | |
| 156 #else | |
| 139 int starting_tab_count = extra_browser->tab_strip_model()->count(); | 157 int starting_tab_count = extra_browser->tab_strip_model()->count(); |
|
msw
2016/07/19 18:51:04
Try to avoid some of this refactoring. You should
Jane
2016/07/19 21:29:56
Done. I did that much refactoring in an attempt to
| |
| 140 | 158 CreateRemoveSigninBrowser(extra_browser); |
| 141 std::unique_ptr<BubbleSyncPromoDelegate> delegate; | 159 // A new tab should have been opened in the extra browser, which should be |
| 142 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 160 // visible. |
| 143 | 161 int tab_count = extra_browser->tab_strip_model()->count(); |
| 144 BrowserList::SetLastActive(extra_browser); | 162 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 145 | 163 #endif |
| 146 // Close all tabs in the original browser. Run all pending messages | |
| 147 // to make sure the browser window closes before continuing. | |
| 148 browser()->tab_strip_model()->CloseAllTabs(); | |
| 149 content::RunAllPendingInMessageLoop(); | |
| 150 | |
| 151 delegate->OnSignInLinkClicked(); | |
| 152 | |
| 153 if (kHasProfileChooser) { | |
| 154 if (switches::UsePasswordSeparatedSigninFlow()) { | |
| 155 EXPECT_TRUE(extra_browser->signin_view_controller()->delegate()); | |
| 156 } else { | |
| 157 EXPECT_TRUE(ProfileChooserView::IsShowing()); | |
| 158 } | |
| 159 } else { | |
| 160 // A new tab should have been opened in the extra browser, which should be | |
| 161 // visible. | |
| 162 int tab_count = extra_browser->tab_strip_model()->count(); | |
| 163 EXPECT_EQ(starting_tab_count + 1, tab_count); | |
| 164 } | |
| 165 } | 164 } |
| OLD | NEW |