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 void BookmarkBubbleSignInDelegateTest::ReplaceBlank(Browser* browser) { | |
39 // The default browser created for tests start with one tab open on | |
40 // about:blank. The sign-in page is a singleton that will | |
41 // replace this tab. This function replaces about:blank with another URL | |
42 // so that the sign in page goes into a new tab. | |
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 | |
noms (inactive)
2014/12/19 19:48:59
If none of the tests are for ChromeOS, can this fi
Roger Tawa OOO till Jul 10th
2015/01/05 20:19:19
Done.
Android already handled in gyp file in previ
| |
49 #if !defined(OS_CHROMEOS) | |
50 | |
51 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | |
52 ReplaceBlank(browser()); | |
53 int starting_tab_count = browser()->tab_strip_model()->count(); | |
54 | |
55 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
56 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
57 | |
58 delegate->OnSignInLinkClicked(); | |
59 | |
60 // A new tab should have been opened and the browser should be visible. | |
61 content::RunAllPendingInMessageLoop(); | |
62 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); | |
63 } | |
64 | |
65 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | |
66 OnSignInLinkClickedReusesBlank) { | |
67 int starting_tab_count = browser()->tab_strip_model()->count(); | |
68 | |
69 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
70 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
71 | |
72 delegate->OnSignInLinkClicked(); | |
73 | |
74 // A new tab should have been opened and the browser should be visible. | |
75 content::RunAllPendingInMessageLoop(); | |
76 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
77 } | |
78 | |
79 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, | |
80 OnSignInLinkClickedIncognito) { | |
81 ReplaceBlank(browser()); | |
82 Browser* incognito_browser = CreateIncognitoBrowser(); | |
83 | |
84 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | |
85 int starting_tab_count_incognito = | |
86 incognito_browser->tab_strip_model()->count(); | |
87 | |
88 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
89 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser)); | |
90 | |
91 delegate->OnSignInLinkClicked(); | |
92 | |
93 content::RunAllPendingInMessageLoop(); | |
94 | |
95 // A new tab should have been opened in the normal browser, which should be | |
96 // visible. | |
97 int tab_count_normal = browser()->tab_strip_model()->count(); | |
98 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | |
99 | |
100 // No effect is expected on the incognito browser. | |
101 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | |
102 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | |
103 } | |
104 | |
105 // Verifies that the sign in page can be loaded in a different browser | |
106 // if the provided browser is invalidated. | |
107 IN_PROC_BROWSER_TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | |
108 // Create an extra browser. | |
109 Browser* extra_browser = CreateBrowser(profile()); | |
110 ReplaceBlank(extra_browser); | |
111 | |
112 int starting_tab_count = extra_browser->tab_strip_model()->count(); | |
113 | |
114 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
115 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | |
116 | |
117 BrowserList::SetLastActive(extra_browser); | |
118 | |
119 browser()->tab_strip_model()->CloseAllTabs(); | |
120 content::RunAllPendingInMessageLoop(); | |
121 | |
122 delegate->OnSignInLinkClicked(); | |
123 | |
124 // A new tab should have been opened in the extra browser, which should be | |
125 // visible. | |
126 content::RunAllPendingInMessageLoop(); | |
127 int tab_count = extra_browser->tab_strip_model()->count(); | |
128 EXPECT_EQ(starting_tab_count + 1, tab_count); | |
129 } | |
130 | |
131 #endif // !defined(OS_CHROMEOS) | |
OLD | NEW |