| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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/views/sync/one_click_signin_bubble_view.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/browser/ui/browser_window.h" | |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 11 #include "chrome/test/base/in_process_browser_test.h" | |
| 12 #include "chrome/test/base/ui_test_utils.h" | |
| 13 #include "content/public/common/page_transition_types.h" | |
| 14 #include "ui/views/controls/button/label_button.h" | |
| 15 | |
| 16 class OneClickSigninBubbleViewBrowserTest : public InProcessBrowserTest { | |
| 17 public: | |
| 18 OneClickSigninBubbleViewBrowserTest() | |
| 19 : on_start_sync_called_(false), | |
| 20 mode_(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST) { | |
| 21 } | |
| 22 | |
| 23 OneClickSigninBubbleView* ShowOneClickSigninBubble( | |
| 24 BrowserWindow::OneClickSigninBubbleType bubble_type) { | |
| 25 browser()->window()->ShowOneClickSigninBubble( | |
| 26 bubble_type, | |
| 27 string16(), | |
| 28 string16(), | |
| 29 base::Bind(&OneClickSigninBubbleViewBrowserTest::OnStartSync, this)); | |
| 30 | |
| 31 OneClickSigninBubbleView* view = | |
| 32 OneClickSigninBubbleView::view_for_testing(); | |
| 33 EXPECT_TRUE(view != NULL); | |
| 34 view->message_loop_for_testing_ = base::MessageLoop::current(); | |
| 35 return view; | |
| 36 } | |
| 37 | |
| 38 void OnStartSync(OneClickSigninSyncStarter::StartSyncMode mode) { | |
| 39 on_start_sync_called_ = true; | |
| 40 mode_ = mode; | |
| 41 } | |
| 42 | |
| 43 protected: | |
| 44 bool on_start_sync_called_; | |
| 45 OneClickSigninSyncStarter::StartSyncMode mode_; | |
| 46 | |
| 47 private: | |
| 48 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleViewBrowserTest); | |
| 49 }; | |
| 50 | |
| 51 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, ShowBubble) { | |
| 52 ShowOneClickSigninBubble(BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 53 content::RunAllPendingInMessageLoop(); | |
| 54 EXPECT_TRUE(OneClickSigninBubbleView::IsShowing()); | |
| 55 } | |
| 56 | |
| 57 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, ShowDialog) { | |
| 58 ShowOneClickSigninBubble( | |
| 59 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 60 content::RunAllPendingInMessageLoop(); | |
| 61 EXPECT_TRUE(OneClickSigninBubbleView::IsShowing()); | |
| 62 } | |
| 63 | |
| 64 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, HideBubble) { | |
| 65 ShowOneClickSigninBubble(BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 66 | |
| 67 OneClickSigninBubbleView::Hide(); | |
| 68 content::RunAllPendingInMessageLoop(); | |
| 69 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 70 } | |
| 71 | |
| 72 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, HideDialog) { | |
| 73 ShowOneClickSigninBubble( | |
| 74 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 75 | |
| 76 OneClickSigninBubbleView::Hide(); | |
| 77 content::RunAllPendingInMessageLoop(); | |
| 78 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 79 EXPECT_TRUE(on_start_sync_called_); | |
| 80 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | |
| 81 } | |
| 82 | |
| 83 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, BubbleOkButton) { | |
| 84 OneClickSigninBubbleView* view = | |
| 85 ShowOneClickSigninBubble( | |
| 86 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 87 | |
| 88 // Simulate pressing the OK button. Set the message loop in the bubble | |
| 89 // view so that it can be quit once the bubble is hidden. | |
| 90 views::ButtonListener* listener = view; | |
| 91 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, | |
| 92 gfx::Point(), gfx::Point(), | |
| 93 0); | |
| 94 listener->ButtonPressed(view->ok_button_, event); | |
| 95 | |
| 96 // View should no longer be showing. The message loop will exit once the | |
| 97 // fade animation of the bubble is done. | |
| 98 content::RunAllPendingInMessageLoop(); | |
| 99 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 100 } | |
| 101 | |
| 102 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, DialogOkButton) { | |
| 103 OneClickSigninBubbleView* view = ShowOneClickSigninBubble( | |
| 104 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 105 | |
| 106 // Simulate pressing the OK button. Set the message loop in the bubble | |
| 107 // view so that it can be quit once the bubble is hidden. | |
| 108 views::ButtonListener* listener = view; | |
| 109 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, | |
| 110 gfx::Point(), gfx::Point(), | |
| 111 0); | |
| 112 listener->ButtonPressed(view->ok_button_, event); | |
| 113 | |
| 114 // View should no longer be showing and sync should start | |
| 115 // The message loop will exit once the fade animation of the dialog is done. | |
| 116 content::RunAllPendingInMessageLoop(); | |
| 117 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 118 EXPECT_TRUE(on_start_sync_called_); | |
| 119 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | |
| 120 } | |
| 121 | |
| 122 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 123 DialogUndoButton) { | |
| 124 OneClickSigninBubbleView* view = ShowOneClickSigninBubble( | |
| 125 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 126 | |
| 127 // Simulate pressing the undo button. Set the message loop in the bubble | |
| 128 // view so that it can be quit once the bubble is hidden. | |
| 129 views::ButtonListener* listener = view; | |
| 130 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, | |
| 131 gfx::Point(), gfx::Point(), | |
| 132 0); | |
| 133 listener->ButtonPressed(view->undo_button_, event); | |
| 134 | |
| 135 // View should no longer be showing. The message loop will exit once the | |
| 136 // fade animation of the bubble is done. | |
| 137 content::RunAllPendingInMessageLoop(); | |
| 138 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 139 EXPECT_TRUE(on_start_sync_called_); | |
| 140 EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, mode_); | |
| 141 } | |
| 142 | |
| 143 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 144 BubbleAdvancedLink) { | |
| 145 int starting_tab_count = browser()->tab_strip_model()->count(); | |
| 146 | |
| 147 OneClickSigninBubbleView* view = ShowOneClickSigninBubble( | |
| 148 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 149 | |
| 150 // Simulate pressing a link in the bubble.This should replace the current tab. | |
| 151 views::LinkListener* listener = view; | |
| 152 listener->LinkClicked(view->advanced_link_, 0); | |
| 153 | |
| 154 // View should no longer be showing and the current tab should be replaced. | |
| 155 content::RunAllPendingInMessageLoop(); | |
| 156 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 157 int tab_count = browser()->tab_strip_model()->count(); | |
| 158 EXPECT_EQ(starting_tab_count, tab_count); | |
| 159 } | |
| 160 | |
| 161 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 162 DialogAdvancedLink) { | |
| 163 int starting_tab_count = browser()->tab_strip_model()->count(); | |
| 164 | |
| 165 OneClickSigninBubbleView* view = ShowOneClickSigninBubble( | |
| 166 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 167 | |
| 168 // Simulate pressing a link in the bubble. This should open a new tab. | |
| 169 views::LinkListener* listener = view; | |
| 170 listener->LinkClicked(view->advanced_link_, 0); | |
| 171 | |
| 172 // View should no longer be showing and a new tab should be opened. | |
| 173 content::RunAllPendingInMessageLoop(); | |
| 174 EXPECT_TRUE(on_start_sync_called_); | |
| 175 EXPECT_EQ(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, mode_); | |
| 176 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 177 int tab_count = browser()->tab_strip_model()->count(); | |
| 178 EXPECT_EQ(starting_tab_count, tab_count); | |
| 179 } | |
| 180 | |
| 181 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 182 BubbleLearnMoreLink) { | |
| 183 int starting_tab_count = browser()->tab_strip_model()->count(); | |
| 184 | |
| 185 OneClickSigninBubbleView* view = ShowOneClickSigninBubble( | |
| 186 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 187 | |
| 188 // View should no longer be showing and a new tab should be added. | |
| 189 views::LinkListener* listener = view; | |
| 190 listener->LinkClicked(view->learn_more_link_, 0); | |
| 191 | |
| 192 content::RunAllPendingInMessageLoop(); | |
| 193 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 194 int tab_count = browser()->tab_strip_model()->count(); | |
| 195 EXPECT_EQ(starting_tab_count + 1, tab_count); | |
| 196 } | |
| 197 | |
| 198 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 199 BubblePressEnterKey) { | |
| 200 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble( | |
| 201 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 202 | |
| 203 // Simulate pressing the Enter key. | |
| 204 views::View* view = one_click_view; | |
| 205 const ui::Accelerator accelerator(ui::VKEY_RETURN, 0); | |
| 206 view->AcceleratorPressed(accelerator); | |
| 207 | |
| 208 // View should no longer be showing. The message loop will exit once the | |
| 209 // fade animation of the bubble is done. | |
| 210 content::RunAllPendingInMessageLoop(); | |
| 211 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 212 } | |
| 213 | |
| 214 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 215 DialogPressEnterKey) { | |
| 216 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble( | |
| 217 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 218 | |
| 219 // Simulate pressing the Enter key. | |
| 220 views::View* view = one_click_view; | |
| 221 const ui::Accelerator accelerator(ui::VKEY_RETURN, 0); | |
| 222 view->AcceleratorPressed(accelerator); | |
| 223 | |
| 224 // View should no longer be showing. The message loop will exit once the | |
| 225 // fade animation of the bubble is done. | |
| 226 content::RunAllPendingInMessageLoop(); | |
| 227 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 228 EXPECT_TRUE(on_start_sync_called_); | |
| 229 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | |
| 230 } | |
| 231 | |
| 232 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 233 BubblePressEscapeKey) { | |
| 234 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble( | |
| 235 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); | |
| 236 | |
| 237 // Simulate pressing the Escape key. | |
| 238 views::View* view = one_click_view; | |
| 239 const ui::Accelerator accelerator(ui::VKEY_ESCAPE, 0); | |
| 240 view->AcceleratorPressed(accelerator); | |
| 241 | |
| 242 // View should no longer be showing. The message loop will exit once the | |
| 243 // fade animation of the bubble is done. | |
| 244 content::RunAllPendingInMessageLoop(); | |
| 245 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 246 } | |
| 247 | |
| 248 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | |
| 249 DialogPressEscapeKey) { | |
| 250 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble( | |
| 251 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); | |
| 252 | |
| 253 // Simulate pressing the Escape key. | |
| 254 views::View* view = one_click_view; | |
| 255 const ui::Accelerator accelerator(ui::VKEY_ESCAPE, 0); | |
| 256 view->AcceleratorPressed(accelerator); | |
| 257 | |
| 258 // View should no longer be showing. The message loop will exit once the | |
| 259 // fade animation of the bubble is done. | |
| 260 content::RunAllPendingInMessageLoop(); | |
| 261 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 262 EXPECT_FALSE(on_start_sync_called_); | |
| 263 } | |
| OLD | NEW |