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

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

Issue 9307086: [Web Intents, Mac] Allow re-open after cancellation/close of picker bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests Created 8 years, 10 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
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 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 5 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
6 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" 6 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
7 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 7 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
8 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h" 8 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
9 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h" 9 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h"
10 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" 10 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
11 #include "testing/gmock/include/gmock/gmock.h"
11 12
12 namespace { 13 namespace {
13 14
14 class FakeIntentPickerDelegate : public WebIntentPickerDelegate { 15 class MockIntentPickerDelegate : public WebIntentPickerDelegate {
15 public: 16 public:
16 virtual ~FakeIntentPickerDelegate() {} 17 virtual ~MockIntentPickerDelegate() {}
17 virtual void OnServiceChosen(
18 size_t index, Disposition disposition) OVERRIDE {};
19 virtual void OnInlineDispositionWebContentsCreated(
20 content::WebContents* web_contents) OVERRIDE {}
21 18
22 // Callback called when the user cancels out of the dialog. 19 MOCK_METHOD2(OnServiceChosen,void(size_t index, Disposition disposition));
23 virtual void OnCancelled() OVERRIDE {}; 20 MOCK_METHOD1(OnInlineDispositionWebContentsCreated,
24 virtual void OnClosing() OVERRIDE {}; 21 void(content::WebContents* web_contents));
22 MOCK_METHOD0(OnCancelled,void());
23 MOCK_METHOD0(OnClosing,void());
25 }; 24 };
26 25
27 } // namespace 26 } // namespace
28 27
29 class WebIntentBubbleControllerTest : public CocoaTest { 28 class WebIntentBubbleControllerTest : public CocoaTest {
30 public: 29 public:
31 virtual void TearDown() { 30 virtual void TearDown() {
32 // Do not animate out because that is hard to test around. 31 // Do not animate out because that is hard to test around.
33 [window_ setDelayOnClose:NO]; 32 if (window_)
34 [controller_ close]; 33 [window_ setDelayOnClose:NO];
34
35 if (picker_.get()) {
36 EXPECT_CALL(delegate_,OnCancelled());
37 EXPECT_CALL(delegate_,OnClosing());
38
39 [controller_ close];
40 (void)picker_.release(); // Closing |controller_| will destroy |picker_|
Robert Sesek 2012/02/03 23:26:51 nit: Comments end with a .
groby-ooo-7-16 2012/02/04 01:57:43 Done.
41 }
35 CocoaTest::TearDown(); 42 CocoaTest::TearDown();
36 } 43 }
37 44
38 void CreateBubble() { 45 void CreatePicker() {
39 picker_.reset(new WebIntentPickerCocoa()); 46 picker_.reset(new WebIntentPickerCocoa());
40 picker_->delegate_ = &delegate_; 47 picker_->delegate_ = &delegate_;
48 window_ = nil;
49 controller_ = nil;
50 }
51
52 void CreateBubble() {
53 CreatePicker();
41 NSPoint anchor=NSMakePoint(0,0); 54 NSPoint anchor=NSMakePoint(0,0);
42 55
43 controller_ = 56 controller_ =
44 [[WebIntentBubbleController alloc] initWithPicker:picker_.get() 57 [[WebIntentBubbleController alloc] initWithPicker:picker_.get()
45 parentWindow:test_window() 58 parentWindow:test_window()
46 anchoredAt:anchor]; 59 anchoredAt:anchor];
47 window_ = static_cast<InfoBubbleWindow*>([controller_ window]); 60 window_ = static_cast<InfoBubbleWindow*>([controller_ window]);
48 [controller_ showWindow:nil]; 61 [controller_ showWindow:nil];
49 } 62 }
50 63
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || 108 EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
96 [button isKindOfClass:[NSButtonCell class]]); 109 [button isKindOfClass:[NSButtonCell class]]);
97 EXPECT_EQ(action, [button action]); 110 EXPECT_EQ(action, [button action]);
98 EXPECT_EQ(controller_, [button target]); 111 EXPECT_EQ(controller_, [button target]);
99 EXPECT_TRUE([button stringValue]); 112 EXPECT_TRUE([button stringValue]);
100 } 113 }
101 114
102 WebIntentBubbleController* controller_; // Weak, owns self. 115 WebIntentBubbleController* controller_; // Weak, owns self.
103 InfoBubbleWindow* window_; // Weak, owned by controller. 116 InfoBubbleWindow* window_; // Weak, owned by controller.
104 scoped_ptr<WebIntentPickerCocoa> picker_; 117 scoped_ptr<WebIntentPickerCocoa> picker_;
105 FakeIntentPickerDelegate delegate_; 118 MockIntentPickerDelegate delegate_;
106 }; 119 };
107 120
108 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { 121 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) {
109 CreateBubble(); 122 CreateBubble();
110 123
111 CheckWindow(/*icon_count=*/0); 124 CheckWindow(/*icon_count=*/0);
112 } 125 }
113 126
114 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { 127 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
115 CreateBubble(); 128 CreateBubble();
116 129
117 WebIntentPickerModel model; 130 WebIntentPickerModel model;
118 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW); 131 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
119 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW); 132 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
120 133
121 [controller_ performLayoutWithModel:&model]; 134 [controller_ performLayoutWithModel:&model];
122 135
123 CheckWindow(/*icon_count=*/2); 136 CheckWindow(/*icon_count=*/2);
124 } 137 }
138
139 TEST_F(WebIntentBubbleControllerTest, OnCancelledWillSignalClose) {
140 CreatePicker();
141
142 EXPECT_CALL(delegate_,OnCancelled());
143 EXPECT_CALL(delegate_,OnClosing());
144 picker_->OnCancelled();
145
146 (void)picker_.release(); // Closing |picker_| will self-destruct it.
Robert Sesek 2012/02/03 23:26:51 ignore_result() in base/basictypes.h.
groby-ooo-7-16 2012/02/04 01:57:43 Done.
147 }
148
149 TEST_F(WebIntentBubbleControllerTest, CloseWillClose) {
150 CreateBubble();
151
152 EXPECT_CALL(delegate_,OnCancelled());
153 EXPECT_CALL(delegate_,OnClosing());
154 picker_->Close();
155
156 (void)picker_.release(); // Closing |picker_| will self-destruct it.
157 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/web_intent_bubble_controller.mm ('k') | chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698