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

Side by Side Diff: chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm

Issue 8697001: Implement confirm bubble for Mac. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "base/compiler_specific.h"
6 #include "base/memory/scoped_nsobject.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11 #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
12 #import "chrome/browser/ui/cocoa/confirm_bubble_view.h"
13 #include "chrome/browser/ui/confirm_bubble_model.h"
14 #include "grit/theme_resources.h"
15 #import "testing/gtest_mac.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #import "ui/gfx/point.h"
18
19 namespace {
20
21 // The model object used in this test. This model implements all methods and
22 // updates its status when ConfirmBubbleController calls its methods.
23 class TestConfirmBubbleModel : public ConfirmBubbleModel {
24 public:
25 TestConfirmBubbleModel();
26 virtual ~TestConfirmBubbleModel() OVERRIDE;
27 virtual string16 GetTitle() const OVERRIDE;
28 virtual string16 GetMessageText() const OVERRIDE;
29 virtual gfx::Image* GetIcon() const OVERRIDE;
30 virtual int GetButtons() const OVERRIDE;
31 virtual string16 GetButtonLabel(BubbleButton button) const OVERRIDE;
32 virtual void Accept() OVERRIDE;
33 virtual void Cancel() OVERRIDE;
34 virtual string16 GetLinkText() const OVERRIDE;
35 virtual void LinkClicked() OVERRIDE;
36
37 bool accept_clicked() const { return accept_clicked_; }
38 bool cancel_clicked() const { return cancel_clicked_; }
39 bool link_clicked() const { return link_clicked_; }
40
41 private:
42 bool accept_clicked_;
43 bool cancel_clicked_;
44 bool link_clicked_;
45 };
46
47 TestConfirmBubbleModel::TestConfirmBubbleModel() :
48 accept_clicked_(false),
49 cancel_clicked_(false),
50 link_clicked_(false) {
51 }
52
53 TestConfirmBubbleModel::~TestConfirmBubbleModel() {
54 }
55
56 string16 TestConfirmBubbleModel::GetTitle() const {
57 return ASCIIToUTF16("Test");
58 }
59
60 string16 TestConfirmBubbleModel::GetMessageText() const {
61 return ASCIIToUTF16("Test Message");
62 }
63
64 gfx::Image* TestConfirmBubbleModel::GetIcon() const {
65 return &ResourceBundle::GetSharedInstance().GetImageNamed(
66 IDR_PRODUCT_LOGO_16);
67 }
68
69 int TestConfirmBubbleModel::GetButtons() const {
70 return BUTTON_OK | BUTTON_CANCEL;
71 }
72
73 string16 TestConfirmBubbleModel::GetButtonLabel(BubbleButton button) const {
74 return button == BUTTON_OK ? ASCIIToUTF16("OK") : ASCIIToUTF16("Cancel");
75 }
76
77 void TestConfirmBubbleModel::Accept() {
78 accept_clicked_ = true;
79 }
80
81 void TestConfirmBubbleModel::Cancel() {
82 cancel_clicked_ = true;
83 }
84
85 string16 TestConfirmBubbleModel::GetLinkText() const {
86 return ASCIIToUTF16("Link");
87 }
88
89 void TestConfirmBubbleModel::LinkClicked() {
90 link_clicked_ = true;
91 }
92
93 } // namespace
94
95 class ConfirmBubbleControllerTest : public CocoaTest {
96 public:
97 ConfirmBubbleControllerTest() {
98 NSView* view = [test_window() contentView];
99 model_.reset(new TestConfirmBubbleModel);
100 gfx::Point origin(0, 0);
101 controller_ =
102 [[ConfirmBubbleController alloc] initWithParent:view
103 origin:origin.ToCGPoint()
104 model:model_.get()];
105 [view addSubview:[controller_ view]
106 positioned:NSWindowAbove
107 relativeTo:nil];
108 }
109
110 ConfirmBubbleView* GetBubbleView() const {
111 return (ConfirmBubbleView*)[controller_ view];
112 }
113
114 TestConfirmBubbleModel* model() const {
115 return model_.get();
116 }
117
118 private:
119 ConfirmBubbleController* controller_; // weak; owns self
120 scoped_ptr<TestConfirmBubbleModel> model_;
121 };
122
123 // Verify clicking a button or a link removes the ConfirmBubbleView object and
124 // calls an appropriate model method.
125 TEST_F(ConfirmBubbleControllerTest, ClickOk) {
126 NSView* view = [test_window() contentView];
127 ConfirmBubbleView* bubble_view = GetBubbleView();
128 bool contains_bubble_view = [[view subviews] containsObject:bubble_view];
129 EXPECT_TRUE(contains_bubble_view);
130
131 // Click its OK button and verify this view has been removed from the test
132 // window. Also verify TestConfirmBubbleModel::Accept() has been called.
133 [bubble_view clickOk];
134
135 contains_bubble_view = [[view subviews] containsObject:bubble_view];
136 EXPECT_FALSE(contains_bubble_view);
137 EXPECT_TRUE(model()->accept_clicked());
138 EXPECT_FALSE(model()->cancel_clicked());
139 EXPECT_FALSE(model()->link_clicked());
140 }
141
142 TEST_F(ConfirmBubbleControllerTest, ClickCancel) {
143 NSView* view = [test_window() contentView];
144 ConfirmBubbleView* bubble_view = GetBubbleView();
145 bool contains_bubble_view = [[view subviews] containsObject:bubble_view];
146 EXPECT_TRUE(contains_bubble_view);
147
148 // Click its cancel button and verify this view has been removed from the test
149 // window. Also verify TestConfirmBubbleModel::Cancel() has been called.
150 [bubble_view clickCancel];
151
152 contains_bubble_view = [[view subviews] containsObject:bubble_view];
153 EXPECT_FALSE(contains_bubble_view);
154 EXPECT_FALSE(model()->accept_clicked());
155 EXPECT_TRUE(model()->cancel_clicked());
156 EXPECT_FALSE(model()->link_clicked());
157 }
158
159 TEST_F(ConfirmBubbleControllerTest, ClickLink) {
160 NSView* view = [test_window() contentView];
161 ConfirmBubbleView* bubble_view = GetBubbleView();
162 bool contains_bubble_view = [[view subviews] containsObject:bubble_view];
163 EXPECT_TRUE(contains_bubble_view);
164
165 // Click its link and verify this view has been removed from the test window.
166 // Also verify TestConfirmBubbleModel::LinkClicked() has been called.
167 [bubble_view clickLink];
168
169 contains_bubble_view = [[view subviews] containsObject:bubble_view];
170 EXPECT_FALSE(contains_bubble_view);
171 EXPECT_FALSE(model()->accept_clicked());
172 EXPECT_FALSE(model()->cancel_clicked());
173 EXPECT_TRUE(model()->link_clicked());
174 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/confirm_bubble_controller.mm ('k') | chrome/browser/ui/cocoa/confirm_bubble_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698