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

Side by Side 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 review issues 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 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 5 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
6 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" 6 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
7 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 7 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
8 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h" 8 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
9 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h" 9 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h"
10 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" 10 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 controller_ = 43 controller_ =
44 [[WebIntentBubbleController alloc] initWithPicker:picker_.get() 44 [[WebIntentBubbleController alloc] initWithPicker:picker_.get()
45 parentWindow:test_window() 45 parentWindow:test_window()
46 anchoredAt:anchor]; 46 anchoredAt:anchor];
47 window_ = static_cast<InfoBubbleWindow*>([controller_ window]); 47 window_ = static_cast<InfoBubbleWindow*>([controller_ window]);
48 [controller_ showWindow:nil]; 48 [controller_ showWindow:nil];
49 } 49 }
50 50
51 // Checks the controller's window for the requisite subviews and icons. 51 // Checks the controller's window for the requisite subviews and icons.
52 void CheckWindow(size_t icon_count) { 52 void CheckWindow(size_t icon_count) {
53 NSArray* views = [[window_ contentView] subviews]; 53 NSArray* flip_views = [[window_ contentView] subviews];
54 54
55 // 4 subviews - Icon, Header text, NSMatrix, CWS link. 55 // Expect 1 subview - the flip view.
56 EXPECT_EQ(4U, [views count]); 56 ASSERT_EQ(1U, [flip_views count]);
57 EXPECT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSButton class]]); 57
58 EXPECT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSMatrix class]]); 58 NSArray* views = [[flip_views objectAtIndex:0] subviews];
59 EXPECT_TRUE([[views objectAtIndex:2] isKindOfClass:[NSTextField class]]); 59
60 EXPECT_TRUE([[views objectAtIndex:3] isKindOfClass:[NSImageView class]]); 60 // 3 + |icon_count| subviews - Icon, Header text, |icon_count| buttons,
61 // and a CWS link.
62 ASSERT_EQ(3U + icon_count, [views count]);
63
64 ASSERT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSTextField class]]);
65 ASSERT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSImageView class]]);
66 for(NSUInteger i = 0; i < icon_count; ++i) {
67 ASSERT_TRUE([[views objectAtIndex:2 + i] isKindOfClass:[NSButton class]]);
68 }
69 ASSERT_TRUE([[views lastObject] isKindOfClass:[NSButton class]]);
Nico 2012/02/06 22:39:38 Can you move this three down? Then you don't need
groby-ooo-7-16 2012/02/06 23:49:41 Done.
61 70
62 // Verify the Chrome Web Store button. 71 // Verify the Chrome Web Store button.
63 NSButton* button = static_cast<NSButton*>([views objectAtIndex:0]); 72 NSButton* button = static_cast<NSButton*>([views lastObject]);
64 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]); 73 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]);
65 CheckButton(button, @selector(showChromeWebStore:)); 74 CheckButton(button, @selector(showChromeWebStore:));
66 75
67 // Verify icons/buttons pointing to services. 76 // Verify buttons pointing to services.
68 NSMatrix* icon_matrix = static_cast<NSMatrix*>([views objectAtIndex:1]); 77 for(NSUInteger i = 0; i < icon_count; ++i) {
69 NSArray* cells = [icon_matrix cells]; 78 NSButton* button = [views objectAtIndex:2 + i];
70 size_t cell_count = 0; 79 CheckServiceButton(button, i);
71 for (NSButtonCell* cell in cells) {
72 // Skip not populated cells
73 if ([cell isKindOfClass:[NSImageCell class]])
74 continue;
75
76 ++cell_count;
77 CheckButton(cell, @selector(invokeService:));
78 } 80 }
79 // TODO(binji): This check needs to be disabled until the bubble controller
80 // is fixed to use the WebIntentPickerModel directly.
81 // EXPECT_EQ(icon_count, cell_count);
82 81
83 EXPECT_EQ([window_ delegate], controller_); 82 EXPECT_EQ([window_ delegate], controller_);
84 } 83 }
85 84
85 // Checks that a service button is hooked up correctly.
86 void CheckServiceButton(NSButton* button, NSUInteger service_index) {
87 CheckButton(button, @selector(invokeService:));
88 EXPECT_EQ(NSInteger(service_index), [button tag]);
89 }
86 // Checks that a button is hooked up correctly. 90 // Checks that a button is hooked up correctly.
87 void CheckButton(id button, SEL action) { 91 void CheckButton(id button, SEL action) {
88 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || 92 EXPECT_TRUE([button isKindOfClass:[NSButton class]] ||
89 [button isKindOfClass:[NSButtonCell class]]); 93 [button isKindOfClass:[NSButtonCell class]]);
90 EXPECT_EQ(action, [button action]); 94 EXPECT_EQ(action, [button action]);
91 EXPECT_EQ(controller_, [button target]); 95 EXPECT_EQ(controller_, [button target]);
92 EXPECT_TRUE([button stringValue]); 96 EXPECT_TRUE([button stringValue]);
93 } 97 }
94 98
95 WebIntentBubbleController* controller_; // Weak, owns self. 99 WebIntentBubbleController* controller_; // Weak, owns self.
96 InfoBubbleWindow* window_; // Weak, owned by controller. 100 InfoBubbleWindow* window_; // Weak, owned by controller.
97 scoped_ptr<WebIntentPickerCocoa> picker_; 101 scoped_ptr<WebIntentPickerCocoa> picker_;
98 FakeIntentPickerDelegate delegate_; 102 FakeIntentPickerDelegate delegate_;
99 }; 103 };
100 104
101 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { 105 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) {
102 CreateBubble(); 106 CreateBubble();
103 107
104 CheckWindow(/*icon_count=*/0); 108 CheckWindow(/*icon_count=*/0);
105 } 109 }
106 110
107 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { 111 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
108 CreateBubble(); 112 CreateBubble();
109 [controller_ replaceImageAtIndex:2 withImage:nil];
110 113
111 CheckWindow(/*icon_count=*/3); 114 WebIntentPickerModel model;
115 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
116 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW);
117
118 [controller_ performLayoutWithModel:&model];
119
120 CheckWindow(/*icon_count=*/2);
112 } 121 }
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