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

Side by Side Diff: chrome/browser/ui/cocoa/passwords/account_chooser_view_controller_unittest.mm

Issue 1992633003: Add "Sign In" button to the account chooser on Mac. (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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" 5 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include <Carbon/Carbon.h> 9 #include <Carbon/Carbon.h>
10 10
11 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
12 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 16 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
17 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" 17 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h"
18 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" 18 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h"
19 #import "chrome/browser/ui/cocoa/passwords/credential_item_button.h" 19 #import "chrome/browser/ui/cocoa/passwords/credential_item_button.h"
20 #include "chrome/browser/ui/passwords/password_dialog_controller.h" 20 #include "chrome/browser/ui/passwords/password_dialog_controller_mock.h"
21 #include "components/autofill/core/common/password_form.h" 21 #include "components/autofill/core/common/password_form.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "testing/gtest_mac.h" 24 #include "testing/gtest_mac.h"
25 #import "ui/events/test/cocoa_test_event_utils.h" 25 #import "ui/events/test/cocoa_test_event_utils.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 #include "url/origin.h" 27 #include "url/origin.h"
28 28
29 @interface AccountAvatarFetcherTestManager : AccountAvatarFetcherManager { 29 @interface AccountAvatarFetcherTestManager : AccountAvatarFetcherManager {
30 std::vector<GURL> fetchedAvatars_; 30 std::vector<GURL> fetchedAvatars_;
(...skipping 18 matching lines...) Expand all
49 constexpr char kDialogTitle[] = "Choose an account"; 49 constexpr char kDialogTitle[] = "Choose an account";
50 50
51 // Returns a PasswordForm with only a username. 51 // Returns a PasswordForm with only a username.
52 std::unique_ptr<autofill::PasswordForm> Credential(const char* username) { 52 std::unique_ptr<autofill::PasswordForm> Credential(const char* username) {
53 std::unique_ptr<autofill::PasswordForm> credential( 53 std::unique_ptr<autofill::PasswordForm> credential(
54 new autofill::PasswordForm); 54 new autofill::PasswordForm);
55 credential->username_value = base::ASCIIToUTF16(username); 55 credential->username_value = base::ASCIIToUTF16(username);
56 return credential; 56 return credential;
57 } 57 }
58 58
59 class PasswordDialogControllerMock : public PasswordDialogController {
60 public:
61 MOCK_CONST_METHOD0(GetLocalForms, const FormsVector&());
62 MOCK_CONST_METHOD0(GetFederationsForms, const FormsVector&());
63 MOCK_CONST_METHOD0(GetAccoutChooserTitle,
64 std::pair<base::string16, gfx::Range>());
65 MOCK_CONST_METHOD0(GetAutoSigninPromoTitle, base::string16());
66 MOCK_CONST_METHOD0(GetAutoSigninText,
67 std::pair<base::string16, gfx::Range>());
68 MOCK_METHOD0(OnSmartLockLinkClicked, void());
69 MOCK_METHOD2(OnChooseCredentials, void(
70 const autofill::PasswordForm& password_form,
71 password_manager::CredentialType credential_type));
72 MOCK_METHOD0(OnAutoSigninOK, void());
73 MOCK_METHOD0(OnAutoSigninTurnOff, void());
74 MOCK_METHOD0(OnCloseDialog, void());
75 };
76
77 // Tests for the account chooser dialog view. 59 // Tests for the account chooser dialog view.
78 class AccountChooserViewControllerTest : public CocoaTest, 60 class AccountChooserViewControllerTest : public CocoaTest,
79 public PasswordPromptBridgeInterface { 61 public PasswordPromptBridgeInterface {
80 public: 62 public:
81 void SetUp() override; 63 void SetUp() override;
82 64
83 PasswordDialogControllerMock& dialog_controller() { 65 PasswordDialogControllerMock& dialog_controller() {
84 return dialog_controller_; 66 return dialog_controller_;
85 } 67 }
86 68
(...skipping 28 matching lines...) Expand all
115 void AccountChooserViewControllerTest::SetUpAccountChooser( 97 void AccountChooserViewControllerTest::SetUpAccountChooser(
116 PasswordDialogController::FormsVector* local) { 98 PasswordDialogController::FormsVector* local) {
117 view_controller_.reset([[AccountChooserViewController alloc] 99 view_controller_.reset([[AccountChooserViewController alloc]
118 initWithBridge:this 100 initWithBridge:this
119 avatarManager:avatar_manager()]); 101 avatarManager:avatar_manager()]);
120 EXPECT_CALL(dialog_controller_, GetLocalForms()) 102 EXPECT_CALL(dialog_controller_, GetLocalForms())
121 .WillOnce(testing::ReturnRef(*local)); 103 .WillOnce(testing::ReturnRef(*local));
122 EXPECT_CALL(dialog_controller_, GetAccoutChooserTitle()) 104 EXPECT_CALL(dialog_controller_, GetAccoutChooserTitle())
123 .WillOnce(testing::Return(std::make_pair(base::ASCIIToUTF16(kDialogTitle), 105 .WillOnce(testing::Return(std::make_pair(base::ASCIIToUTF16(kDialogTitle),
124 gfx::Range(0, 5)))); 106 gfx::Range(0, 5))));
107 EXPECT_CALL(dialog_controller_, ShouldShowSignInButton())
108 .WillOnce(testing::Return(local->size() == 1));
125 [view_controller_ view]; 109 [view_controller_ view];
126 ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&dialog_controller_)); 110 ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&dialog_controller_));
127 } 111 }
128 112
129 void AccountChooserViewControllerTest::PerformClose() { 113 void AccountChooserViewControllerTest::PerformClose() {
130 view_controller_.reset(); 114 view_controller_.reset();
131 OnPerformClose(); 115 OnPerformClose();
132 } 116 }
133 117
134 PasswordDialogController* 118 PasswordDialogController*
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 198
215 TEST_F(AccountChooserViewControllerTest, ClickTitleLink) { 199 TEST_F(AccountChooserViewControllerTest, ClickTitleLink) {
216 PasswordDialogController::FormsVector local_forms; 200 PasswordDialogController::FormsVector local_forms;
217 local_forms.push_back(Credential("pizza")); 201 local_forms.push_back(Credential("pizza"));
218 SetUpAccountChooser(&local_forms); 202 SetUpAccountChooser(&local_forms);
219 EXPECT_CALL(dialog_controller(), OnSmartLockLinkClicked()); 203 EXPECT_CALL(dialog_controller(), OnSmartLockLinkClicked());
220 [view_controller().titleView clickedOnLink:@"" 204 [view_controller().titleView clickedOnLink:@""
221 atIndex:0]; 205 atIndex:0];
222 } 206 }
223 207
208 TEST_F(AccountChooserViewControllerTest, ClickSignIn) {
209 PasswordDialogController::FormsVector local_forms;
210 local_forms.push_back(Credential("pizza"));
211 SetUpAccountChooser(&local_forms);
212 EXPECT_TRUE(view_controller().signInButton);
213 EXPECT_CALL(dialog_controller(), OnSignInClicked());
214 [view_controller().signInButton performClick:nil];
215 }
216
224 TEST_F(AccountChooserViewControllerTest, ClosePromptAndHandleClick) { 217 TEST_F(AccountChooserViewControllerTest, ClosePromptAndHandleClick) {
225 // A user may press mouse down, some navigation closes the dialog, mouse up 218 // A user may press mouse down, some navigation closes the dialog, mouse up
226 // still sends the action. The view should not crash. 219 // still sends the action. The view should not crash.
227 PasswordDialogController::FormsVector local_forms; 220 PasswordDialogController::FormsVector local_forms;
228 local_forms.push_back(Credential("pizza")); 221 local_forms.push_back(Credential("pizza"));
229 SetUpAccountChooser(&local_forms); 222 SetUpAccountChooser(&local_forms);
230 [view_controller() setBridge:nil]; 223 [view_controller() setBridge:nil];
231 [view_controller().titleView clickedOnLink:@"" atIndex:0]; 224 [view_controller().titleView clickedOnLink:@"" atIndex:0];
232 [base::mac::ObjCCastStrict<CredentialItemButton>( 225 [base::mac::ObjCCastStrict<CredentialItemButton>(
233 [view_controller().credentialButtons objectAtIndex:0]) performClick:nil]; 226 [view_controller().credentialButtons objectAtIndex:0]) performClick:nil];
234 [view_controller().cancelButton performClick:nil]; 227 [view_controller().cancelButton performClick:nil];
228 EXPECT_TRUE(view_controller().signInButton);
229 [view_controller().signInButton performClick:nil];
235 } 230 }
236 231
237 TEST_F(AccountChooserViewControllerTest, CloseOnEsc) { 232 TEST_F(AccountChooserViewControllerTest, CloseOnEsc) {
238 PasswordDialogController::FormsVector local_forms; 233 PasswordDialogController::FormsVector local_forms;
239 local_forms.push_back(Credential("pizza")); 234 local_forms.push_back(Credential("pizza"));
240 SetUpAccountChooser(&local_forms); 235 SetUpAccountChooser(&local_forms);
241 EXPECT_CALL(*this, OnPerformClose()); 236 EXPECT_CALL(*this, OnPerformClose());
242 [[view_controller() view] 237 [[view_controller() view]
243 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( 238 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode(
244 kVK_Escape, '\e', NSKeyDown, 0)]; 239 kVK_Escape, '\e', NSKeyDown, 0)];
245 } 240 }
246 241
247 } // namespace 242 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698