1 // Copyright 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_notification_controller.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
10 #include "testing/gtest_mac.h"
11 #import "ui/base/test/ui_cocoa_test_helper.h"
13 using base::ASCIIToUTF16;
17 class AutofillNotificationControllerTest : public ui::CocoaTest {
19 virtual void SetUp() {
21 InitControllerWithNotification(
22 autofill::DialogNotification(autofill::DialogNotification::NONE,
23 ASCIIToUTF16("A notification title")));
26 void InitControllerWithNotification(
27 const autofill::DialogNotification& notification) {
29 [[AutofillNotificationController alloc]
30 initWithNotification:¬ification
32 [[test_window() contentView] setSubviews:@[[controller_ view]]];
36 base::scoped_nsobject<AutofillNotificationController> controller_;
41 TEST_VIEW(AutofillNotificationControllerTest, [controller_ view])
43 TEST_F(AutofillNotificationControllerTest, Subviews) {
44 NSView* view = [controller_ view];
45 ASSERT_EQ(3U, [[view subviews] count]);
46 EXPECT_TRUE([[[view subviews] objectAtIndex:0] isKindOfClass:
48 EXPECT_TRUE([[[view subviews] objectAtIndex:1] isKindOfClass:
50 EXPECT_TRUE([[[view subviews] objectAtIndex:2] isKindOfClass:
52 EXPECT_NSEQ([controller_ textview],
53 [[view subviews] objectAtIndex:0]);
54 EXPECT_NSEQ([controller_ checkbox],
55 [[view subviews] objectAtIndex:1]);
56 EXPECT_NSEQ([controller_ tooltipView],
57 [[view subviews] objectAtIndex:2]);
59 // Just to exercise the code path.
60 [controller_ performLayout];
63 TEST_F(AutofillNotificationControllerTest, TextLabelOnly) {
64 InitControllerWithNotification(
65 autofill::DialogNotification(
66 autofill::DialogNotification::DEVELOPER_WARNING,
67 ASCIIToUTF16("A notification title")));
69 EXPECT_FALSE([[controller_ textview] isHidden]);
70 EXPECT_TRUE([[controller_ checkbox] isHidden]);
71 EXPECT_TRUE([[controller_ tooltipView] isHidden]);
74 TEST_F(AutofillNotificationControllerTest, CheckboxOnly) {
75 autofill::DialogNotification notification(
76 autofill::DialogNotification::WALLET_USAGE_CONFIRMATION,
77 ASCIIToUTF16("A notification title"));
78 ASSERT_TRUE(notification.HasCheckbox());
79 InitControllerWithNotification(notification);
81 EXPECT_TRUE([[controller_ textview] isHidden]);
82 EXPECT_FALSE([[controller_ checkbox] isHidden]);
83 EXPECT_TRUE([[controller_ tooltipView] isHidden]);
86 TEST_F(AutofillNotificationControllerTest, TextLabelAndTooltip) {
87 autofill::DialogNotification notification(
88 autofill::DialogNotification::DEVELOPER_WARNING,
89 ASCIIToUTF16("A notification title"));
90 notification.set_tooltip_text(ASCIIToUTF16("My very informative tooltip."));
91 InitControllerWithNotification(notification);
93 EXPECT_FALSE([[controller_ textview] isHidden]);
94 EXPECT_TRUE([[controller_ checkbox] isHidden]);
95 EXPECT_FALSE([[controller_ tooltipView] isHidden]);
98 TEST_F(AutofillNotificationControllerTest, CheckboxAndTooltip) {
99 autofill::DialogNotification notification(
100 autofill::DialogNotification::WALLET_USAGE_CONFIRMATION,
101 ASCIIToUTF16("A notification title"));
102 ASSERT_TRUE(notification.HasCheckbox());
103 notification.set_tooltip_text(ASCIIToUTF16("My very informative tooltip."));
104 InitControllerWithNotification(notification);
106 EXPECT_TRUE([[controller_ textview] isHidden]);
107 EXPECT_FALSE([[controller_ checkbox] isHidden]);
108 EXPECT_FALSE([[controller_ tooltipView] isHidden]);