Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_bubble_sign_in_delegate_browsertest.cc
blob536c1eafb699cfc3328e1b5d552f8087ae1f84b1
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/common/chrome_switches.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_utils.h"
23 #include "ui/events/event_constants.h"
24 #include "ui/gfx/range/range.h"
26 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest {
27 public:
28 BookmarkBubbleSignInDelegateTest() {}
30 Profile* profile() { return browser()->profile(); }
32 void ReplaceBlank(Browser* browser);
34 private:
35 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest);
38 // The default browser created for tests start with one tab open on
39 // about:blank. The sign-in page is a singleton that will
40 // replace this tab. This function replaces about:blank with another URL
41 // so that the sign in page goes into a new tab.
42 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) {
43 chrome::NavigateParams params(
44 chrome::GetSingletonTabNavigateParams(browser, GURL("chrome:version")));
45 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
46 chrome::ShowSingletonTabOverwritingNTP(browser, params);
49 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) {
50 ReplaceBlank(browser());
51 int starting_tab_count = browser()->tab_strip_model()->count();
53 scoped_ptr<BookmarkBubbleDelegate> delegate;
54 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
56 delegate->OnSignInLinkClicked();
58 // A new tab should have been opened and the browser should be visible.
59 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count());
62 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest,
63 OnSignInLinkClickedReusesBlank) {
64 int starting_tab_count = browser()->tab_strip_model()->count();
66 scoped_ptr<BookmarkBubbleDelegate> delegate;
67 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
69 delegate->OnSignInLinkClicked();
71 // A new tab should have been opened and the browser should be visible.
72 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count());
75 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest,
76 OnSignInLinkClickedIncognito) {
77 ReplaceBlank(browser());
78 Browser* incognito_browser = CreateIncognitoBrowser();
80 int starting_tab_count_normal = browser()->tab_strip_model()->count();
81 int starting_tab_count_incognito =
82 incognito_browser->tab_strip_model()->count();
84 scoped_ptr<BookmarkBubbleDelegate> delegate;
85 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser));
87 delegate->OnSignInLinkClicked();
89 // A new tab should have been opened in the normal browser, which should be
90 // visible.
91 int tab_count_normal = browser()->tab_strip_model()->count();
92 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal);
94 // No effect is expected on the incognito browser.
95 int tab_count_incognito = incognito_browser->tab_strip_model()->count();
96 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito);
99 // Verifies that the sign in page can be loaded in a different browser
100 // if the provided browser is invalidated.
101 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) {
102 // Create an extra browser.
103 Browser* extra_browser = CreateBrowser(profile());
104 ReplaceBlank(extra_browser);
106 int starting_tab_count = extra_browser->tab_strip_model()->count();
108 scoped_ptr<BookmarkBubbleDelegate> delegate;
109 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
111 BrowserList::SetLastActive(extra_browser);
113 // Close all tabs in the original browser. Run all pending messages
114 // to make sure the browser window closes before continuing.
115 browser()->tab_strip_model()->CloseAllTabs();
116 content::RunAllPendingInMessageLoop();
118 delegate->OnSignInLinkClicked();
120 // A new tab should have been opened in the extra browser, which should be
121 // visible.
122 int tab_count = extra_browser->tab_strip_model()->count();
123 EXPECT_EQ(starting_tab_count + 1, tab_count);