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

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