OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_controller.h" | |
6 | |
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" | |
12 | |
13 using base::ASCIIToUTF16; | |
14 | |
15 namespace { | |
16 | |
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 } | |
25 | |
26 void InitControllerWithNotification( | |
27 const autofill::DialogNotification& notification) { | |
28 controller_.reset( | |
29 [[AutofillNotificationController alloc] | |
30 initWithNotification:¬ification | |
31 delegate:NULL]); | |
32 [[test_window() contentView] setSubviews:@[[controller_ view]]]; | |
33 } | |
34 | |
35 protected: | |
36 base::scoped_nsobject<AutofillNotificationController> controller_; | |
37 }; | |
38 | |
39 } // namespace | |
40 | |
41 TEST_VIEW(AutofillNotificationControllerTest, [controller_ view]) | |
42 | |
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]); | |
54 | |
55 // Just to exercise the code path. | |
56 [controller_ performLayout]; | |
57 } | |
58 | |
59 TEST_F(AutofillNotificationControllerTest, TextLabelOnly) { | |
60 InitControllerWithNotification( | |
61 autofill::DialogNotification( | |
62 autofill::DialogNotification::DEVELOPER_WARNING, | |
63 ASCIIToUTF16("A notification title"))); | |
64 | |
65 EXPECT_FALSE([[controller_ textview] isHidden]); | |
66 EXPECT_TRUE([[controller_ tooltipView] isHidden]); | |
67 } | |
68 | |
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); | |
75 | |
76 EXPECT_FALSE([[controller_ textview] isHidden]); | |
77 EXPECT_FALSE([[controller_ tooltipView] isHidden]); | |
78 } | |
OLD | NEW |