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

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

Issue 10048005: Convert OSX intent picker unit tests to PlatformTests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed review issues Created 8 years, 8 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/web_intent_sheet_controller.h"
6 #include "base/message_loop.h" 6
7 #include "base/memory/scoped_nsobject.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #import "chrome/browser/ui/cocoa/hover_close_button.h" 9 #import "chrome/browser/ui/cocoa/hover_close_button.h"
9 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" 10 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 11 #include "chrome/browser/ui/intents/web_intent_picker_model.h"
11 #import "chrome/browser/ui/cocoa/web_intent_sheet_controller.h"
12 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h"
13 #include "chrome/browser/ui/cocoa/web_intent_picker_test_base.h"
14 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
15 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
16 #include "content/test/test_browser_thread.h" 12 #include "content/test/test_browser_thread.h"
17 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/platform_test.h"
18 15
19 class WebIntentPickerSheetControllerTest 16 class WebIntentPickerSheetControllerTest : public CocoaTest {
20 : public TabContentsWrapperTestHarness,
21 public WebIntentPickerTestBase {
22 public: 17 public:
23 WebIntentPickerSheetControllerTest()
24 : ui_thread_(content::BrowserThread::UI, MessageLoopForUI::current()) {}
25 18
26 virtual ~WebIntentPickerSheetControllerTest() { 19 virtual void SetUp() {
Robert Sesek 2012/04/17 23:15:39 CocoaTest::SetUp()
groby-ooo-7-16 2012/04/25 23:19:16 Done.
27 message_loop_.RunAllPending(); 20 controller_.reset(
28 } 21 [[WebIntentPickerSheetController alloc] initWithPicker:nil]);
29 22 window_ = [controller_ window];
30 virtual void TearDown() {
31 if (picker_.get()) {
32 EXPECT_CALL(delegate_, OnCancelled());
33 EXPECT_CALL(delegate_, OnClosing());
34
35 [controller_ cancelOperation:controller_];
36 // Closing |controller_| destroys |picker_|.
37 ignore_result(picker_.release());
38 }
39 TabContentsWrapperTestHarness::TearDown();
40 }
41
42 void CreatePicker() {
43 picker_.reset(new WebIntentPickerCocoa());
44 picker_->delegate_ = &delegate_;
45 picker_->model_ = &model_;
46 window_ = nil;
47 controller_ = nil;
48 } 23 }
49 24
50 // Checks the controller's window for the requisite subviews and icons. 25 // Checks the controller's window for the requisite subviews and icons.
51 void CheckWindow(size_t icon_count) { 26 void CheckWindow(size_t row_count) {
52 NSArray* flip_views = [[window_ contentView] subviews]; 27 NSArray* flip_views = [[window_ contentView] subviews];
53 28
54 // Check for proper firstResponder. 29 // Check for proper firstResponder.
55 ASSERT_EQ(controller_, [window_ firstResponder]); 30 ASSERT_EQ(controller_.get(), [window_ firstResponder]);
56 31
57 // Expect 1 subview - the flip view. 32 // Expect 1 subview - the flip view.
58 ASSERT_EQ(1U, [flip_views count]); 33 ASSERT_EQ(1U, [flip_views count]);
59 34
60 NSArray* views = [[flip_views objectAtIndex:0] subviews]; 35 NSArray* views = [[flip_views objectAtIndex:0] subviews];
61 36
62 // 4 + |icon_count| subviews - icon, header text, close button, 37 // 4 + |row_count| subviews - icon, header text, close button,
63 // |icon_count| buttons, and a CWS link. 38 // |row_count| buttons, and a CWS link.
64 ASSERT_EQ(4U + icon_count, [views count]); 39 ASSERT_EQ(4U + row_count, [views count]);
65 40
66 ASSERT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSTextField class]]); 41 ASSERT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSTextField class]]);
67 ASSERT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSImageView class]]); 42 ASSERT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSImageView class]]);
68 ASSERT_TRUE([[views objectAtIndex:2] isKindOfClass: 43 ASSERT_TRUE([[views objectAtIndex:2] isKindOfClass:
69 [HoverCloseButton class]]); 44 [HoverCloseButton class]]);
70 for(NSUInteger i = 0; i < icon_count; ++i) { 45 for(NSUInteger i = 0; i < row_count; ++i) {
71 ASSERT_TRUE([[views objectAtIndex:3 + i] isKindOfClass: 46 ASSERT_TRUE([[views objectAtIndex:3 + i] isKindOfClass:
72 [NSButton class]]); 47 [NSButton class]]);
73 } 48 }
74 49
75 // Verify the close button 50 // Verify the close button
76 NSButton* close_button = static_cast<NSButton*>([views objectAtIndex:2]); 51 NSButton* close_button = static_cast<NSButton*>([views objectAtIndex:2]);
77 CheckButton(close_button, @selector(cancelOperation:)); 52 CheckButton(close_button, @selector(cancelOperation:));
78 53
79 // Verify the Chrome Web Store button. 54 // Verify the Chrome Web Store button.
80 NSButton* button = static_cast<NSButton*>([views lastObject]); 55 NSButton* button = static_cast<NSButton*>([views lastObject]);
81 ASSERT_TRUE([button isKindOfClass:[NSButton class]]); 56 ASSERT_TRUE([button isKindOfClass:[NSButton class]]);
82 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]); 57 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]);
83 CheckButton(button, @selector(showChromeWebStore:)); 58 CheckButton(button, @selector(showChromeWebStore:));
84 59
85 // Verify buttons pointing to services. 60 // Verify buttons pointing to services.
86 for(NSUInteger i = 0; i < icon_count; ++i) { 61 for(NSUInteger i = 0; i < row_count; ++i) {
87 NSButton* button = [views objectAtIndex:3 + i]; 62 NSButton* button = [views objectAtIndex:3 + i];
88 CheckServiceButton(button, i); 63 CheckServiceButton(button, i);
89 } 64 }
90 } 65 }
91 66
92 // Checks that a service button is hooked up correctly. 67 // Checks that a service button is hooked up correctly.
93 void CheckServiceButton(NSButton* button, NSUInteger service_index) { 68 void CheckServiceButton(NSButton* button, NSUInteger service_index) {
94 CheckButton(button, @selector(invokeService:)); 69 CheckButton(button, @selector(invokeService:));
95 EXPECT_EQ(NSInteger(service_index), [button tag]); 70 EXPECT_EQ(NSInteger(service_index), [button tag]);
96 } 71 }
97 72
98 // Checks that a button is hooked up correctly. 73 // Checks that a button is hooked up correctly.
99 void CheckButton(id button, SEL action) { 74 void CheckButton(id button, SEL action) {
100 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || 75 EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
101 [button isKindOfClass:[NSButtonCell class]]); 76 [button isKindOfClass:[NSButtonCell class]]);
102 EXPECT_EQ(action, [button action]); 77 EXPECT_EQ(action, [button action]);
103 EXPECT_EQ(controller_, [button target]); 78 EXPECT_EQ(controller_.get(), [button target]);
104 EXPECT_TRUE([button stringValue]); 79 EXPECT_TRUE([button stringValue]);
105 } 80 }
106 81
107 content::TestBrowserThread ui_thread_; 82 // Controller under test.
83 scoped_nsobject<WebIntentPickerSheetController> controller_;
Robert Sesek 2012/04/17 23:15:39 This doesn't own itself?
groby-ooo-7-16 2012/04/25 23:19:16 Usually, it does. But releasing requires properly
84
85 NSWindow* window_; // Weak, owned by |controller_|.
108 }; 86 };
109 87
110 TEST_F(WebIntentPickerSheetControllerTest, EmptyBubble) { 88 TEST_F(WebIntentPickerSheetControllerTest, NoRows) {
111 CreateBubble(contents_wrapper()); 89 CheckWindow(/*row_count=*/0);
112
113 CheckWindow(/*icon_count=*/0);
114 } 90 }
115 91
116 TEST_F(WebIntentPickerSheetControllerTest, PopulatedBubble) { 92 TEST_F(WebIntentPickerSheetControllerTest, PopulatedRows) {
117 CreateBubble(contents_wrapper());
118
119 WebIntentPickerModel model; 93 WebIntentPickerModel model;
120 model.AddInstalledService(string16(), GURL(), 94 model.AddInstalledService(string16(), GURL(),
121 WebIntentPickerModel::DISPOSITION_WINDOW); 95 WebIntentPickerModel::DISPOSITION_WINDOW);
122 model.AddInstalledService(string16(), GURL(), 96 model.AddInstalledService(string16(), GURL(),
123 WebIntentPickerModel::DISPOSITION_WINDOW); 97 WebIntentPickerModel::DISPOSITION_WINDOW);
124 98
125 [controller_ performLayoutWithModel:&model]; 99 [controller_ performLayoutWithModel:&model];
126 100
127 CheckWindow(/*icon_count=*/2); 101 CheckWindow(/*row_count=*/2);
128 }
129
130 TEST_F(WebIntentPickerSheetControllerTest, OnCancelledWillSignalClose) {
131 CreatePicker();
132
133 EXPECT_CALL(delegate_, OnCancelled());
134 EXPECT_CALL(delegate_, OnClosing());
135 picker_->OnCancelled();
136
137 ignore_result(picker_.release()); // Closing |picker_| will destruct it.
138 } 102 }
139 103
140 TEST_F(WebIntentPickerSheetControllerTest, SuggestionView) { 104 TEST_F(WebIntentPickerSheetControllerTest, SuggestionView) {
141 CreateBubble(contents_wrapper());
142
143 WebIntentPickerModel model; 105 WebIntentPickerModel model;
144 106
145 model.AddSuggestedExtension(string16(), string16(), 2.5); 107 model.AddSuggestedExtension(string16(), string16(), 2.5);
146 [controller_ performLayoutWithModel:&model]; 108 [controller_ performLayoutWithModel:&model];
147 109
148 // Get subviews. 110 // Get subviews.
149 NSArray* flip_views = [[window_ contentView] subviews]; 111 NSArray* flip_views = [[window_ contentView] subviews];
150 NSArray* main_views = [[flip_views objectAtIndex:0] subviews]; 112 NSArray* main_views = [[flip_views objectAtIndex:0] subviews];
151 113
152 // 4th object should be the suggestion view. 114 // 4th object should be the suggestion view.
(...skipping 15 matching lines...) Expand all
168 isKindOfClass:[NSButton class]]); 130 isKindOfClass:[NSButton class]]);
169 NSButton* title_button = [[item_view subviews] objectAtIndex:1]; 131 NSButton* title_button = [[item_view subviews] objectAtIndex:1];
170 CheckButton(title_button, @selector(openExtensionLink:)); 132 CheckButton(title_button, @selector(openExtensionLink:));
171 133
172 // Verify "Add to Chromium" button is hooked up properly 134 // Verify "Add to Chromium" button is hooked up properly
173 ASSERT_TRUE([[[item_view subviews] objectAtIndex:7] 135 ASSERT_TRUE([[[item_view subviews] objectAtIndex:7]
174 isKindOfClass:[NSButton class]]); 136 isKindOfClass:[NSButton class]]);
175 NSButton* add_button = [[item_view subviews] objectAtIndex:7]; 137 NSButton* add_button = [[item_view subviews] objectAtIndex:7];
176 CheckButton(add_button, @selector(installExtension:)); 138 CheckButton(add_button, @selector(installExtension:));
177 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698