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.
5 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h"
9 #import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
12 #import "ui/gfx/test/ui_cocoa_test_helper.h"
16 class AutofillMainContainerTest : public ui::CocoaTest {
18 virtual void SetUp() {
24 container_.reset([[AutofillMainContainer alloc] initWithDelegate:
26 [[test_window() contentView] setSubviews:@[ [container_ view] ]];
30 base::scoped_nsobject<AutofillMainContainer> container_;
31 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_;
36 TEST_VIEW(AutofillMainContainerTest, [container_ view])
38 TEST_F(AutofillMainContainerTest, SubViews) {
39 bool hasButtons = false;
40 bool hasDetailsContainer = false;
41 bool hasCheckbox = false;
42 bool hasCheckboxTooltip = false;
43 bool hasNotificationContainer = false;
45 EXPECT_EQ(5U, [[[container_ view] subviews] count]);
46 for (NSView* view in [[container_ view] subviews]) {
47 NSArray* subviews = [view subviews];
48 if ([view isKindOfClass:[NSScrollView class]]) {
49 hasDetailsContainer = true;
50 } else if (view == [container_ saveInChromeTooltipForTesting]) {
51 hasCheckboxTooltip = true;
52 } else if ([subviews count] == 2) {
54 [[subviews objectAtIndex:0] isKindOfClass:[NSButton class]]);
56 [[subviews objectAtIndex:1] isKindOfClass:[NSButton class]]);
58 } else if ([view isKindOfClass:[NSButton class]] &&
59 view == [container_ saveInChromeCheckboxForTesting]) {
62 // Assume by default this is the notification area view.
63 // There is no way to easily verify that with more detail.
64 hasNotificationContainer = true;
68 EXPECT_TRUE(hasButtons);
69 EXPECT_TRUE(hasDetailsContainer);
70 EXPECT_TRUE(hasNotificationContainer);
71 EXPECT_TRUE(hasCheckbox);
72 EXPECT_TRUE(hasCheckboxTooltip);
75 // Ensure the default state of the "Save in Chrome" checkbox is controlled by
77 TEST_F(AutofillMainContainerTest, SaveDetailsDefaultsFromDelegate) {
78 using namespace testing;
79 EXPECT_CALL(delegate_, ShouldOfferToSaveInChrome()).Times(2)
80 .WillRepeatedly(Return(true));
81 EXPECT_CALL(delegate_,ShouldSaveInChrome()).Times(2)
82 .WillOnce(Return(false))
83 .WillOnce(Return(true));
86 EXPECT_FALSE([container_ saveDetailsLocally]);
89 EXPECT_TRUE([container_ saveDetailsLocally]);
92 TEST_F(AutofillMainContainerTest, SaveInChromeCheckboxVisibility) {
93 using namespace testing;
95 // Tests that the checkbox is only visible if the delegate allows it.
96 EXPECT_CALL(delegate_, ShouldOfferToSaveInChrome()).Times(2)
97 .WillOnce(Return(false))
98 .WillOnce(Return(true));
101 NSButton* checkbox = [container_ saveInChromeCheckboxForTesting];
102 NSImageView* tooltip = [container_ saveInChromeTooltipForTesting];
103 ASSERT_TRUE(checkbox);
104 ASSERT_TRUE(tooltip);
106 EXPECT_TRUE([checkbox isHidden]);
107 EXPECT_TRUE([tooltip isHidden]);
108 [container_ modelChanged];
109 EXPECT_FALSE([checkbox isHidden]);
110 EXPECT_FALSE([tooltip isHidden]);