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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/test_extension_service.h" | 11 #include "chrome/browser/extensions/test_extension_service.h" |
12 #include "chrome/browser/extensions/test_extension_system.h" | 12 #include "chrome/browser/extensions/test_extension_system.h" |
13 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" | 13 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
16 #include "chrome/browser/ui/singleton_tabs.h" | 16 #include "chrome/browser/ui/singleton_tabs.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
23 #include "ui/events/event_constants.h" | 24 #include "ui/events/event_constants.h" |
24 #include "ui/gfx/range/range.h" | 25 #include "ui/gfx/range/range.h" |
25 | 26 |
27 | |
sky
2015/03/09 15:54:20
nit: remove this newline.
Mike Lerman
2015/03/10 15:58:58
Done.
| |
26 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { | 28 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { |
27 public: | 29 public: |
28 BookmarkBubbleSignInDelegateTest() {} | 30 BookmarkBubbleSignInDelegateTest() {} |
29 | 31 |
30 Profile* profile() { return browser()->profile(); } | 32 Profile* profile() { return browser()->profile(); } |
31 | 33 |
32 void ReplaceBlank(Browser* browser); | 34 void ReplaceBlank(Browser* browser); |
33 | 35 |
36 void ExpectProfileChooserShows(bool shows); | |
37 | |
34 private: | 38 private: |
35 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); | 39 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); |
36 }; | 40 }; |
37 | 41 |
38 // The default browser created for tests start with one tab open on | 42 // The default browser created for tests start with one tab open on |
39 // about:blank. The sign-in page is a singleton that will | 43 // about:blank. The sign-in page is a singleton that will |
40 // replace this tab. This function replaces about:blank with another URL | 44 // replace this tab. This function replaces about:blank with another URL |
41 // so that the sign in page goes into a new tab. | 45 // so that the sign in page goes into a new tab. |
42 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { | 46 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { |
43 chrome::NavigateParams params( | 47 chrome::NavigateParams params( |
44 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version"))); | 48 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version"))); |
45 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; | 49 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
46 chrome::ShowSingletonTabOverwritingNTP(browser, params); | 50 chrome::ShowSingletonTabOverwritingNTP(browser, params); |
47 } | 51 } |
48 | 52 |
53 void BookmarkBubbleSignInDelegateTest::ExpectProfileChooserShows(bool shows) { | |
54 base::MessageLoop::current()->RunUntilIdle(); | |
sky
2015/03/09 15:54:20
We do you need the RunUntilIdle?
The pattern you
Mike Lerman
2015/03/10 15:58:58
We don't need the Runloop();. I thought we didn't,
| |
55 // There's no good way, across platforms, to determine if the User Menu shows. | |
56 // Verify for Views, and otherwise we just check nothing crashed. | |
57 #if defined(TOOLKIT_VIEWS) | |
58 EXPECT_EQ(shows, ProfileChooserView::IsShowing()); | |
59 #endif | |
60 } | |
61 | |
49 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | 62 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { |
50 ReplaceBlank(browser()); | 63 ReplaceBlank(browser()); |
51 int starting_tab_count = browser()->tab_strip_model()->count(); | 64 int starting_tab_count = browser()->tab_strip_model()->count(); |
52 | 65 |
53 scoped_ptr<BookmarkBubbleDelegate> delegate; | 66 scoped_ptr<BookmarkBubbleDelegate> delegate; |
54 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 67 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
55 | 68 |
56 delegate->OnSignInLinkClicked(); | 69 delegate->OnSignInLinkClicked(); |
57 | 70 |
58 // A new tab should have been opened and the browser should be visible. | 71 #if defined(OS_CHROMEOS) |
sky
2015/03/09 15:54:20
All these ifdefs make it hard to follow. I think i
Mike Lerman
2015/03/10 15:58:58
Done.
| |
72 // ChromeOS has no Profile Chooser; signin happens in a full tab. | |
59 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); | 73 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); |
74 #else | |
75 // The browser remains visible and the Profile Chooser shows. | |
76 ExpectProfileChooserShows(true); | |
77 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
78 #endif | |
60 } | 79 } |
61 | 80 |
62 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 81 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
63 OnSignInLinkClickedReusesBlank) { | 82 OnSignInLinkClickedReusesBlank) { |
64 int starting_tab_count = browser()->tab_strip_model()->count(); | 83 int starting_tab_count = browser()->tab_strip_model()->count(); |
65 | 84 |
66 scoped_ptr<BookmarkBubbleDelegate> delegate; | 85 scoped_ptr<BookmarkBubbleDelegate> delegate; |
67 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 86 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
68 | 87 |
69 delegate->OnSignInLinkClicked(); | 88 delegate->OnSignInLinkClicked(); |
70 | 89 |
71 // A new tab should have been opened and the browser should be visible. | 90 #if defined(OS_CHROMEOS) |
91 // ChromeOS has no Profile Chooser; signin happens in a full tab. | |
72 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | 92 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); |
93 #else | |
94 // The browser remains visible and the Profile Chooser shows. | |
95 ExpectProfileChooserShows(true); | |
96 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
97 #endif | |
73 } | 98 } |
74 | 99 |
75 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 100 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
76 OnSignInLinkClickedIncognito) { | 101 OnSignInLinkClickedIncognito) { |
77 ReplaceBlank(browser()); | 102 ReplaceBlank(browser()); |
78 Browser* incognito_browser = CreateIncognitoBrowser(); | 103 Browser* incognito_browser = CreateIncognitoBrowser(); |
79 | 104 |
105 #if defined(OS_CHROMEOS) | |
80 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | 106 int starting_tab_count_normal = browser()->tab_strip_model()->count(); |
107 #endif | |
81 int starting_tab_count_incognito = | 108 int starting_tab_count_incognito = |
82 incognito_browser->tab_strip_model()->count(); | 109 incognito_browser->tab_strip_model()->count(); |
83 | 110 |
84 scoped_ptr<BookmarkBubbleDelegate> delegate; | 111 scoped_ptr<BookmarkBubbleDelegate> delegate; |
85 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | 112 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); |
86 | 113 |
87 delegate->OnSignInLinkClicked(); | 114 delegate->OnSignInLinkClicked(); |
88 | 115 |
116 | |
117 #if defined(OS_CHROMEOS) | |
118 // ChromeOS has no Profile Chooser; signin happens in a full tab. | |
89 // A new tab should have been opened in the normal browser, which should be | 119 // A new tab should have been opened in the normal browser, which should be |
90 // visible. | 120 // visible. |
91 int tab_count_normal = browser()->tab_strip_model()->count(); | 121 int tab_count_normal = browser()->tab_strip_model()->count(); |
92 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | 122 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); |
93 | 123 |
94 // No effect is expected on the incognito browser. | 124 // No effect is expected on the incognito browser. |
95 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | 125 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); |
96 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | 126 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); |
127 #else | |
128 // ProfileChooser doesn't show in an incognito window. | |
129 ExpectProfileChooserShows(false); | |
130 | |
131 // No effect is expected on the incognito browser. | |
132 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | |
133 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | |
134 #endif | |
97 } | 135 } |
98 | |
99 // Verifies that the sign in page can be loaded in a different browser | 136 // Verifies that the sign in page can be loaded in a different browser |
100 // if the provided browser is invalidated. | 137 // if the provided browser is invalidated. |
101 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | 138 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { |
102 // Create an extra browser. | 139 // Create an extra browser. |
103 Browser* extra_browser = CreateBrowser(profile()); | 140 Browser* extra_browser = CreateBrowser(profile()); |
104 ReplaceBlank(extra_browser); | 141 ReplaceBlank(extra_browser); |
105 | 142 |
143 #if defined(OS_CHROMEOS) | |
106 int starting_tab_count = extra_browser->tab_strip_model()->count(); | 144 int starting_tab_count = extra_browser->tab_strip_model()->count(); |
145 #endif | |
107 | 146 |
108 scoped_ptr<BookmarkBubbleDelegate> delegate; | 147 scoped_ptr<BookmarkBubbleDelegate> delegate; |
109 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 148 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
110 | 149 |
111 BrowserList::SetLastActive(extra_browser); | 150 BrowserList::SetLastActive(extra_browser); |
112 | 151 |
113 // Close all tabs in the original browser. Run all pending messages | 152 // Close all tabs in the original browser. Run all pending messages |
114 // to make sure the browser window closes before continuing. | 153 // to make sure the browser window closes before continuing. |
115 browser()->tab_strip_model()->CloseAllTabs(); | 154 browser()->tab_strip_model()->CloseAllTabs(); |
116 content::RunAllPendingInMessageLoop(); | 155 content::RunAllPendingInMessageLoop(); |
117 | 156 |
118 delegate->OnSignInLinkClicked(); | 157 delegate->OnSignInLinkClicked(); |
119 | 158 |
159 #if defined(OS_CHROMEOS) | |
160 // ChromeOS has no Profile Chooser; signin happens in a full tab. | |
120 // A new tab should have been opened in the extra browser, which should be | 161 // A new tab should have been opened in the extra browser, which should be |
121 // visible. | 162 // visible. |
122 int tab_count = extra_browser->tab_strip_model()->count(); | 163 int tab_count = extra_browser->tab_strip_model()->count(); |
123 EXPECT_EQ(starting_tab_count + 1, tab_count); | 164 EXPECT_EQ(starting_tab_count + 1, tab_count); |
165 #else | |
166 // The Profile Chooser shows in a browser. | |
167 ExpectProfileChooserShows(true); | |
168 #endif | |
124 } | 169 } |
OLD | NEW |