Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_bubble_sign_in_delegate_browsertest.cc
blob82e3dd9806eeb4c888c29ef81ab9d87d826381a4
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/test_extension_service.h"
12 #include "chrome/browser/extensions/test_extension_system.h"
13 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/singleton_tabs.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/testing_profile.h"
22 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_utils.h"
24 #include "ui/events/event_constants.h"
25 #include "ui/gfx/range/range.h"
27 #if defined(OS_CHROMEOS)
28 const bool kHasProfileChooser = false;
29 #else
30 const bool kHasProfileChooser = true;
31 #endif
33 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest {
34 public:
35 BookmarkBubbleSignInDelegateTest() {}
37 Profile* profile() { return browser()->profile(); }
39 void ReplaceBlank(Browser* browser);
41 private:
42 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest);
45 // The default browser created for tests start with one tab open on
46 // about:blank. The sign-in page is a singleton that will
47 // replace this tab. This function replaces about:blank with another URL
48 // so that the sign in page goes into a new tab.
49 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) {
50 chrome::NavigateParams params(
51 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version")));
52 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
53 chrome::ShowSingletonTabOverwritingNTP(browser, params);
56 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) {
57 ReplaceBlank(browser());
58 int starting_tab_count = browser()->tab_strip_model()->count();
60 scoped_ptr<BookmarkBubbleDelegate> delegate;
61 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
63 delegate->OnSignInLinkClicked();
65 if (kHasProfileChooser) {
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());
73 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest,
74 OnSignInLinkClickedReusesBlank) {
75 int starting_tab_count = browser()->tab_strip_model()->count();
77 scoped_ptr<BookmarkBubbleDelegate> delegate;
78 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
80 delegate->OnSignInLinkClicked();
82 if (kHasProfileChooser) {
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());
90 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest,
91 OnSignInLinkClickedIncognito) {
92 ReplaceBlank(browser());
93 Browser* incognito_browser = CreateIncognitoBrowser();
95 int starting_tab_count_normal = browser()->tab_strip_model()->count();
96 int starting_tab_count_incognito =
97 incognito_browser->tab_strip_model()->count();
99 scoped_ptr<BookmarkBubbleDelegate> delegate;
100 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser));
102 delegate->OnSignInLinkClicked();
104 if (kHasProfileChooser) {
105 // ProfileChooser doesn't show in an incognito window.
106 EXPECT_FALSE(ProfileChooserView::IsShowing());
107 } else {
108 // A new tab should have been opened in the normal browser, which should be
109 // visible.
110 int tab_count_normal = browser()->tab_strip_model()->count();
111 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal);
113 // No effect is expected on the incognito browser.
114 int tab_count_incognito = incognito_browser->tab_strip_model()->count();
115 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito);
118 // Verifies that the sign in page can be loaded in a different browser
119 // if the provided browser is invalidated.
120 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) {
121 // Create an extra browser.
122 Browser* extra_browser = CreateBrowser(profile());
123 ReplaceBlank(extra_browser);
125 int starting_tab_count = extra_browser->tab_strip_model()->count();
127 scoped_ptr<BookmarkBubbleDelegate> delegate;
128 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
130 BrowserList::SetLastActive(extra_browser);
132 // Close all tabs in the original browser. Run all pending messages
133 // to make sure the browser window closes before continuing.
134 browser()->tab_strip_model()->CloseAllTabs();
135 content::RunAllPendingInMessageLoop();
137 delegate->OnSignInLinkClicked();
139 if (kHasProfileChooser) {
140 EXPECT_TRUE(ProfileChooserView::IsShowing());
141 } else {
142 // A new tab should have been opened in the extra browser, which should be
143 // visible.
144 int tab_count = extra_browser->tab_strip_model()->count();
145 EXPECT_EQ(starting_tab_count + 1, tab_count);