NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_bubble_sign_in_delegate_unittest.cc
blob87685c0bf6f22441584e5dff49d9e09b8c864ac0
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/extensions/test_extension_service.h"
11 #include "chrome/browser/extensions/test_extension_system.h"
12 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/browser_with_test_window_test.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "ui/events/event_constants.h"
19 #include "ui/gfx/range/range.h"
21 class BookmarkBubbleSignInDelegateTest : public BrowserWithTestWindowTest {
22 public:
23 BookmarkBubbleSignInDelegateTest() {}
25 virtual void SetUp() OVERRIDE;
27 protected:
28 class Window : public TestBrowserWindow {
29 public:
30 Window() : show_count_(0) {}
32 int show_count() { return show_count_; }
34 private:
35 // TestBrowserWindow:
36 virtual void Show() OVERRIDE {
37 ++show_count_;
40 // Number of times that the Show() method has been called.
41 int show_count_;
43 DISALLOW_COPY_AND_ASSIGN(Window);
46 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE {
47 return new Window();
50 private:
51 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest);
54 void BookmarkBubbleSignInDelegateTest::SetUp() {
55 BrowserWithTestWindowTest::SetUp();
56 // Adds TestExtensionSystem, since signin uses the gaia auth extension.
57 static_cast<extensions::TestExtensionSystem*>(
58 extensions::ExtensionSystem::Get(profile()))->CreateExtensionService(
59 CommandLine::ForCurrentProcess(), base::FilePath(), false);
62 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) {
63 int starting_tab_count = browser()->tab_strip_model()->count();
65 scoped_ptr<BookmarkBubbleDelegate> delegate;
66 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
68 delegate->OnSignInLinkClicked();
70 // A new tab should have been opened and the browser should be visible.
71 int tab_count = browser()->tab_strip_model()->count();
72 EXPECT_EQ(starting_tab_count + 1, tab_count);
73 EXPECT_LE(1,
74 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
75 browser()->window())->show_count());
78 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClickedIncognito) {
79 // Create an incognito browser.
80 TestingProfile::Builder incognito_profile_builder;
81 incognito_profile_builder.SetIncognito();
82 scoped_ptr<TestingProfile> incognito_profile =
83 incognito_profile_builder.Build();
84 incognito_profile->SetOriginalProfile(profile());
85 profile()->SetOffTheRecordProfile(incognito_profile.PassAs<Profile>());
87 scoped_ptr<BrowserWindow> incognito_window;
88 incognito_window.reset(CreateBrowserWindow());
89 Browser::CreateParams params(browser()->profile()->GetOffTheRecordProfile(),
90 browser()->host_desktop_type());
91 params.window = incognito_window.get();
92 scoped_ptr<Browser> incognito_browser;
93 incognito_browser.reset(new Browser(params));
95 int starting_tab_count_normal = browser()->tab_strip_model()->count();
96 int starting_tab_count_incognito =
97 incognito_browser.get()->tab_strip_model()->count();
99 scoped_ptr<BookmarkBubbleDelegate> delegate;
100 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser.get()));
102 delegate->OnSignInLinkClicked();
104 // A new tab should have been opened in the normal browser, which should be
105 // visible.
106 int tab_count_normal = browser()->tab_strip_model()->count();
107 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal);
108 EXPECT_LE(1,
109 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
110 browser()->window())->show_count());
112 // No effect is expected on the incognito browser.
113 int tab_count_incognito = incognito_browser->tab_strip_model()->count();
114 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito);
115 EXPECT_EQ(0,
116 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
117 incognito_window.get())->show_count());
120 // Verifies that the sign in page can be loaded in a different browser
121 // if the provided browser is invalidated.
122 TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) {
123 // Create an extra browser.
124 scoped_ptr<BrowserWindow> extra_window;
125 extra_window.reset(CreateBrowserWindow());
127 Browser::CreateParams params(browser()->profile(),
128 browser()->host_desktop_type());
129 params.window = extra_window.get();
130 scoped_ptr<Browser> extra_browser;
131 extra_browser.reset(new Browser(params));
133 int starting_tab_count = extra_browser->tab_strip_model()->count();
135 scoped_ptr<BookmarkBubbleDelegate> delegate;
136 delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
138 BrowserList::SetLastActive(extra_browser.get());
140 browser()->tab_strip_model()->CloseAllTabs();
141 set_browser(NULL);
143 delegate->OnSignInLinkClicked();
145 // A new tab should have been opened in the extra browser, which should be
146 // visible.
147 int tab_count = extra_browser->tab_strip_model()->count();
148 EXPECT_EQ(starting_tab_count + 1, tab_count);
149 EXPECT_LE(1,
150 static_cast<BookmarkBubbleSignInDelegateTest::Window*>(
151 extra_window.get())->show_count());
153 // Required to avoid a crash when the browser is deleted.
154 extra_browser->tab_strip_model()->CloseAllTabs();