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

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: Fixed review issues 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));
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || 110 EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
96 [button isKindOfClass:[NSButtonCell class]]); 111 [button isKindOfClass:[NSButtonCell class]]);
97 EXPECT_EQ(action, [button action]); 112 EXPECT_EQ(action, [button action]);
98 EXPECT_EQ(controller_, [button target]); 113 EXPECT_EQ(controller_, [button target]);
99 EXPECT_TRUE([button stringValue]); 114 EXPECT_TRUE([button stringValue]);
100 } 115 }
101 116
102 WebIntentBubbleController* controller_; // Weak, owns self. 117 WebIntentBubbleController* controller_; // Weak, owns self.
103 InfoBubbleWindow* window_; // Weak, owned by controller. 118 InfoBubbleWindow* window_; // Weak, owned by controller.
104 scoped_ptr<WebIntentPickerCocoa> picker_; 119 scoped_ptr<WebIntentPickerCocoa> picker_;
105 FakeIntentPickerDelegate delegate_; 120 MockIntentPickerDelegate delegate_;
106 }; 121 };
107 122
108 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { 123 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) {
109 CreateBubble(); 124 CreateBubble();
110 125
111 CheckWindow(/*icon_count=*/0); 126 CheckWindow(/*icon_count=*/0);
112 } 127 }
113 128
114 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { 129 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
115 CreateBubble(); 130 CreateBubble();
116 131
117 WebIntentPickerModel model; 132 WebIntentPickerModel model;
118 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW); 133 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
119 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW); 134 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
120 135
121 [controller_ performLayoutWithModel:&model]; 136 [controller_ performLayoutWithModel:&model];
122 137
123 CheckWindow(/*icon_count=*/2); 138 CheckWindow(/*icon_count=*/2);
124 } 139 }
140
141 TEST_F(WebIntentBubbleControllerTest, OnCancelledWillSignalClose) {
142 CreatePicker();
143
144 EXPECT_CALL(delegate_,OnCancelled());
145 EXPECT_CALL(delegate_,OnClosing());
146 picker_->OnCancelled();
147
148 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
149 }
150
151 TEST_F(WebIntentBubbleControllerTest, CloseWillClose) {
152 CreateBubble();
153
154 EXPECT_CALL(delegate_,OnCancelled());
155 EXPECT_CALL(delegate_,OnClosing());
156 picker_->Close();
157
158 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698