Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate_unittest.cc

Issue 23726016: Show non-incognito browser in front of incognito browser when signing in from bookmark bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix type Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" 9 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/browser_with_test_window_test.h" 13 #include "chrome/test/base/browser_with_test_window_test.h"
14 #include "chrome/test/base/testing_profile.h"
13 #include "ui/base/events/event_constants.h" 15 #include "ui/base/events/event_constants.h"
14 #include "ui/base/range/range.h" 16 #include "ui/base/range/range.h"
15 17
16 typedef BrowserWithTestWindowTest BookmarkBubbleSignInDelegateTest; 18 class BookmarkBubbleSignInDelegateTest : public BrowserWithTestWindowTest {
19 public:
20 BookmarkBubbleSignInDelegateTest() {}
21
22 protected:
23 class Window : public TestBrowserWindow {
24 public:
25 Window() : show_count_(0) {}
26
27 int show_count() { return show_count_; }
28
29 private:
30 // TestBrowserWindow:
31 virtual void Show() OVERRIDE {
32 ++show_count_;
33 }
34
35 // Number of times that the Show() method has been called.
36 int show_count_;
37
38 DISALLOW_COPY_AND_ASSIGN(Window);
39 };
40
41 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE {
42 return new Window();
43 }
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest);
47 };
17 48
18 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { 49 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) {
19 int starting_tab_count = browser()->tab_strip_model()->count(); 50 int starting_tab_count = browser()->tab_strip_model()->count();
20 51
21 scoped_ptr<BookmarkBubbleDelegate> delegate; 52 scoped_ptr<BookmarkBubbleDelegate> delegate;
22 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); 53 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
23 54
24 delegate->OnSignInLinkClicked(); 55 delegate->OnSignInLinkClicked();
25 56
26 // A new tab should have been opened. 57 // A new tab should have been opened and the browser should be visible.
27 int tab_count = browser()->tab_strip_model()->count(); 58 int tab_count = browser()->tab_strip_model()->count();
28 EXPECT_EQ(starting_tab_count + 1, tab_count); 59 EXPECT_EQ(starting_tab_count + 1, tab_count);
60 EXPECT_EQ(1,
61 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
62 browser()->window())->show_count());
63 }
64
65 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClickedIncognito) {
66 // Create an incognito browser.
67 TestingProfile::Builder incognito_profile_builder;
68 incognito_profile_builder.SetIncognito();
69 scoped_ptr<TestingProfile> incognito_profile =
70 incognito_profile_builder.Build();
71 incognito_profile->SetOriginalProfile(profile());
72 profile()->SetOffTheRecordProfile(incognito_profile.PassAs<Profile>());
73
74 scoped_ptr<BrowserWindow> incognito_window;
75 incognito_window.reset(CreateBrowserWindow());
76 Browser::CreateParams params(browser()->profile()->GetOffTheRecordProfile(),
77 browser()->host_desktop_type());
78 params.window = incognito_window.get();
79 scoped_ptr<Browser> incognito_browser;
80 incognito_browser.reset(new Browser(params));
81
82 int starting_tab_count_normal = browser()->tab_strip_model()->count();
83 int starting_tab_count_incognito =
84 incognito_browser.get()->tab_strip_model()->count();
85
86 scoped_ptr<BookmarkBubbleDelegate> delegate;
87 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser.get()));
88
89 delegate->OnSignInLinkClicked();
90
91 // A new tab should have been opened in the normal browser, which should be
92 // visible.
93 int tab_count_normal = browser()->tab_strip_model()->count();
94 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal);
95 EXPECT_EQ(1,
96 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
97 browser()->window())->show_count());
98
99 // No effect is expected on the incognito browser.
100 int tab_count_incognito = incognito_browser->tab_strip_model()->count();
101 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito);
102 EXPECT_EQ(0,
103 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
104 incognito_window.get())->show_count());
29 } 105 }
30 106
31 // Verifies that the sign in page can be loaded in a different browser 107 // Verifies that the sign in page can be loaded in a different browser
32 // if the provided browser is invalidated. 108 // if the provided browser is invalidated.
33 TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { 109 TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) {
34 // Create an extra browser. 110 // Create an extra browser.
35 scoped_ptr<BrowserWindow> extra_window; 111 scoped_ptr<BrowserWindow> extra_window;
36 extra_window.reset(CreateBrowserWindow()); 112 extra_window.reset(CreateBrowserWindow());
37 113
38 Browser::CreateParams params(browser()->profile(), 114 Browser::CreateParams params(browser()->profile(),
39 browser()->host_desktop_type()); 115 browser()->host_desktop_type());
40 params.window = extra_window.get(); 116 params.window = extra_window.get();
41 scoped_ptr<Browser> extra_browser; 117 scoped_ptr<Browser> extra_browser;
42 extra_browser.reset(new Browser(params)); 118 extra_browser.reset(new Browser(params));
43 119
44 int starting_tab_count = extra_browser->tab_strip_model()->count(); 120 int starting_tab_count = extra_browser->tab_strip_model()->count();
45 121
46 scoped_ptr<BookmarkBubbleDelegate> delegate; 122 scoped_ptr<BookmarkBubbleDelegate> delegate;
47 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); 123 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
48 124
49 BrowserList::SetLastActive(extra_browser.get()); 125 BrowserList::SetLastActive(extra_browser.get());
50 126
51 browser()->tab_strip_model()->CloseAllTabs(); 127 browser()->tab_strip_model()->CloseAllTabs();
52 set_browser(NULL); 128 set_browser(NULL);
53 129
54 delegate->OnSignInLinkClicked(); 130 delegate->OnSignInLinkClicked();
55 131
56 // A new tab should have been opened in the extra browser. 132 // A new tab should have been opened in the extra browser, which should be
133 // visible.
57 int tab_count = extra_browser->tab_strip_model()->count(); 134 int tab_count = extra_browser->tab_strip_model()->count();
58 EXPECT_EQ(starting_tab_count + 1, tab_count); 135 EXPECT_EQ(starting_tab_count + 1, tab_count);
136 EXPECT_EQ(1,
137 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
138 extra_window.get())->show_count());
59 139
60 // Required to avoid a crash when the browser is deleted. 140 // Required to avoid a crash when the browser is deleted.
61 extra_browser->tab_strip_model()->CloseAllTabs(); 141 extra_browser->tab_strip_model()->CloseAllTabs();
62 } 142 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698