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

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: 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
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 #include "base/basictypes.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" 8 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 9 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h" 10 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
11 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h" 11 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h"
12 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" 12 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
13 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
14 #include "content/browser/tab_contents/test_tab_contents.h"
15 #include "content/test/test_browser_thread.h"
13 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
14 17
15 namespace { 18 namespace {
16 19
17 class MockIntentPickerDelegate : public WebIntentPickerDelegate { 20 class MockIntentPickerDelegate : public WebIntentPickerDelegate {
18 public: 21 public:
19 virtual ~MockIntentPickerDelegate() {} 22 virtual ~MockIntentPickerDelegate() {}
20 23
21 MOCK_METHOD2(OnServiceChosen, void(size_t index, Disposition disposition)); 24 MOCK_METHOD2(OnServiceChosen, void(size_t index, Disposition disposition));
22 MOCK_METHOD1(OnInlineDispositionWebContentsCreated, 25 MOCK_METHOD1(OnInlineDispositionWebContentsCreated,
23 void(content::WebContents* web_contents)); 26 void(content::WebContents* web_contents));
24 MOCK_METHOD0(OnCancelled, void()); 27 MOCK_METHOD0(OnCancelled, void());
25 MOCK_METHOD0(OnClosing, void()); 28 MOCK_METHOD0(OnClosing, void());
26 }; 29 };
27 30
28 } // namespace 31 } // namespace
29 32
30 class WebIntentBubbleControllerTest : public CocoaTest { 33 class WebIntentBubbleControllerTest : public TabContentsWrapperTestHarness {
31 public: 34 public:
35 WebIntentBubbleControllerTest()
36 : ui_thread_(content::BrowserThread::UI, MessageLoopForUI::current()) {}
37
32 virtual ~WebIntentBubbleControllerTest() { 38 virtual ~WebIntentBubbleControllerTest() {
33 message_loop_.RunAllPending(); 39 message_loop_.RunAllPending();
34 } 40 }
41
35 virtual void TearDown() { 42 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()) { 43 if (picker_.get()) {
41 EXPECT_CALL(delegate_, OnCancelled()); 44 EXPECT_CALL(delegate_, OnCancelled());
42 EXPECT_CALL(delegate_, OnClosing()); 45 EXPECT_CALL(delegate_, OnClosing());
43 46
44 [controller_ close]; 47 [controller_ closeSheet];
45 // Closing |controller_| destroys |picker_|. 48 // Closing |controller_| destroys |picker_|.
46 ignore_result(picker_.release()); 49 ignore_result(picker_.release());
47 } 50 }
48 CocoaTest::TearDown(); 51 TabContentsWrapperTestHarness::TearDown();
49 } 52 }
50 53
51 void CreatePicker() { 54 void CreatePicker() {
52 picker_.reset(new WebIntentPickerCocoa()); 55 picker_.reset(new WebIntentPickerCocoa());
53 picker_->delegate_ = &delegate_; 56 picker_->delegate_ = &delegate_;
54 picker_->model_ = &model_; 57 picker_->model_ = &model_;
55 window_ = nil; 58 window_ = nil;
56 controller_ = nil; 59 controller_ = nil;
57 } 60 }
58 61
59 void CreateBubble() { 62 void CreateBubble() {
60 CreatePicker(); 63 Browser* browser=(Browser*)0xdeadbeef;
Nico 2012/03/03 06:13:49 Huh? If the browser object isn't needed, maybe WIP
groby-ooo-7-16 2012/03/03 23:41:49 It's needed _only_ if you invoke inline dispositio
61 NSPoint anchor=NSMakePoint(0, 0); 64 picker_.reset(new WebIntentPickerCocoa(browser, contents_wrapper(),
65 &delegate_, &model_));
Nico 2012/03/03 06:13:49 indent is off
groby-ooo-7-16 2012/03/03 23:41:49 Done.
62 66
63 controller_ = 67 controller_ =
64 [[WebIntentBubbleController alloc] initWithPicker:picker_.get() 68 [[WebIntentBubbleController alloc] initWithPicker:picker_.get()];
65 parentWindow:test_window() 69 window_ = [controller_ window];
66 anchoredAt:anchor];
67 window_ = static_cast<InfoBubbleWindow*>([controller_ window]);
68 [controller_ showWindow:nil]; 70 [controller_ showWindow:nil];
69 } 71 }
70 72
71 // Checks the controller's window for the requisite subviews and icons. 73 // Checks the controller's window for the requisite subviews and icons.
72 void CheckWindow(size_t icon_count) { 74 void CheckWindow(size_t icon_count) {
73 NSArray* flip_views = [[window_ contentView] subviews]; 75 NSArray* flip_views = [[window_ contentView] subviews];
74 76
75 // Expect 1 subview - the flip view. 77 // Expect 1 subview - the flip view.
76 ASSERT_EQ(1U, [flip_views count]); 78 ASSERT_EQ(1U, [flip_views count]);
77 79
(...skipping 13 matching lines...) Expand all
91 NSButton* button = static_cast<NSButton*>([views lastObject]); 93 NSButton* button = static_cast<NSButton*>([views lastObject]);
92 ASSERT_TRUE([button isKindOfClass:[NSButton class]]); 94 ASSERT_TRUE([button isKindOfClass:[NSButton class]]);
93 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]); 95 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]);
94 CheckButton(button, @selector(showChromeWebStore:)); 96 CheckButton(button, @selector(showChromeWebStore:));
95 97
96 // Verify buttons pointing to services. 98 // Verify buttons pointing to services.
97 for(NSUInteger i = 0; i < icon_count; ++i) { 99 for(NSUInteger i = 0; i < icon_count; ++i) {
98 NSButton* button = [views objectAtIndex:2 + i]; 100 NSButton* button = [views objectAtIndex:2 + i];
99 CheckServiceButton(button, i); 101 CheckServiceButton(button, i);
100 } 102 }
101
102 EXPECT_EQ([window_ delegate], controller_);
103 } 103 }
104 104
105 // Checks that a service button is hooked up correctly. 105 // Checks that a service button is hooked up correctly.
106 void CheckServiceButton(NSButton* button, NSUInteger service_index) { 106 void CheckServiceButton(NSButton* button, NSUInteger service_index) {
107 CheckButton(button, @selector(invokeService:)); 107 CheckButton(button, @selector(invokeService:));
108 EXPECT_EQ(NSInteger(service_index), [button tag]); 108 EXPECT_EQ(NSInteger(service_index), [button tag]);
109 } 109 }
110 // Checks that a button is hooked up correctly. 110 // Checks that a button is hooked up correctly.
111 void CheckButton(id button, SEL action) { 111 void CheckButton(id button, SEL action) {
112 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || 112 EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
113 [button isKindOfClass:[NSButtonCell class]]); 113 [button isKindOfClass:[NSButtonCell class]]);
114 EXPECT_EQ(action, [button action]); 114 EXPECT_EQ(action, [button action]);
115 EXPECT_EQ(controller_, [button target]); 115 EXPECT_EQ(controller_, [button target]);
116 EXPECT_TRUE([button stringValue]); 116 EXPECT_TRUE([button stringValue]);
117 } 117 }
118 118
119 content::TestBrowserThread ui_thread_;
119 WebIntentBubbleController* controller_; // Weak, owns self. 120 WebIntentBubbleController* controller_; // Weak, owns self.
120 InfoBubbleWindow* window_; // Weak, owned by controller. 121 NSWindow* window_; // Weak, owned by controller.
121 scoped_ptr<WebIntentPickerCocoa> picker_; 122 scoped_ptr<WebIntentPickerCocoa> picker_;
122 MockIntentPickerDelegate delegate_; 123 MockIntentPickerDelegate delegate_;
123 MessageLoopForUI message_loop_;
124 WebIntentPickerModel model_; // The model used by the picker 124 WebIntentPickerModel model_; // The model used by the picker
125 }; 125 };
126 126
127 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { 127 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) {
128 CreateBubble(); 128 CreateBubble();
129 129
130 CheckWindow(/*icon_count=*/0); 130 CheckWindow(/*icon_count=*/0);
131 } 131 }
132 132
133 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { 133 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 EXPECT_CALL(delegate_, OnServiceChosen( 172 EXPECT_CALL(delegate_, OnServiceChosen(
173 0, WebIntentPickerModel::DISPOSITION_WINDOW)); 173 0, WebIntentPickerModel::DISPOSITION_WINDOW));
174 EXPECT_CALL(delegate_, OnCancelled()).Times(0); 174 EXPECT_CALL(delegate_, OnCancelled()).Times(0);
175 EXPECT_CALL(delegate_, OnClosing()); 175 EXPECT_CALL(delegate_, OnClosing());
176 176
177 picker_->OnServiceChosen(0); 177 picker_->OnServiceChosen(0);
178 picker_->Close(); 178 picker_->Close();
179 179
180 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it. 180 ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
181 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698