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

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

Issue 9581041: Make web intents picker work as constrained dialog instead of InfoBubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unneeded code Created 8 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/message_loop.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
11 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h"
12 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 namespace {
16
17 class MockIntentPickerDelegate : public WebIntentPickerDelegate {
18 public:
19 virtual ~MockIntentPickerDelegate() {}
20
21 MOCK_METHOD2(OnServiceChosen, void(size_t index, Disposition disposition));
22 MOCK_METHOD1(OnInlineDispositionWebContentsCreated,
23 void(content::WebContents* web_contents));
24 MOCK_METHOD0(OnCancelled, void());
25 MOCK_METHOD0(OnClosing, void());
26 };
27
28 } // namespace
29
30 class WebIntentBubbleControllerTest : public CocoaTest {
31 public:
32 virtual ~WebIntentBubbleControllerTest() {
33 message_loop_.RunAllPending();
34 }
35 virtual void TearDown() {
36 // Do not animate out because that is hard to test around.
37 if (window_)
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 }
48 CocoaTest::TearDown();
49 }
50
51 void CreatePicker() {
52 picker_.reset(new WebIntentPickerCocoa());
53 picker_->delegate_ = &delegate_;
54 picker_->model_ = &model_;
55 window_ = nil;
56 controller_ = nil;
57 }
58
59 void CreateBubble() {
60 CreatePicker();
61 NSPoint anchor=NSMakePoint(0, 0);
62
63 controller_ =
64 [[WebIntentBubbleController alloc] initWithPicker:picker_.get()
65 parentWindow:test_window()
66 anchoredAt:anchor];
67 window_ = static_cast<InfoBubbleWindow*>([controller_ window]);
68 [controller_ showWindow:nil];
69 }
70
71 // Checks the controller's window for the requisite subviews and icons.
72 void CheckWindow(size_t icon_count) {
73 NSArray* flip_views = [[window_ contentView] subviews];
74
75 // Expect 1 subview - the flip view.
76 ASSERT_EQ(1U, [flip_views count]);
77
78 NSArray* views = [[flip_views objectAtIndex:0] subviews];
79
80 // 3 + |icon_count| subviews - Icon, Header text, |icon_count| buttons,
81 // and a CWS link.
82 ASSERT_EQ(3U + icon_count, [views count]);
83
84 ASSERT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSTextField class]]);
85 ASSERT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSImageView class]]);
86 for(NSUInteger i = 0; i < icon_count; ++i) {
87 ASSERT_TRUE([[views objectAtIndex:2 + i] isKindOfClass:[NSButton class]]);
88 }
89
90 // Verify the Chrome Web Store button.
91 NSButton* button = static_cast<NSButton*>([views lastObject]);
92 ASSERT_TRUE([button isKindOfClass:[NSButton class]]);
93 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]);
94 CheckButton(button, @selector(showChromeWebStore:));
95
96 // Verify buttons pointing to services.
97 for(NSUInteger i = 0; i < icon_count; ++i) {
98 NSButton* button = [views objectAtIndex:2 + i];
99 CheckServiceButton(button, i);
100 }
101
102 EXPECT_EQ([window_ delegate], controller_);
103 }
104
105 // Checks that a service button is hooked up correctly.
106 void CheckServiceButton(NSButton* button, NSUInteger service_index) {
107 CheckButton(button, @selector(invokeService:));
108 EXPECT_EQ(NSInteger(service_index), [button tag]);
109 }
110 // Checks that a button is hooked up correctly.
111 void CheckButton(id button, SEL action) {
112 EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
113 [button isKindOfClass:[NSButtonCell class]]);
114 EXPECT_EQ(action, [button action]);
115 EXPECT_EQ(controller_, [button target]);
116 EXPECT_TRUE([button stringValue]);
117 }
118
119 WebIntentBubbleController* controller_; // Weak, owns self.
120 InfoBubbleWindow* window_; // Weak, owned by controller.
121 scoped_ptr<WebIntentPickerCocoa> picker_;
122 MockIntentPickerDelegate delegate_;
123 MessageLoopForUI message_loop_;
124 WebIntentPickerModel model_; // The model used by the picker
125 };
126
127 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) {
128 CreateBubble();
129
130 CheckWindow(/*icon_count=*/0);
131 }
132
133 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
134 CreateBubble();
135
136 WebIntentPickerModel model;
137 model.AddInstalledService(string16(), GURL(),
138 WebIntentPickerModel::DISPOSITION_WINDOW);
139 model.AddInstalledService(string16(), GURL(),
140 WebIntentPickerModel::DISPOSITION_WINDOW);
141
142 [controller_ performLayoutWithModel:&model];
143
144 CheckWindow(/*icon_count=*/2);
145 }
146
147 TEST_F(WebIntentBubbleControllerTest, OnCancelledWillSignalClose) {
148 CreatePicker();
149
150 EXPECT_CALL(delegate_, OnCancelled());
151 EXPECT_CALL(delegate_, OnClosing());
152 picker_->OnCancelled();
153
154 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
155 }
156
157 TEST_F(WebIntentBubbleControllerTest, CloseWillClose) {
158 CreateBubble();
159
160 EXPECT_CALL(delegate_, OnCancelled());
161 EXPECT_CALL(delegate_, OnClosing());
162 picker_->Close();
163
164 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
165 }
166
167 TEST_F(WebIntentBubbleControllerTest, DontCancelAfterServiceInvokation) {
168 CreateBubble();
169 model_.AddInstalledService(string16(), GURL(),
170 WebIntentPickerModel::DISPOSITION_WINDOW);
171
172 EXPECT_CALL(delegate_, OnServiceChosen(
173 0, WebIntentPickerModel::DISPOSITION_WINDOW));
174 EXPECT_CALL(delegate_, OnCancelled()).Times(0);
175 EXPECT_CALL(delegate_, OnClosing());
176
177 picker_->OnServiceChosen(0);
178 picker_->Close();
179
180 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
181 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/web_intent_bubble_controller.mm ('k') | chrome/browser/ui/cocoa/web_intent_picker_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698