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