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

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