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

Unified Diff: chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm

Issue 9310074: Switch to using WebIntentPickerModel, and bring picker closer to mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit tests Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm
index 8da099508d36f8d1541a2ac550e83d4b6c341ba0..4cb514605daa094022859480360b8487bc09f761 100644
--- a/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm
@@ -50,39 +50,46 @@ class WebIntentBubbleControllerTest : public CocoaTest {
// Checks the controller's window for the requisite subviews and icons.
void CheckWindow(size_t icon_count) {
- NSArray* views = [[window_ contentView] subviews];
+ NSArray* flip_views = [[window_ contentView] subviews];
- // 4 subviews - Icon, Header text, NSMatrix, CWS link.
- EXPECT_EQ(4U, [views count]);
- EXPECT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSButton class]]);
- EXPECT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSMatrix class]]);
- EXPECT_TRUE([[views objectAtIndex:2] isKindOfClass:[NSTextField class]]);
- EXPECT_TRUE([[views objectAtIndex:3] isKindOfClass:[NSImageView class]]);
+ // Expect 1 subview - the flip view
Nico 2012/02/03 23:27:07 .
groby-ooo-7-16 2012/02/06 22:30:19 Done.
+ ASSERT_EQ(1U, [flip_views count]);
+
+ NSArray* views = [[flip_views objectAtIndex:0] subviews];
+
+ // 3 + |icon_count| subviews - Icon, Header text, |icon_count| buttons,
+ // and a CWS link.
+ ASSERT_EQ(3U + icon_count, [views count]);
+
+ NSUInteger cws_index = 2 + icon_count;
Nico 2012/02/03 23:27:07 You don't really use this. Maybe remove, and below
groby-ooo-7-16 2012/02/06 22:30:19 Done.
+
+ EXPECT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSTextField class]]);
+ EXPECT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSImageView class]]);
+ for(NSUInteger i = 0; i < icon_count; ++i) {
+ EXPECT_TRUE([[views objectAtIndex:2 + i] isKindOfClass:[NSButton class]]);
+ }
+ EXPECT_TRUE([[views objectAtIndex:cws_index]
+ isKindOfClass:[NSButton class]]);
// Verify the Chrome Web Store button.
- NSButton* button = static_cast<NSButton*>([views objectAtIndex:0]);
+ NSButton* button = static_cast<NSButton*>([views objectAtIndex:cws_index]);
EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]);
CheckButton(button, @selector(showChromeWebStore:));
- // Verify icons/buttons pointing to services.
- NSMatrix* icon_matrix = static_cast<NSMatrix*>([views objectAtIndex:1]);
- NSArray* cells = [icon_matrix cells];
- size_t cell_count = 0;
- for (NSButtonCell* cell in cells) {
- // Skip not populated cells
- if ([cell isKindOfClass:[NSImageCell class]])
- continue;
-
- ++cell_count;
- CheckButton(cell, @selector(invokeService:));
+ // Verify buttons pointing to services.
+ for(NSUInteger i = 0; i < icon_count; ++i) {
+ NSButton* button = [views objectAtIndex:2 + i];
+ CheckServiceButton(button, i);
Nico 2012/02/03 23:27:07 Can't you fold this loop into the previous loop?
groby-ooo-7-16 2012/02/06 22:30:19 I didn't want to fold it up since technically the
}
- // TODO(binji): This check needs to be disabled until the bubble controller
- // is fixed to use the WebIntentPickerModel directly.
- // EXPECT_EQ(icon_count, cell_count);
EXPECT_EQ([window_ delegate], controller_);
}
+ // Checks that a service button is hooked up correctly.
+ void CheckServiceButton(NSButton* button, NSUInteger service_index) {
+ CheckButton(button, @selector(invokeService:));
+ EXPECT_EQ(NSInteger(service_index), [button tag]);
+ }
// Checks that a button is hooked up correctly.
void CheckButton(id button, SEL action) {
EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
@@ -106,7 +113,12 @@ TEST_F(WebIntentBubbleControllerTest, EmptyBubble) {
TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
CreateBubble();
- [controller_ replaceImageAtIndex:2 withImage:nil];
- CheckWindow(/*icon_count=*/3);
+ WebIntentPickerModel model;
+ model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
+ model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
+
+ [controller_ performLayoutWithModel:&model];
+
+ CheckWindow(/*icon_count=*/2);
}

Powered by Google App Engine
This is Rietveld 408576698