OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" | |
6 | |
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" | |
25 | |
26 class BookmarkBubbleSignInDelegateTest : public InProcessBrowserTest { | |
27 public: | |
28 BookmarkBubbleSignInDelegateTest() {} | |
29 | |
30 Profile* profile() { return browser()->profile(); } | |
31 | |
32 void ReplaceBlank(Browser* browser); | |
33 | |
34 private: | |
35 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); | |
36 }; | |
37 | |
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); | |
47 } | |
48 | |
49 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | |
50 ReplaceBlank(browser()); | |
51 int starting_tab_count = browser()->tab_strip_model()->count(); | |
52 | |
53 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
54 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
55 | |
56 delegate->OnSignInLinkClicked(); | |
57 | |
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()); | |
60 } | |
61 | |
62 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | |
63 OnSignInLinkClickedReusesBlank) { | |
64 int starting_tab_count = browser()->tab_strip_model()->count(); | |
65 | |
66 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
67 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
68 | |
69 delegate->OnSignInLinkClicked(); | |
70 | |
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()); | |
73 } | |
74 | |
75 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | |
76 OnSignInLinkClickedIncognito) { | |
77 ReplaceBlank(browser()); | |
78 Browser* incognito_browser = CreateIncognitoBrowser(); | |
79 | |
80 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | |
81 int starting_tab_count_incognito = | |
82 incognito_browser->tab_strip_model()->count(); | |
83 | |
84 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
85 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | |
86 | |
87 delegate->OnSignInLinkClicked(); | |
88 | |
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); | |
93 | |
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); | |
97 } | |
98 | |
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); | |
105 | |
106 int starting_tab_count = extra_browser->tab_strip_model()->count(); | |
107 | |
108 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
109 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
110 | |
111 BrowserList::SetLastActive(extra_browser); | |
112 | |
113 browser()->tab_strip_model()->CloseAllTabs(); | |
114 content::RunAllPendingInMessageLoop(); | |
sky
2015/01/06 22:49:11
Please document why this one is needed.
Roger Tawa OOO till Jul 10th
2015/01/07 02:09:09
Done.
| |
115 | |
116 delegate->OnSignInLinkClicked(); | |
117 | |
118 // A new tab should have been opened in the extra browser, which should be | |
119 // visible. | |
120 int tab_count = extra_browser->tab_strip_model()->count(); | |
121 EXPECT_EQ(starting_tab_count + 1, tab_count); | |
122 } | |
OLD | NEW |