Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / autofill / autofill_details_container_unittest.mm
1 // Copyright (c) 2013 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/autofill/autofill_details_container.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h"
10 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h"
13 #import "ui/gfx/test/ui_cocoa_test_helper.h"
14
15 namespace {
16
17 class AutofillDetailsContainerTest : public ui::CocoaTest {
18  public:
19   AutofillDetailsContainerTest() {
20     container_.reset([[AutofillDetailsContainer alloc] initWithDelegate:
21                          &delegate_]);
22     [[test_window() contentView] addSubview:[container_ view]];
23   }
24
25  protected:
26   base::scoped_nsobject<AutofillDetailsContainer> container_;
27   testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_;
28 };
29
30 }  // namespace
31
32 TEST_VIEW(AutofillDetailsContainerTest, [container_ view])
33
34 TEST_F(AutofillDetailsContainerTest, BasicProperties) {
35   EXPECT_TRUE([[container_ view] isKindOfClass:[NSScrollView class]]);
36   EXPECT_GT([[[container_ view] subviews] count], 0U);
37
38   [[container_ view] setFrameSize:[container_ preferredSize]];
39   EXPECT_GT(NSHeight([[container_ view] frame]), 0);
40   EXPECT_GT(NSWidth([[container_ view] frame]), 0);
41 }
42
43 TEST_F(AutofillDetailsContainerTest, ValidateAllSections) {
44   using namespace autofill;
45   using namespace testing;
46
47   ValidityMessages validity;
48
49   EXPECT_CALL(delegate_, InputsAreValid(_, _))
50       .Times(3)
51       .WillOnce(Return(validity))
52       .WillOnce(Return(validity))
53       .WillOnce(Return(validity));
54
55   EXPECT_TRUE([container_ validate]);
56
57   ValidityMessages invalid;
58   invalid.Set(ADDRESS_HOME_ZIP,
59               ValidityMessage(base::ASCIIToUTF16("Some error message"), false));
60
61   EXPECT_CALL(delegate_, InputsAreValid(_, _))
62       .Times(3)
63       .WillOnce(Return(validity))
64       .WillOnce(Return(validity))
65       .WillOnce(Return(invalid));
66
67   EXPECT_FALSE([container_ validate]);
68 }