Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: chrome/browser/ui/views/passwords/password_dialog_view_browsertest.cc

Issue 1998993003: Add a test for the "Sign in" button in the account chooser on Views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 6 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 23 matching lines...) Expand all
34 net::HttpStatusCode response_code, 34 net::HttpStatusCode response_code,
35 net::URLRequestStatus::Status status) { 35 net::URLRequestStatus::Status status) {
36 OnRequestDone(url); 36 OnRequestDone(url);
37 return std::unique_ptr<net::FakeURLFetcher>( 37 return std::unique_ptr<net::FakeURLFetcher>(
38 new net::FakeURLFetcher(url, d, response_data, response_code, status)); 38 new net::FakeURLFetcher(url, d, response_data, response_code, status));
39 } 39 }
40 40
41 MOCK_METHOD1(OnRequestDone, void(const GURL&)); 41 MOCK_METHOD1(OnRequestDone, void(const GURL&));
42 }; 42 };
43 43
44 // A Widget observer class used to observe bubbles closing.
45 class BubbleCloseObserver : public views::WidgetObserver {
46 public:
47 explicit BubbleCloseObserver(views::DialogDelegateView* bubble);
48 ~BubbleCloseObserver() override;
49
50 bool widget_closed() const { return widget_ == NULL; }
vabr (Chromium) 2016/05/23 14:09:13 nit: nullptr Also on line 74.
vasilii 2016/05/23 14:15:46 Done.
51
52 private:
53 // WidgetObserver:
54 void OnWidgetClosing(views::Widget* widget) override;
55
56 views::Widget* widget_;
57
58 DISALLOW_COPY_AND_ASSIGN(BubbleCloseObserver);
59 };
60
61 BubbleCloseObserver::BubbleCloseObserver(views::DialogDelegateView* bubble)
62 : widget_(bubble->GetWidget()) {
63 widget_->AddObserver(this);
64 }
65
66 BubbleCloseObserver::~BubbleCloseObserver() {
67 if (widget_)
68 widget_->RemoveObserver(this);
69 }
70
71 void BubbleCloseObserver::OnWidgetClosing(views::Widget* widget) {
72 DCHECK_EQ(widget_, widget);
73 widget_->RemoveObserver(this);
74 widget_ = NULL;
75 }
76
44 // ManagePasswordsUIController subclass to capture the dialog instance 77 // ManagePasswordsUIController subclass to capture the dialog instance
45 class TestManagePasswordsUIController : public ManagePasswordsUIController { 78 class TestManagePasswordsUIController : public ManagePasswordsUIController {
46 public: 79 public:
47 explicit TestManagePasswordsUIController(content::WebContents* web_contents); 80 explicit TestManagePasswordsUIController(content::WebContents* web_contents);
48 81
49 void OnDialogHidden() override; 82 void OnDialogHidden() override;
50 AccountChooserPrompt* CreateAccountChooser( 83 AccountChooserPrompt* CreateAccountChooser(
51 PasswordDialogController* controller) override; 84 PasswordDialogController* controller) override;
52 AutoSigninFirstRunPrompt* CreateAutoSigninPrompt( 85 AutoSigninFirstRunPrompt* CreateAutoSigninPrompt(
53 PasswordDialogController* controller) override; 86 PasswordDialogController* controller) override;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 283
251 EXPECT_TRUE(controller()->current_account_chooser()); 284 EXPECT_TRUE(controller()->current_account_chooser());
252 AccountChooserDialogView* dialog = controller()->current_account_chooser(); 285 AccountChooserDialogView* dialog = controller()->current_account_chooser();
253 EXPECT_CALL(*this, OnChooseCredential(nullptr)); 286 EXPECT_CALL(*this, OnChooseCredential(nullptr));
254 EXPECT_CALL(*controller(), OnDialogClosed()); 287 EXPECT_CALL(*controller(), OnDialogClosed());
255 dialog->GetWidget()->Close(); 288 dialog->GetWidget()->Close();
256 EXPECT_FALSE(controller()->current_autosignin_prompt()); 289 EXPECT_FALSE(controller()->current_autosignin_prompt());
257 } 290 }
258 291
259 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, 292 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest,
293 PopupAccountChooserWithSingleCredentialClickSignIn) {
294 GURL origin("https://example.com");
295 ScopedVector<autofill::PasswordForm> local_credentials;
296 autofill::PasswordForm form;
297 form.origin = origin;
298 form.display_name = base::ASCIIToUTF16("Peter");
299 form.username_value = base::ASCIIToUTF16("peter@pan.test");
300 local_credentials.push_back(new autofill::PasswordForm(form));
301
302 SetupChooseCredentials(std::move(local_credentials),
303 ScopedVector<autofill::PasswordForm>(), origin);
304
305 EXPECT_TRUE(controller()->current_account_chooser());
306 views::DialogDelegateView* dialog = controller()->current_account_chooser();
307 BubbleCloseObserver bubble_observer(dialog);
308 EXPECT_CALL(*this, OnChooseCredential(testing::Pointee(form)));
309 dialog->Accept();
310 EXPECT_TRUE(bubble_observer.widget_closed());
311 }
312
313 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest,
260 PopupAccountChooserWithSingleCredentialReturnNonEmpty) { 314 PopupAccountChooserWithSingleCredentialReturnNonEmpty) {
261 GURL origin("https://example.com"); 315 GURL origin("https://example.com");
262 ScopedVector<autofill::PasswordForm> local_credentials; 316 ScopedVector<autofill::PasswordForm> local_credentials;
263 autofill::PasswordForm form; 317 autofill::PasswordForm form;
264 form.origin = origin; 318 form.origin = origin;
265 form.display_name = base::ASCIIToUTF16("Peter"); 319 form.display_name = base::ASCIIToUTF16("Peter");
266 form.username_value = base::ASCIIToUTF16("peter@pan.test"); 320 form.username_value = base::ASCIIToUTF16("peter@pan.test");
267 local_credentials.push_back(new autofill::PasswordForm(form)); 321 local_credentials.push_back(new autofill::PasswordForm(form));
268 322
269 SetupChooseCredentials(std::move(local_credentials), 323 SetupChooseCredentials(std::move(local_credentials),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 405
352 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, PopupAutoSigninPrompt) { 406 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, PopupAutoSigninPrompt) {
353 EXPECT_TRUE( 407 EXPECT_TRUE(
354 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( 408 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
355 browser()->profile()->GetPrefs())); 409 browser()->profile()->GetPrefs()));
356 controller()->OnPromptEnableAutoSignin(); 410 controller()->OnPromptEnableAutoSignin();
357 ASSERT_TRUE(controller()->current_autosignin_prompt()); 411 ASSERT_TRUE(controller()->current_autosignin_prompt());
358 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); 412 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState());
359 AutoSigninFirstRunDialogView* dialog = 413 AutoSigninFirstRunDialogView* dialog =
360 controller()->current_autosignin_prompt(); 414 controller()->current_autosignin_prompt();
415 BubbleCloseObserver bubble_observer(dialog);
361 ui::Accelerator esc(ui::VKEY_ESCAPE, 0); 416 ui::Accelerator esc(ui::VKEY_ESCAPE, 0);
362 EXPECT_CALL(*controller(), OnDialogClosed()); 417 EXPECT_CALL(*controller(), OnDialogClosed());
363 EXPECT_TRUE(dialog->GetWidget()->client_view()->AcceleratorPressed(esc)); 418 EXPECT_TRUE(dialog->GetWidget()->client_view()->AcceleratorPressed(esc));
419 EXPECT_TRUE(bubble_observer.widget_closed());
364 content::RunAllPendingInMessageLoop(); 420 content::RunAllPendingInMessageLoop();
365 testing::Mock::VerifyAndClearExpectations(controller()); 421 testing::Mock::VerifyAndClearExpectations(controller());
366 EXPECT_TRUE( 422 EXPECT_TRUE(
367 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( 423 password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
368 browser()->profile()->GetPrefs())); 424 browser()->profile()->GetPrefs()));
369 } 425 }
370 426
371 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest, 427 IN_PROC_BROWSER_TEST_F(PasswordDialogViewTest,
372 PopupAutoSigninPromptAfterBlockedZeroclick) { 428 PopupAutoSigninPromptAfterBlockedZeroclick) {
373 EXPECT_TRUE( 429 EXPECT_TRUE(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 password_manager::prefs::kCredentialsEnableAutosignin, true); 465 password_manager::prefs::kCredentialsEnableAutosignin, true);
410 466
411 // Successful login with the same form after block will prompt: 467 // Successful login with the same form after block will prompt:
412 blocked_form.reset(new autofill::PasswordForm(form)); 468 blocked_form.reset(new autofill::PasswordForm(form));
413 client()->NotifyUserCouldBeAutoSignedIn(std::move(blocked_form)); 469 client()->NotifyUserCouldBeAutoSignedIn(std::move(blocked_form));
414 client()->NotifySuccessfulLoginWithExistingPassword(form); 470 client()->NotifySuccessfulLoginWithExistingPassword(form);
415 ASSERT_TRUE(controller()->current_autosignin_prompt()); 471 ASSERT_TRUE(controller()->current_autosignin_prompt());
416 } 472 }
417 473
418 } // namespace 474 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698