Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / passwords / manage_password_item_view_controller_unittest.mm
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.
4
5 #import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h"
6
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"
17
18 namespace {
19 static const CGFloat kArbitraryWidth = 500;
20 }  // namespace
21
22 typedef ManagePasswordsControllerTest ManagePasswordItemViewControllerTest;
23
24 TEST_F(ManagePasswordItemViewControllerTest,
25        PendingStateShouldHavePendingView) {
26   base::scoped_nsobject<ManagePasswordItemViewController> controller(
27       [[ManagePasswordItemViewController alloc]
28           initWithModel:model()
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]);
34 }
35
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);
46
47   base::scoped_nsobject<ManagePasswordItemViewController> controller(
48       [[ManagePasswordItemViewController alloc]
49           initWithModel:model()
50                position:password_manager::ui::FIRST_ITEM
51                minWidth:kArbitraryWidth]);
52   ManagePasswordItemPendingView* pendingView =
53       base::mac::ObjCCast<ManagePasswordItemPendingView>(
54           [controller contentView]);
55
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]);
60 }