BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / autofill_notification_controller_unittest.mm
blobaa0cdf8d4e020ec3d0c95311f78b7d554622a5c6
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/gfx/test/ui_cocoa_test_helper.h"
13 using base::ASCIIToUTF16;
15 namespace {
17 class AutofillNotificationControllerTest : public ui::CocoaTest {
18  public:
19   void SetUp() override {
20     CocoaTest::SetUp();
21     InitControllerWithNotification(
22         autofill::DialogNotification(autofill::DialogNotification::NONE,
23                                      ASCIIToUTF16("A notification title")));
24   }
26   void InitControllerWithNotification(
27       const autofill::DialogNotification& notification) {
28     controller_.reset(
29         [[AutofillNotificationController alloc]
30              initWithNotification:&notification
31                          delegate:NULL]);
32     [[test_window() contentView] setSubviews:@[[controller_ view]]];
33   }
35  protected:
36   base::scoped_nsobject<AutofillNotificationController> controller_;
39 }  // namespace
41 TEST_VIEW(AutofillNotificationControllerTest, [controller_ view])
43 TEST_F(AutofillNotificationControllerTest, Subviews) {
44   NSView* view = [controller_ view];
45   ASSERT_EQ(2U, [[view subviews] count]);
46   EXPECT_TRUE([[[view subviews] objectAtIndex:0] isKindOfClass:
47       [NSTextView class]]);
48   EXPECT_TRUE([[[view subviews] objectAtIndex:1] isKindOfClass:
49       [NSButton class]]);
50   EXPECT_NSEQ([controller_ textview],
51               [[view subviews] objectAtIndex:0]);
52   EXPECT_NSEQ([controller_ tooltipView],
53               [[view subviews] objectAtIndex:1]);
55   // Just to exercise the code path.
56   [controller_ performLayout];
59 TEST_F(AutofillNotificationControllerTest, TextLabelOnly) {
60   InitControllerWithNotification(
61       autofill::DialogNotification(
62           autofill::DialogNotification::DEVELOPER_WARNING,
63           ASCIIToUTF16("A notification title")));
65   EXPECT_FALSE([[controller_ textview] isHidden]);
66   EXPECT_TRUE([[controller_ tooltipView] isHidden]);
69 TEST_F(AutofillNotificationControllerTest, TextLabelAndTooltip) {
70   autofill::DialogNotification notification(
71           autofill::DialogNotification::DEVELOPER_WARNING,
72           ASCIIToUTF16("A notification title"));
73   notification.set_tooltip_text(ASCIIToUTF16("My very informative tooltip."));
74   InitControllerWithNotification(notification);
76   EXPECT_FALSE([[controller_ textview] isHidden]);
77   EXPECT_FALSE([[controller_ tooltipView] isHidden]);