OLD | NEW |
---|---|
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 Loading... | |
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 |
Nico
2012/02/03 23:27:07
.
groby-ooo-7-16
2012/02/06 22:30:19
Done.
| |
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 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.
| |
65 | |
66 EXPECT_TRUE([[views objectAtIndex:0] isKindOfClass:[NSTextField class]]); | |
67 EXPECT_TRUE([[views objectAtIndex:1] isKindOfClass:[NSImageView class]]); | |
68 for(NSUInteger i = 0; i < icon_count; ++i) { | |
69 EXPECT_TRUE([[views objectAtIndex:2 + i] isKindOfClass:[NSButton class]]); | |
70 } | |
71 EXPECT_TRUE([[views objectAtIndex:cws_index] | |
72 isKindOfClass:[NSButton class]]); | |
61 | 73 |
62 // Verify the Chrome Web Store button. | 74 // Verify the Chrome Web Store button. |
63 NSButton* button = static_cast<NSButton*>([views objectAtIndex:0]); | 75 NSButton* button = static_cast<NSButton*>([views objectAtIndex:cws_index]); |
64 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]); | 76 EXPECT_TRUE([[button cell] isKindOfClass:[HyperlinkButtonCell class]]); |
65 CheckButton(button, @selector(showChromeWebStore:)); | 77 CheckButton(button, @selector(showChromeWebStore:)); |
66 | 78 |
67 // Verify icons/buttons pointing to services. | 79 // Verify buttons pointing to services. |
68 NSMatrix* icon_matrix = static_cast<NSMatrix*>([views objectAtIndex:1]); | 80 for(NSUInteger i = 0; i < icon_count; ++i) { |
69 NSArray* cells = [icon_matrix cells]; | 81 NSButton* button = [views objectAtIndex:2 + i]; |
70 size_t cell_count = 0; | 82 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
| |
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 } | 83 } |
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 | 84 |
83 EXPECT_EQ([window_ delegate], controller_); | 85 EXPECT_EQ([window_ delegate], controller_); |
84 } | 86 } |
85 | 87 |
88 // Checks that a service button is hooked up correctly. | |
89 void CheckServiceButton(NSButton* button, NSUInteger service_index) { | |
90 CheckButton(button, @selector(invokeService:)); | |
91 EXPECT_EQ(NSInteger(service_index), [button tag]); | |
92 } | |
86 // Checks that a button is hooked up correctly. | 93 // Checks that a button is hooked up correctly. |
87 void CheckButton(id button, SEL action) { | 94 void CheckButton(id button, SEL action) { |
88 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || | 95 EXPECT_TRUE([button isKindOfClass:[NSButton class]] || |
89 [button isKindOfClass:[NSButtonCell class]]); | 96 [button isKindOfClass:[NSButtonCell class]]); |
90 EXPECT_EQ(action, [button action]); | 97 EXPECT_EQ(action, [button action]); |
91 EXPECT_EQ(controller_, [button target]); | 98 EXPECT_EQ(controller_, [button target]); |
92 EXPECT_TRUE([button stringValue]); | 99 EXPECT_TRUE([button stringValue]); |
93 } | 100 } |
94 | 101 |
95 WebIntentBubbleController* controller_; // Weak, owns self. | 102 WebIntentBubbleController* controller_; // Weak, owns self. |
96 InfoBubbleWindow* window_; // Weak, owned by controller. | 103 InfoBubbleWindow* window_; // Weak, owned by controller. |
97 scoped_ptr<WebIntentPickerCocoa> picker_; | 104 scoped_ptr<WebIntentPickerCocoa> picker_; |
98 FakeIntentPickerDelegate delegate_; | 105 FakeIntentPickerDelegate delegate_; |
99 }; | 106 }; |
100 | 107 |
101 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { | 108 TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { |
102 CreateBubble(); | 109 CreateBubble(); |
103 | 110 |
104 CheckWindow(/*icon_count=*/0); | 111 CheckWindow(/*icon_count=*/0); |
105 } | 112 } |
106 | 113 |
107 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { | 114 TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { |
108 CreateBubble(); | 115 CreateBubble(); |
109 [controller_ replaceImageAtIndex:2 withImage:nil]; | |
110 | 116 |
111 CheckWindow(/*icon_count=*/3); | 117 WebIntentPickerModel model; |
118 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW); | |
119 model.AddItem(string16(),GURL(),WebIntentPickerModel::DISPOSITION_WINDOW); | |
120 | |
121 [controller_ performLayoutWithModel:&model]; | |
122 | |
123 CheckWindow(/*icon_count=*/2); | |
112 } | 124 } |
OLD | NEW |