Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_main_container_unittest.mm

Issue 1931043002: Remove requestAutocomplete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_main_container.h"
6
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"
13
14 namespace {
15
16 class AutofillMainContainerTest : public ui::CocoaTest {
17 public:
18 virtual void SetUp() {
19 CocoaTest::SetUp();
20 RebuildView();
21 }
22
23 void RebuildView() {
24 container_.reset([[AutofillMainContainer alloc] initWithDelegate:
25 &delegate_]);
26 [[test_window() contentView] setSubviews:@[ [container_ view] ]];
27 }
28
29 protected:
30 base::scoped_nsobject<AutofillMainContainer> container_;
31 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_;
32 };
33
34 } // namespace
35
36 TEST_VIEW(AutofillMainContainerTest, [container_ view])
37
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;
44
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) {
53 EXPECT_TRUE(
54 [[subviews objectAtIndex:0] isKindOfClass:[NSButton class]]);
55 EXPECT_TRUE(
56 [[subviews objectAtIndex:1] isKindOfClass:[NSButton class]]);
57 hasButtons = true;
58 } else if ([view isKindOfClass:[NSButton class]] &&
59 view == [container_ saveInChromeCheckboxForTesting]) {
60 hasCheckbox = true;
61 } else {
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;
65 }
66 }
67
68 EXPECT_TRUE(hasButtons);
69 EXPECT_TRUE(hasDetailsContainer);
70 EXPECT_TRUE(hasNotificationContainer);
71 EXPECT_TRUE(hasCheckbox);
72 EXPECT_TRUE(hasCheckboxTooltip);
73 }
74
75 // Ensure the default state of the "Save in Chrome" checkbox is controlled by
76 // the delegate.
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));
84
85 RebuildView();
86 EXPECT_FALSE([container_ saveDetailsLocally]);
87
88 RebuildView();
89 EXPECT_TRUE([container_ saveDetailsLocally]);
90 }
91
92 TEST_F(AutofillMainContainerTest, SaveInChromeCheckboxVisibility) {
93 using namespace testing;
94
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));
99
100 RebuildView();
101 NSButton* checkbox = [container_ saveInChromeCheckboxForTesting];
102 NSImageView* tooltip = [container_ saveInChromeTooltipForTesting];
103 ASSERT_TRUE(checkbox);
104 ASSERT_TRUE(tooltip);
105
106 EXPECT_TRUE([checkbox isHidden]);
107 EXPECT_TRUE([tooltip isHidden]);
108 [container_ modelChanged];
109 EXPECT_FALSE([checkbox isHidden]);
110 EXPECT_FALSE([tooltip isHidden]);
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698