| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/views/sync/one_click_signin_bubble_view.h" | 5 #include "chrome/browser/ui/views/sync/one_click_signin_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "content/public/common/page_transition_types.h" | 13 #include "content/public/common/page_transition_types.h" |
| 13 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
| 14 | 15 |
| 15 class OneClickSigninBubbleViewBrowserTest : public InProcessBrowserTest { | 16 class OneClickSigninBubbleViewBrowserTest : public InProcessBrowserTest { |
| 16 public: | 17 public: |
| 17 OneClickSigninBubbleViewBrowserTest() | 18 OneClickSigninBubbleViewBrowserTest() |
| 18 : on_start_sync_called_(false), | 19 : on_start_sync_called_(false), |
| 19 mode_(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST) { | 20 mode_(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 OneClickSigninBubbleView* ShowOneClickSigninBubble() { | 23 OneClickSigninBubbleView* ShowOneClickSigninBubble( |
| 24 BrowserWindow::OneClickSigninBubbleType bubble_type) { |
| 23 browser()->window()->ShowOneClickSigninBubble( | 25 browser()->window()->ShowOneClickSigninBubble( |
| 24 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 26 bubble_type, |
| 27 string16(), |
| 25 string16(), | 28 string16(), |
| 26 base::Bind(&OneClickSigninBubbleViewBrowserTest::OnStartSync, this)); | 29 base::Bind(&OneClickSigninBubbleViewBrowserTest::OnStartSync, this)); |
| 27 | 30 |
| 28 content::RunAllPendingInMessageLoop(); | |
| 29 EXPECT_TRUE(OneClickSigninBubbleView::IsShowing()); | |
| 30 | |
| 31 OneClickSigninBubbleView* view = | 31 OneClickSigninBubbleView* view = |
| 32 OneClickSigninBubbleView::view_for_testing(); | 32 OneClickSigninBubbleView::view_for_testing(); |
| 33 EXPECT_TRUE(view != NULL); | 33 EXPECT_TRUE(view != NULL); |
| 34 | |
| 35 // Simulate pressing a link in the bubble. This should open a new tab. | |
| 36 view->message_loop_for_testing_ = MessageLoop::current(); | 34 view->message_loop_for_testing_ = MessageLoop::current(); |
| 37 return view; | 35 return view; |
| 38 } | 36 } |
| 39 | 37 |
| 40 void OnStartSync(OneClickSigninSyncStarter::StartSyncMode mode) { | 38 void OnStartSync(OneClickSigninSyncStarter::StartSyncMode mode) { |
| 41 on_start_sync_called_ = true; | 39 on_start_sync_called_ = true; |
| 42 mode_ = mode; | 40 mode_ = mode; |
| 43 } | 41 } |
| 44 | 42 |
| 45 protected: | 43 protected: |
| 46 bool on_start_sync_called_; | 44 bool on_start_sync_called_; |
| 47 OneClickSigninSyncStarter::StartSyncMode mode_; | 45 OneClickSigninSyncStarter::StartSyncMode mode_; |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleViewBrowserTest); | 48 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleViewBrowserTest); |
| 51 }; | 49 }; |
| 52 | 50 |
| 53 // Disabled. See http://crbug.com/132348 | 51 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, ShowBubble) { |
| 54 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, DISABLED_Show) { | 52 ShowOneClickSigninBubble(BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE); |
| 55 ShowOneClickSigninBubble(); | |
| 56 content::RunAllPendingInMessageLoop(); | 53 content::RunAllPendingInMessageLoop(); |
| 57 EXPECT_TRUE(OneClickSigninBubbleView::IsShowing()); | 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); |
| 58 | 66 |
| 59 OneClickSigninBubbleView::Hide(); | 67 OneClickSigninBubbleView::Hide(); |
| 60 content::RunAllPendingInMessageLoop(); | 68 content::RunAllPendingInMessageLoop(); |
| 61 EXPECT_TRUE(on_start_sync_called_); | |
| 62 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | |
| 63 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | 69 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 64 } | 70 } |
| 65 | 71 |
| 66 // Disabled. See http://crbug.com/132348 | 72 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, HideDialog) { |
| 67 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, DISABLED_OkButton) { | 73 ShowOneClickSigninBubble( |
| 68 OneClickSigninBubbleView* view = 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); |
| 69 | 87 |
| 70 // Simulate pressing the OK button. Set the message loop in the bubble | 88 // Simulate pressing the OK button. Set the message loop in the bubble |
| 71 // view so that it can be quit once the bubble is hidden. | 89 // view so that it can be quit once the bubble is hidden. |
| 72 views::ButtonListener* listener = view; | 90 views::ButtonListener* listener = view; |
| 73 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, | 91 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, |
| 74 gfx::Point(), gfx::Point(), | 92 gfx::Point(), gfx::Point(), |
| 75 0); | 93 0); |
| 76 listener->ButtonPressed(view->ok_button_, event); | 94 listener->ButtonPressed(view->ok_button_, event); |
| 77 | 95 |
| 78 // View should no longer be showing. The message loop will exit once the | 96 // View should no longer be showing. The message loop will exit once the |
| 79 // fade animation of the bubble is done. | 97 // fade animation of the bubble is done. |
| 80 content::RunMessageLoop(); | 98 content::RunAllPendingInMessageLoop(); |
| 81 EXPECT_TRUE(on_start_sync_called_); | |
| 82 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | |
| 83 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | 99 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 84 } | 100 } |
| 85 | 101 |
| 86 // Disabled. See http://crbug.com/132348 | 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 |
| 87 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | 122 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, |
| 88 DISABLED_UndoButton) { | 123 DialogUndoButton) { |
| 89 OneClickSigninBubbleView* view = ShowOneClickSigninBubble(); | 124 OneClickSigninBubbleView* view = ShowOneClickSigninBubble( |
| 125 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); |
| 90 | 126 |
| 91 // Simulate pressing the undo button. Set the message loop in the bubble | 127 // Simulate pressing the undo button. Set the message loop in the bubble |
| 92 // view so that it can be quit once the bubble is hidden. | 128 // view so that it can be quit once the bubble is hidden. |
| 93 views::ButtonListener* listener = view; | 129 views::ButtonListener* listener = view; |
| 94 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, | 130 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, |
| 95 gfx::Point(), gfx::Point(), | 131 gfx::Point(), gfx::Point(), |
| 96 0); | 132 0); |
| 97 listener->ButtonPressed(view->undo_button_, event); | 133 listener->ButtonPressed(view->undo_button_, event); |
| 98 | 134 |
| 99 // View should no longer be showing. The message loop will exit once the | 135 // View should no longer be showing. The message loop will exit once the |
| 100 // fade animation of the bubble is done. | 136 // fade animation of the bubble is done. |
| 101 content::RunMessageLoop(); | 137 content::RunAllPendingInMessageLoop(); |
| 138 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 102 EXPECT_TRUE(on_start_sync_called_); | 139 EXPECT_TRUE(on_start_sync_called_); |
| 103 EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, mode_); | 140 EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, mode_); |
| 104 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 105 } | 141 } |
| 106 | 142 |
| 107 // Disabled. See http://crbug.com/132348 | |
| 108 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, |
| 109 DISABLED_AdvancedLink) { | 144 BubbleAdvancedLink) { |
| 110 OneClickSigninBubbleView* view = ShowOneClickSigninBubble(); | 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); |
| 111 | 167 |
| 112 // Simulate pressing a link in the bubble. This should open a new tab. | 168 // Simulate pressing a link in the bubble. This should open a new tab. |
| 113 views::LinkListener* listener = view; | 169 views::LinkListener* listener = view; |
| 114 listener->LinkClicked(view->advanced_link_, 0); | 170 listener->LinkClicked(view->advanced_link_, 0); |
| 115 | 171 |
| 116 // View should no longer be showing and a new tab should be opened. | 172 // View should no longer be showing and a new tab should be opened. |
| 117 content::RunMessageLoop(); | 173 content::RunAllPendingInMessageLoop(); |
| 118 EXPECT_TRUE(on_start_sync_called_); | 174 EXPECT_TRUE(on_start_sync_called_); |
| 119 EXPECT_EQ(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, mode_); | 175 EXPECT_EQ(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, mode_); |
| 120 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | 176 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 177 int tab_count = browser()->tab_strip_model()->count(); |
| 178 EXPECT_EQ(starting_tab_count, tab_count); |
| 121 } | 179 } |
| 122 | 180 |
| 123 // Disabled. See http://crbug.com/132348 | |
| 124 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | 181 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, |
| 125 DISABLED_PressEnterKey) { | 182 BubbleLearnMoreLink) { |
| 126 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble(); | 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); |
| 127 | 202 |
| 128 // Simulate pressing the Enter key. | 203 // Simulate pressing the Enter key. |
| 129 views::View* view = one_click_view; | 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; |
| 130 const ui::Accelerator accelerator(ui::VKEY_RETURN, 0); | 221 const ui::Accelerator accelerator(ui::VKEY_RETURN, 0); |
| 131 view->AcceleratorPressed(accelerator); | 222 view->AcceleratorPressed(accelerator); |
| 132 | 223 |
| 133 // View should no longer be showing. The message loop will exit once the | 224 // View should no longer be showing. The message loop will exit once the |
| 134 // fade animation of the bubble is done. | 225 // fade animation of the bubble is done. |
| 135 content::RunMessageLoop(); | 226 content::RunAllPendingInMessageLoop(); |
| 227 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 136 EXPECT_TRUE(on_start_sync_called_); | 228 EXPECT_TRUE(on_start_sync_called_); |
| 137 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | 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(); |
| 138 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | 245 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 139 } | 246 } |
| 140 | 247 |
| 141 // Disabled. See http://crbug.com/132348 | |
| 142 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, | 248 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleViewBrowserTest, |
| 143 DISABLED_PressEscapeKey) { | 249 DialogPressEscapeKey) { |
| 144 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble(); | 250 OneClickSigninBubbleView* one_click_view = ShowOneClickSigninBubble( |
| 251 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG); |
| 145 | 252 |
| 146 // Simulate pressing the Escape key. | 253 // Simulate pressing the Escape key. |
| 147 views::View* view = one_click_view; | 254 views::View* view = one_click_view; |
| 148 const ui::Accelerator accelerator(ui::VKEY_ESCAPE, 0); | 255 const ui::Accelerator accelerator(ui::VKEY_ESCAPE, 0); |
| 149 view->AcceleratorPressed(accelerator); | 256 view->AcceleratorPressed(accelerator); |
| 150 | 257 |
| 151 // View should no longer be showing. The message loop will exit once the | 258 // View should no longer be showing. The message loop will exit once the |
| 152 // fade animation of the bubble is done. | 259 // fade animation of the bubble is done. |
| 153 content::RunMessageLoop(); | 260 content::RunAllPendingInMessageLoop(); |
| 261 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); |
| 154 EXPECT_FALSE(on_start_sync_called_); | 262 EXPECT_FALSE(on_start_sync_called_); |
| 155 EXPECT_FALSE(OneClickSigninBubbleView::IsShowing()); | |
| 156 } | 263 } |
| OLD | NEW |