blob: 47a8ab4c9017bceab2394bb88e479d8f96dd4ee0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
#include "base/mac/scoped_nsobject.h"
#include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"
namespace {
class AutofillMainContainerTest : public ui::CocoaTest {
public:
virtual void SetUp() {
CocoaTest::SetUp();
RebuildView();
}
void RebuildView() {
container_.reset([[AutofillMainContainer alloc] initWithDelegate:
&delegate_]);
[[test_window() contentView] setSubviews:@[ [container_ view] ]];
}
protected:
base::scoped_nsobject<AutofillMainContainer> container_;
testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_;
};
} // namespace
TEST_VIEW(AutofillMainContainerTest, [container_ view])
TEST_F(AutofillMainContainerTest, SubViews) {
bool hasButtons = false;
bool hasDetailsContainer = false;
bool hasCheckbox = false;
bool hasCheckboxTooltip = false;
bool hasNotificationContainer = false;
EXPECT_EQ(5U, [[[container_ view] subviews] count]);
for (NSView* view in [[container_ view] subviews]) {
NSArray* subviews = [view subviews];
if ([view isKindOfClass:[NSScrollView class]]) {
hasDetailsContainer = true;
} else if (view == [container_ saveInChromeTooltipForTesting]) {
hasCheckboxTooltip = true;
} else if ([subviews count] == 2) {
EXPECT_TRUE(
[[subviews objectAtIndex:0] isKindOfClass:[NSButton class]]);
EXPECT_TRUE(
[[subviews objectAtIndex:1] isKindOfClass:[NSButton class]]);
hasButtons = true;
} else if ([view isKindOfClass:[NSButton class]] &&
view == [container_ saveInChromeCheckboxForTesting]) {
hasCheckbox = true;
} else {
// Assume by default this is the notification area view.
// There is no way to easily verify that with more detail.
hasNotificationContainer = true;
}
}
EXPECT_TRUE(hasButtons);
EXPECT_TRUE(hasDetailsContainer);
EXPECT_TRUE(hasNotificationContainer);
EXPECT_TRUE(hasCheckbox);
EXPECT_TRUE(hasCheckboxTooltip);
}
// Ensure the default state of the "Save in Chrome" checkbox is controlled by
// the delegate.
TEST_F(AutofillMainContainerTest, SaveDetailsDefaultsFromDelegate) {
using namespace testing;
EXPECT_CALL(delegate_, ShouldOfferToSaveInChrome()).Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(delegate_,ShouldSaveInChrome()).Times(2)
.WillOnce(Return(false))
.WillOnce(Return(true));
RebuildView();
EXPECT_FALSE([container_ saveDetailsLocally]);
RebuildView();
EXPECT_TRUE([container_ saveDetailsLocally]);
}
TEST_F(AutofillMainContainerTest, SaveInChromeCheckboxVisibility) {
using namespace testing;
// Tests that the checkbox is only visible if the delegate allows it.
EXPECT_CALL(delegate_, ShouldOfferToSaveInChrome()).Times(2)
.WillOnce(Return(false))
.WillOnce(Return(true));
RebuildView();
NSButton* checkbox = [container_ saveInChromeCheckboxForTesting];
NSImageView* tooltip = [container_ saveInChromeTooltipForTesting];
ASSERT_TRUE(checkbox);
ASSERT_TRUE(tooltip);
EXPECT_TRUE([checkbox isHidden]);
EXPECT_TRUE([tooltip isHidden]);
[container_ modelChanged];
EXPECT_FALSE([checkbox isHidden]);
EXPECT_FALSE([tooltip isHidden]);
}
|