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

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

Issue 801043003: Change ShowConfirmBubble() to take model by scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/strings/string16.h" 6 #include "base/strings/string16.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h" 9 #import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
10 #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h" 10 #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 class ConfirmBubbleControllerTest : public CocoaTest { 101 class ConfirmBubbleControllerTest : public CocoaTest {
102 public: 102 public:
103 ConfirmBubbleControllerTest() 103 ConfirmBubbleControllerTest()
104 : model_deleted_(false), 104 : model_deleted_(false),
105 accept_clicked_(false), 105 accept_clicked_(false),
106 cancel_clicked_(false), 106 cancel_clicked_(false),
107 link_clicked_(false) { 107 link_clicked_(false) {
108 NSView* view = [test_window() contentView]; 108 NSView* view = [test_window() contentView];
109 // This model is owned by the controller created below. 109 // This model is owned by the controller created below.
110 model_ = new TestConfirmBubbleModel(&model_deleted_, 110 model_.reset(new TestConfirmBubbleModel(&model_deleted_,
111 &accept_clicked_, 111 &accept_clicked_,
112 &cancel_clicked_, 112 &cancel_clicked_,
113 &link_clicked_); 113 &link_clicked_));
114 gfx::Point origin(0, 0); 114 gfx::Point origin(0, 0);
115 controller_ = 115 controller_ =
116 [[ConfirmBubbleController alloc] initWithParent:view 116 [[ConfirmBubbleController alloc] initWithParent:view
117 origin:origin.ToCGPoint() 117 origin:origin.ToCGPoint()
118 model:model_]; 118 model:model_.Pass()];
119 [view addSubview:[controller_ view] 119 [view addSubview:[controller_ view]
120 positioned:NSWindowAbove 120 positioned:NSWindowAbove
121 relativeTo:nil]; 121 relativeTo:nil];
122 } 122 }
123 123
124 ConfirmBubbleCocoa* GetBubble() const { 124 ConfirmBubbleCocoa* GetBubble() const {
125 return (ConfirmBubbleCocoa*)[controller_ view]; 125 return (ConfirmBubbleCocoa*)[controller_ view];
126 } 126 }
127 127
128 TestConfirmBubbleModel* model() const { return model_; }
129 bool model_deleted() const { return model_deleted_; } 128 bool model_deleted() const { return model_deleted_; }
130 bool accept_clicked() const { return accept_clicked_; } 129 bool accept_clicked() const { return accept_clicked_; }
131 bool cancel_clicked() const { return cancel_clicked_; } 130 bool cancel_clicked() const { return cancel_clicked_; }
132 bool link_clicked() const { return link_clicked_; } 131 bool link_clicked() const { return link_clicked_; }
133 132
134 private: 133 private:
135 ConfirmBubbleController* controller_; // weak; owns self 134 ConfirmBubbleController* controller_; // weak; owns self
136 TestConfirmBubbleModel* model_; // weak 135 scoped_ptr<TestConfirmBubbleModel> model_;
137 bool model_deleted_; 136 bool model_deleted_;
138 bool accept_clicked_; 137 bool accept_clicked_;
139 bool cancel_clicked_; 138 bool cancel_clicked_;
140 bool link_clicked_; 139 bool link_clicked_;
141 }; 140 };
142 141
143 // Verify clicking a button or a link removes the ConfirmBubbleCocoa object and 142 // Verify clicking a button or a link removes the ConfirmBubbleCocoa object and
144 // calls an appropriate model method. 143 // calls an appropriate model method.
145 TEST_F(ConfirmBubbleControllerTest, ClickOk) { 144 TEST_F(ConfirmBubbleControllerTest, ClickOk) {
146 NSView* view = [test_window() contentView]; 145 NSView* view = [test_window() contentView];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Click its link and verify this view has been removed from the test window. 184 // Click its link and verify this view has been removed from the test window.
186 // Also verify TestConfirmBubbleModel::LinkClicked() has been called. 185 // Also verify TestConfirmBubbleModel::LinkClicked() has been called.
187 [bubble clickLink]; 186 [bubble clickLink];
188 187
189 contains_bubble_view = [[view subviews] containsObject:bubble]; 188 contains_bubble_view = [[view subviews] containsObject:bubble];
190 EXPECT_FALSE(contains_bubble_view); 189 EXPECT_FALSE(contains_bubble_view);
191 EXPECT_FALSE(accept_clicked()); 190 EXPECT_FALSE(accept_clicked());
192 EXPECT_FALSE(cancel_clicked()); 191 EXPECT_FALSE(cancel_clicked());
193 EXPECT_TRUE(link_clicked()); 192 EXPECT_TRUE(link_clicked());
194 } 193 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/confirm_bubble_controller.mm ('k') | chrome/browser/ui/confirm_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698