OLD | NEW |
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/views/sync/one_click_signin_dialog_view.h" | 5 #include "chrome/browser/ui/views/sync/one_click_signin_dialog_view.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" |
14 #include "chrome/browser/ui/sync/one_click_signin_links_delegate.h" | 15 #include "chrome/browser/ui/sync/one_click_signin_links_delegate.h" |
15 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" | 16 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" |
16 #include "components/constrained_window/constrained_window_views.h" | 17 #include "components/constrained_window/constrained_window_views.h" |
17 #include "content/public/test/test_utils.h" | |
18 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
19 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
20 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 #include "ui/views/widget/widget_observer.h" | 22 #include "ui/views/widget/widget_observer.h" |
23 #include "ui/views/window/dialog_client_view.h" | 23 #include "ui/views/window/dialog_client_view.h" |
24 | 24 |
25 class OneClickSigninDialogViewTest : public views::ViewsTestBase, | 25 class OneClickSigninDialogViewTest : public views::ViewsTestBase, |
26 public views::WidgetObserver { | 26 public views::WidgetObserver { |
27 public: | 27 public: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 // Widget to host the anchor view of the dialog. Destroys itself when closed. | 116 // Widget to host the anchor view of the dialog. Destroys itself when closed. |
117 views::Widget* anchor_widget_ = nullptr; | 117 views::Widget* anchor_widget_ = nullptr; |
118 base::RunLoop* run_loop_ = nullptr; | 118 base::RunLoop* run_loop_ = nullptr; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(OneClickSigninDialogViewTest); | 120 DISALLOW_COPY_AND_ASSIGN(OneClickSigninDialogViewTest); |
121 }; | 121 }; |
122 | 122 |
123 TEST_F(OneClickSigninDialogViewTest, ShowDialog) { | 123 TEST_F(OneClickSigninDialogViewTest, ShowDialog) { |
124 ShowOneClickSigninDialog(); | 124 ShowOneClickSigninDialog(); |
125 content::RunAllPendingInMessageLoop(); | 125 base::RunLoop().RunUntilIdle(); |
126 EXPECT_TRUE(OneClickSigninDialogView::IsShowing()); | 126 EXPECT_TRUE(OneClickSigninDialogView::IsShowing()); |
127 } | 127 } |
128 | 128 |
129 TEST_F(OneClickSigninDialogViewTest, HideDialog) { | 129 TEST_F(OneClickSigninDialogViewTest, HideDialog) { |
130 ShowOneClickSigninDialog(); | 130 ShowOneClickSigninDialog(); |
131 | 131 |
132 OneClickSigninDialogView::Hide(); | 132 OneClickSigninDialogView::Hide(); |
133 WaitForClose(); | 133 WaitForClose(); |
134 EXPECT_FALSE(OneClickSigninDialogView::IsShowing()); | 134 EXPECT_FALSE(OneClickSigninDialogView::IsShowing()); |
135 EXPECT_TRUE(on_start_sync_called_); | 135 EXPECT_TRUE(on_start_sync_called_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 TEST_F(OneClickSigninDialogViewTest, LearnMoreLink) { | 185 TEST_F(OneClickSigninDialogViewTest, LearnMoreLink) { |
186 OneClickSigninDialogView* view = ShowOneClickSigninDialog(); | 186 OneClickSigninDialogView* view = ShowOneClickSigninDialog(); |
187 | 187 |
188 views::LinkListener* listener = view; | 188 views::LinkListener* listener = view; |
189 listener->LinkClicked(view->learn_more_link_, 0); | 189 listener->LinkClicked(view->learn_more_link_, 0); |
190 | 190 |
191 // View should still be showing and the OnLearnMoreLinkClicked method | 191 // View should still be showing and the OnLearnMoreLinkClicked method |
192 // of the delegate should have been called with |is_dialog| == true. | 192 // of the delegate should have been called with |is_dialog| == true. |
193 content::RunAllPendingInMessageLoop(); | 193 base::RunLoop().RunUntilIdle(); |
194 EXPECT_TRUE(OneClickSigninDialogView::IsShowing()); | 194 EXPECT_TRUE(OneClickSigninDialogView::IsShowing()); |
195 EXPECT_EQ(1, learn_more_click_count_); | 195 EXPECT_EQ(1, learn_more_click_count_); |
196 } | 196 } |
197 | 197 |
198 TEST_F(OneClickSigninDialogViewTest, PressEnterKey) { | 198 TEST_F(OneClickSigninDialogViewTest, PressEnterKey) { |
199 OneClickSigninDialogView* one_click_view = ShowOneClickSigninDialog(); | 199 OneClickSigninDialogView* one_click_view = ShowOneClickSigninDialog(); |
200 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0); | 200 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0); |
201 one_click_view->GetWidget()->OnKeyEvent(&event); | 201 one_click_view->GetWidget()->OnKeyEvent(&event); |
202 | 202 |
203 WaitForClose(); | 203 WaitForClose(); |
204 EXPECT_FALSE(OneClickSigninDialogView::IsShowing()); | 204 EXPECT_FALSE(OneClickSigninDialogView::IsShowing()); |
205 EXPECT_TRUE(on_start_sync_called_); | 205 EXPECT_TRUE(on_start_sync_called_); |
206 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); | 206 EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, mode_); |
207 } | 207 } |
208 | 208 |
209 TEST_F(OneClickSigninDialogViewTest, PressEscapeKey) { | 209 TEST_F(OneClickSigninDialogViewTest, PressEscapeKey) { |
210 OneClickSigninDialogView* one_click_view = ShowOneClickSigninDialog(); | 210 OneClickSigninDialogView* one_click_view = ShowOneClickSigninDialog(); |
211 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0); | 211 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0); |
212 one_click_view->GetWidget()->OnKeyEvent(&event); | 212 one_click_view->GetWidget()->OnKeyEvent(&event); |
213 | 213 |
214 WaitForClose(); | 214 WaitForClose(); |
215 EXPECT_FALSE(OneClickSigninDialogView::IsShowing()); | 215 EXPECT_FALSE(OneClickSigninDialogView::IsShowing()); |
216 EXPECT_TRUE(on_start_sync_called_); | 216 EXPECT_TRUE(on_start_sync_called_); |
217 EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, mode_); | 217 EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, mode_); |
218 } | 218 } |
OLD | NEW |