1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h"
7 #include "base/mac/foundation_util.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
12 #import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h"
13 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_controller_test.h"
14 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/gtest_mac.h"
19 static const CGFloat kArbitraryWidth = 500;
22 typedef ManagePasswordsControllerTest ManagePasswordItemViewControllerTest;
24 TEST_F(ManagePasswordItemViewControllerTest,
25 PendingStateShouldHavePendingView) {
26 base::scoped_nsobject<ManagePasswordItemViewController> controller(
27 [[ManagePasswordItemViewController alloc]
29 position:password_manager::ui::FIRST_ITEM
30 minWidth:kArbitraryWidth]);
31 EXPECT_EQ(MANAGE_PASSWORD_ITEM_STATE_PENDING, [controller state]);
32 EXPECT_NSEQ([ManagePasswordItemPendingView class],
33 [[controller contentView] class]);
36 TEST_F(ManagePasswordItemViewControllerTest,
37 PendingViewShouldHaveCorrectUsernameAndObscuredPassword) {
38 // Set the pending credentials.
39 autofill::PasswordForm form;
40 NSString* const kUsername = @"foo";
41 NSString* const kPassword = @"bar";
42 form.username_value = base::SysNSStringToUTF16(kUsername);
43 form.password_value = base::SysNSStringToUTF16(kPassword);
44 ui_controller()->SetPendingCredentials(form);
45 ui_controller()->SetState(password_manager::ui::PENDING_PASSWORD_STATE);
47 base::scoped_nsobject<ManagePasswordItemViewController> controller(
48 [[ManagePasswordItemViewController alloc]
50 position:password_manager::ui::FIRST_ITEM
51 minWidth:kArbitraryWidth]);
52 ManagePasswordItemPendingView* pendingView =
53 base::mac::ObjCCast<ManagePasswordItemPendingView>(
54 [controller contentView]);
56 // Ensure the fields are populated properly and the password is obscured.
57 EXPECT_NSEQ(kUsername, pendingView.usernameField.stringValue);
58 EXPECT_NSEQ(kPassword, pendingView.passwordField.stringValue);
59 EXPECT_TRUE([[pendingView.passwordField cell] echosBullets]);