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 #if defined(OS_CHROMEOS) | |
28 const bool kHasProfileChooser = false; | |
29 #else | |
30 const bool kHasProfileChooser = true; | |
31 #endif | |
32 | |
26 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { | 33 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { |
27 public: | 34 public: |
28 BookmarkBubbleSignInDelegateTest() {} | 35 BookmarkBubbleSignInDelegateTest() {} |
29 | 36 |
30 Profile* profile() { return browser()->profile(); } | 37 Profile* profile() { return browser()->profile(); } |
31 | 38 |
32 void ReplaceBlank(Browser* browser); | 39 void ReplaceBlank(Browser* browser); |
33 | 40 |
34 private: | 41 private: |
35 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); | 42 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); |
(...skipping 12 matching lines...) Expand all Loading... | |
48 | 55 |
49 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | 56 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { |
50 ReplaceBlank(browser()); | 57 ReplaceBlank(browser()); |
51 int starting_tab_count = browser()->tab_strip_model()->count(); | 58 int starting_tab_count = browser()->tab_strip_model()->count(); |
52 | 59 |
53 scoped_ptr<BookmarkBubbleDelegate> delegate; | 60 scoped_ptr<BookmarkBubbleDelegate> delegate; |
54 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 61 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
55 | 62 |
56 delegate->OnSignInLinkClicked(); | 63 delegate->OnSignInLinkClicked(); |
57 | 64 |
58 // A new tab should have been opened and the browser should be visible. | 65 if (kHasProfileChooser) { |
59 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); | 66 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
67 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
68 } else { | |
69 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); | |
70 } | |
60 } | 71 } |
61 | 72 |
62 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 73 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
63 OnSignInLinkClickedReusesBlank) { | 74 OnSignInLinkClickedReusesBlank) { |
64 int starting_tab_count = browser()->tab_strip_model()->count(); | 75 int starting_tab_count = browser()->tab_strip_model()->count(); |
65 | 76 |
66 scoped_ptr<BookmarkBubbleDelegate> delegate; | 77 scoped_ptr<BookmarkBubbleDelegate> delegate; |
67 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 78 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
68 | 79 |
69 delegate->OnSignInLinkClicked(); | 80 delegate->OnSignInLinkClicked(); |
70 | 81 |
71 // A new tab should have been opened and the browser should be visible. | 82 if (kHasProfileChooser) { |
72 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | 83 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
84 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
85 } else { | |
86 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
87 } | |
73 } | 88 } |
74 | 89 |
75 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | 90 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, |
76 OnSignInLinkClickedIncognito) { | 91 OnSignInLinkClickedIncognito) { |
77 ReplaceBlank(browser()); | 92 ReplaceBlank(browser()); |
78 Browser* incognito_browser = CreateIncognitoBrowser(); | 93 Browser* incognito_browser = CreateIncognitoBrowser(); |
79 | 94 |
80 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | 95 int starting_tab_count_normal = browser()->tab_strip_model()->count(); |
81 int starting_tab_count_incognito = | 96 int starting_tab_count_incognito = |
82 incognito_browser->tab_strip_model()->count(); | 97 incognito_browser->tab_strip_model()->count(); |
83 | 98 |
84 scoped_ptr<BookmarkBubbleDelegate> delegate; | 99 scoped_ptr<BookmarkBubbleDelegate> delegate; |
85 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | 100 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); |
86 | 101 |
87 delegate->OnSignInLinkClicked(); | 102 delegate->OnSignInLinkClicked(); |
88 | 103 |
89 // A new tab should have been opened in the normal browser, which should be | 104 if (kHasProfileChooser) { |
90 // visible. | 105 // ProfileChooser doesn't show in an incognito window. |
91 int tab_count_normal = browser()->tab_strip_model()->count(); | 106 EXPECT_FALSE(ProfileChooserView::IsShowing()); |
92 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | |
93 | 107 |
94 // No effect is expected on the incognito browser. | 108 // No effect is expected on the incognito browser. |
95 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | 109 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); |
noms (inactive)
2015/03/17 14:26:30
nit: L108-109 are the same as L117-L120
Mike Lerman
2015/03/18 19:29:48
Ooh, nice! Done.
| |
96 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | 110 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); |
111 } else { | |
112 // A new tab should have been opened in the normal browser, which should be | |
113 // visible. | |
114 int tab_count_normal = browser()->tab_strip_model()->count(); | |
115 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | |
116 | |
117 // No effect is expected on the incognito browser. | |
118 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | |
119 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | |
120 } | |
97 } | 121 } |
98 | 122 |
99 // Verifies that the sign in page can be loaded in a different browser | 123 // Verifies that the sign in page can be loaded in a different browser |
100 // if the provided browser is invalidated. | 124 // if the provided browser is invalidated. |
101 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | 125 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { |
102 // Create an extra browser. | 126 // Create an extra browser. |
103 Browser* extra_browser = CreateBrowser(profile()); | 127 Browser* extra_browser = CreateBrowser(profile()); |
104 ReplaceBlank(extra_browser); | 128 ReplaceBlank(extra_browser); |
105 | 129 |
106 int starting_tab_count = extra_browser->tab_strip_model()->count(); | 130 int starting_tab_count = extra_browser->tab_strip_model()->count(); |
107 | 131 |
108 scoped_ptr<BookmarkBubbleDelegate> delegate; | 132 scoped_ptr<BookmarkBubbleDelegate> delegate; |
109 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 133 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
110 | 134 |
111 BrowserList::SetLastActive(extra_browser); | 135 BrowserList::SetLastActive(extra_browser); |
112 | 136 |
113 // Close all tabs in the original browser. Run all pending messages | 137 // Close all tabs in the original browser. Run all pending messages |
114 // to make sure the browser window closes before continuing. | 138 // to make sure the browser window closes before continuing. |
115 browser()->tab_strip_model()->CloseAllTabs(); | 139 browser()->tab_strip_model()->CloseAllTabs(); |
116 content::RunAllPendingInMessageLoop(); | 140 content::RunAllPendingInMessageLoop(); |
117 | 141 |
118 delegate->OnSignInLinkClicked(); | 142 delegate->OnSignInLinkClicked(); |
119 | 143 |
120 // A new tab should have been opened in the extra browser, which should be | 144 if (kHasProfileChooser) { |
121 // visible. | 145 EXPECT_TRUE(ProfileChooserView::IsShowing()); |
122 int tab_count = extra_browser->tab_strip_model()->count(); | 146 } else { |
123 EXPECT_EQ(starting_tab_count + 1, tab_count); | 147 // A new tab should have been opened in the extra browser, which should be |
148 // visible. | |
149 int tab_count = extra_browser->tab_strip_model()->count(); | |
150 EXPECT_EQ(starting_tab_count + 1, tab_count); | |
151 } | |
124 } | 152 } |
OLD | NEW |