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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa_controller_unittest.mm

Issue 2342723002: Reland: Update image and text color when row is selected in the chooser on Mac (Closed)
Patch Set: fixed Mac asan test Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/extensions/chooser_dialog_cocoa_controller.h" 5 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa_controller.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/chooser_controller/mock_chooser_controller.h" 13 #include "chrome/browser/chooser_controller/mock_chooser_controller.h"
14 #import "chrome/browser/ui/cocoa/chooser_content_view_cocoa.h" 14 #import "chrome/browser/ui/cocoa/chooser_content_view_cocoa.h"
15 #import "chrome/browser/ui/cocoa/cocoa_profile_test.h" 15 #import "chrome/browser/ui/cocoa/cocoa_profile_test.h"
16 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 16 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
17 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa.h" 17 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa.h"
18 #include "chrome/browser/ui/cocoa/spinner_view.h" 18 #include "chrome/browser/ui/cocoa/spinner_view.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "skia/ext/skia_utils_mac.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/gtest_mac.h" 23 #include "testing/gtest_mac.h"
23 #include "ui/base/l10n/l10n_util_mac.h" 24 #include "ui/base/l10n/l10n_util_mac.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/color_palette.h" 26 #include "ui/gfx/color_palette.h"
26 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_unittest_util.h" 28 #include "ui/gfx/image/image_unittest_util.h"
28 #include "ui/gfx/paint_vector_icon.h" 29 #include "ui/gfx/paint_vector_icon.h"
29 #include "ui/gfx/vector_icons_public.h" 30 #include "ui/gfx/vector_icons_public.h"
30 #include "ui/resources/grit/ui_resources.h" 31 #include "ui/resources/grit/ui_resources.h"
31 32
32 namespace { 33 namespace {
33 34
34 // The lookup table for signal strength level image. 35 // The lookup table for signal strength level image.
35 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, 36 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR,
36 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, 37 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR,
37 IDR_SIGNAL_4_BAR}; 38 IDR_SIGNAL_4_BAR};
39 const int kSignalStrengthLevelImageSelectedIds[5] = {
40 IDR_SIGNAL_0_BAR_SELECTED, IDR_SIGNAL_1_BAR_SELECTED,
41 IDR_SIGNAL_2_BAR_SELECTED, IDR_SIGNAL_3_BAR_SELECTED,
42 IDR_SIGNAL_4_BAR_SELECTED};
38 43
39 } // namespace 44 } // namespace
40 45
41 class ChooserDialogCocoaControllerTest : public CocoaProfileTest { 46 class ChooserDialogCocoaControllerTest : public CocoaProfileTest {
42 protected: 47 protected:
43 ChooserDialogCocoaControllerTest() 48 ChooserDialogCocoaControllerTest()
44 : rb_(ui::ResourceBundle::GetSharedInstance()) {} 49 : rb_(ui::ResourceBundle::GetSharedInstance()) {}
45 ~ChooserDialogCocoaControllerTest() override {} 50 ~ChooserDialogCocoaControllerTest() override {}
46 51
47 void SetUp() override { 52 void SetUp() override {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 help_button_ = [chooser_content_view_ helpButton]; 87 help_button_ = [chooser_content_view_ helpButton];
83 ASSERT_TRUE(help_button_); 88 ASSERT_TRUE(help_button_);
84 } 89 }
85 90
86 void ExpectNoRowImage(int row) { 91 void ExpectNoRowImage(int row) {
87 ASSERT_FALSE( 92 ASSERT_FALSE(
88 [chooser_content_view_ tableRowViewImage:static_cast<NSInteger>(row)]); 93 [chooser_content_view_ tableRowViewImage:static_cast<NSInteger>(row)]);
89 } 94 }
90 95
91 void ExpectSignalStrengthLevelImageIs(int row, 96 void ExpectSignalStrengthLevelImageIs(int row,
92 int expected_signal_strength_level) { 97 int expected_signal_strength_level,
98 int expected_color) {
93 NSImageView* image_view = 99 NSImageView* image_view =
94 [chooser_content_view_ tableRowViewImage:static_cast<NSInteger>(row)]; 100 [chooser_content_view_ tableRowViewImage:static_cast<NSInteger>(row)];
95 ASSERT_TRUE(image_view); 101 ASSERT_TRUE(image_view);
96 EXPECT_NSEQ( 102 int image_id =
97 rb_.GetNativeImageNamed( 103 expected_color == MockChooserController::kImageColorUnselected
98 kSignalStrengthLevelImageIds[expected_signal_strength_level]) 104 ? kSignalStrengthLevelImageIds[expected_signal_strength_level]
99 .ToNSImage(), 105 : kSignalStrengthLevelImageSelectedIds
100 [image_view image]); 106 [expected_signal_strength_level];
107 EXPECT_NSEQ(rb_.GetNativeImageNamed(image_id).ToNSImage(),
108 [image_view image]);
101 } 109 }
102 110
103 void ExpectRowImageIsConnectedImage(int row) { 111 void ExpectRowImageIsConnectedImage(int row, SkColor expected_color) {
104 NSImageView* image_view = 112 NSImageView* image_view =
105 [chooser_content_view_ tableRowViewImage:static_cast<NSInteger>(row)]; 113 [chooser_content_view_ tableRowViewImage:static_cast<NSInteger>(row)];
106 ASSERT_TRUE(image_view); 114 ASSERT_TRUE(image_view);
107 EXPECT_TRUE(gfx::test::AreImagesEqual( 115 EXPECT_TRUE(gfx::test::AreImagesEqual(
108 gfx::Image(gfx::CreateVectorIcon(gfx::VectorIconId::BLUETOOTH_CONNECTED, 116 gfx::Image(gfx::CreateVectorIcon(gfx::VectorIconId::BLUETOOTH_CONNECTED,
109 gfx::kChromeIconGrey)), 117 expected_color)),
110 gfx::Image([[image_view image] copy]))); 118 gfx::Image([[image_view image] copy])));
111 } 119 }
112 120
113 void ExpectRowTextIs(int row, NSString* expected_text) { 121 void ExpectRowTextIs(int row, NSString* expected_text) {
114 EXPECT_NSEQ(expected_text, 122 EXPECT_NSEQ(expected_text,
115 [[chooser_content_view_ 123 [[chooser_content_view_
116 tableRowViewText:static_cast<NSInteger>(row)] stringValue]); 124 tableRowViewText:static_cast<NSInteger>(row)] stringValue]);
117 } 125 }
118 126
127 void ExpectRowTextColorIs(int row, NSColor* expected_color) {
128 EXPECT_NSEQ(expected_color,
129 [[chooser_content_view_
130 tableRowViewText:static_cast<NSInteger>(row)] textColor]);
131 }
132
119 bool IsRowPaired(int row) { 133 bool IsRowPaired(int row) {
120 NSTextField* paired_status = [chooser_content_view_ 134 NSTextField* paired_status = [chooser_content_view_
121 tableRowViewPairedStatus:static_cast<NSInteger>(row)]; 135 tableRowViewPairedStatus:static_cast<NSInteger>(row)];
122 if (paired_status) { 136 if (paired_status) {
123 EXPECT_NSEQ(l10n_util::GetNSString(IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT), 137 EXPECT_NSEQ(l10n_util::GetNSString(IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT),
124 [paired_status stringValue]); 138 [paired_status stringValue]);
125 return true; 139 return true;
126 } else { 140 } else {
127 return false; 141 return false;
128 } 142 }
129 } 143 }
130 144
145 void ExpectPairedTextColorIs(int row, NSColor* expected_color) {
146 EXPECT_NSEQ(
147 expected_color,
148 [[chooser_content_view_
149 tableRowViewPairedStatus:static_cast<NSInteger>(row)] textColor]);
150 }
151
131 ui::ResourceBundle& rb_; 152 ui::ResourceBundle& rb_;
132 153
133 std::unique_ptr<ChooserDialogCocoa> chooser_dialog_; 154 std::unique_ptr<ChooserDialogCocoa> chooser_dialog_;
134 155
135 MockChooserController* mock_chooser_controller_; 156 MockChooserController* mock_chooser_controller_;
136 ChooserDialogCocoaController* chooser_dialog_controller_; 157 ChooserDialogCocoaController* chooser_dialog_controller_;
137 ChooserContentViewCocoa* chooser_content_view_; 158 ChooserContentViewCocoa* chooser_content_view_;
138 NSTableView* table_view_; 159 NSTableView* table_view_;
139 SpinnerView* spinner_; 160 SpinnerView* spinner_;
140 NSTextField* status_; 161 NSTextField* status_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 mock_chooser_controller_->OptionAdded( 196 mock_chooser_controller_->OptionAdded(
176 base::ASCIIToUTF16("a"), 197 base::ASCIIToUTF16("a"),
177 MockChooserController::kNoSignalStrengthLevelImage, 198 MockChooserController::kNoSignalStrengthLevelImage,
178 MockChooserController::ConnectedPairedStatus::CONNECTED | 199 MockChooserController::ConnectedPairedStatus::CONNECTED |
179 MockChooserController::ConnectedPairedStatus::PAIRED); 200 MockChooserController::ConnectedPairedStatus::PAIRED);
180 EXPECT_EQ(1, table_view_.numberOfRows); 201 EXPECT_EQ(1, table_view_.numberOfRows);
181 EXPECT_EQ(1, table_view_.numberOfColumns); 202 EXPECT_EQ(1, table_view_.numberOfColumns);
182 // |table_view_| should be enabled since there is an option. 203 // |table_view_| should be enabled since there is an option.
183 EXPECT_TRUE(table_view_.enabled); 204 EXPECT_TRUE(table_view_.enabled);
184 EXPECT_EQ(-1, table_view_.selectedRow); 205 EXPECT_EQ(-1, table_view_.selectedRow);
185 ExpectRowImageIsConnectedImage(0); 206 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
186 ExpectRowTextIs(0, @"a"); 207 ExpectRowTextIs(0, @"a");
187 EXPECT_TRUE(IsRowPaired(0)); 208 EXPECT_TRUE(IsRowPaired(0));
188 EXPECT_FALSE(connect_button_.enabled); 209 EXPECT_FALSE(connect_button_.enabled);
189 EXPECT_TRUE(cancel_button_.enabled); 210 EXPECT_TRUE(cancel_button_.enabled);
190 EXPECT_TRUE(help_button_.enabled); 211 EXPECT_TRUE(help_button_.enabled);
191 212
192 mock_chooser_controller_->OptionAdded( 213 mock_chooser_controller_->OptionAdded(
193 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar, 214 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar,
194 MockChooserController::ConnectedPairedStatus::NONE); 215 MockChooserController::ConnectedPairedStatus::NONE);
195 EXPECT_EQ(2, table_view_.numberOfRows); 216 EXPECT_EQ(2, table_view_.numberOfRows);
196 EXPECT_EQ(1, table_view_.numberOfColumns); 217 EXPECT_EQ(1, table_view_.numberOfColumns);
197 EXPECT_TRUE(table_view_.enabled); 218 EXPECT_TRUE(table_view_.enabled);
198 EXPECT_EQ(-1, table_view_.selectedRow); 219 EXPECT_EQ(-1, table_view_.selectedRow);
199 ExpectSignalStrengthLevelImageIs( 220 ExpectSignalStrengthLevelImageIs(
200 1, MockChooserController::kSignalStrengthLevel0Bar); 221 1, MockChooserController::kSignalStrengthLevel0Bar,
222 MockChooserController::kImageColorUnselected);
201 ExpectRowTextIs(1, @"b"); 223 ExpectRowTextIs(1, @"b");
202 EXPECT_FALSE(IsRowPaired(1)); 224 EXPECT_FALSE(IsRowPaired(1));
203 225
204 mock_chooser_controller_->OptionAdded( 226 mock_chooser_controller_->OptionAdded(
205 base::ASCIIToUTF16("c"), MockChooserController::kSignalStrengthLevel1Bar, 227 base::ASCIIToUTF16("c"), MockChooserController::kSignalStrengthLevel1Bar,
206 MockChooserController::ConnectedPairedStatus::NONE); 228 MockChooserController::ConnectedPairedStatus::NONE);
207 EXPECT_EQ(3, table_view_.numberOfRows); 229 EXPECT_EQ(3, table_view_.numberOfRows);
208 EXPECT_EQ(1, table_view_.numberOfColumns); 230 EXPECT_EQ(1, table_view_.numberOfColumns);
209 EXPECT_TRUE(table_view_.enabled); 231 EXPECT_TRUE(table_view_.enabled);
210 EXPECT_EQ(-1, table_view_.selectedRow); 232 EXPECT_EQ(-1, table_view_.selectedRow);
211 ExpectSignalStrengthLevelImageIs( 233 ExpectSignalStrengthLevelImageIs(
212 2, MockChooserController::kSignalStrengthLevel1Bar); 234 2, MockChooserController::kSignalStrengthLevel1Bar,
235 MockChooserController::kImageColorUnselected);
213 ExpectRowTextIs(2, @"c"); 236 ExpectRowTextIs(2, @"c");
214 EXPECT_FALSE(IsRowPaired(2)); 237 EXPECT_FALSE(IsRowPaired(2));
215 238
216 mock_chooser_controller_->OptionAdded( 239 mock_chooser_controller_->OptionAdded(
217 base::ASCIIToUTF16("d"), MockChooserController::kSignalStrengthLevel2Bar, 240 base::ASCIIToUTF16("d"), MockChooserController::kSignalStrengthLevel2Bar,
218 MockChooserController::ConnectedPairedStatus::NONE); 241 MockChooserController::ConnectedPairedStatus::NONE);
219 ExpectSignalStrengthLevelImageIs( 242 ExpectSignalStrengthLevelImageIs(
220 3, MockChooserController::kSignalStrengthLevel2Bar); 243 3, MockChooserController::kSignalStrengthLevel2Bar,
244 MockChooserController::kImageColorUnselected);
221 ExpectRowTextIs(3, @"d"); 245 ExpectRowTextIs(3, @"d");
222 EXPECT_FALSE(IsRowPaired(3)); 246 EXPECT_FALSE(IsRowPaired(3));
223 247
224 mock_chooser_controller_->OptionAdded( 248 mock_chooser_controller_->OptionAdded(
225 base::ASCIIToUTF16("e"), MockChooserController::kSignalStrengthLevel3Bar, 249 base::ASCIIToUTF16("e"), MockChooserController::kSignalStrengthLevel3Bar,
226 MockChooserController::ConnectedPairedStatus::NONE); 250 MockChooserController::ConnectedPairedStatus::NONE);
227 ExpectSignalStrengthLevelImageIs( 251 ExpectSignalStrengthLevelImageIs(
228 4, MockChooserController::kSignalStrengthLevel3Bar); 252 4, MockChooserController::kSignalStrengthLevel3Bar,
253 MockChooserController::kImageColorUnselected);
229 ExpectRowTextIs(4, @"e"); 254 ExpectRowTextIs(4, @"e");
230 EXPECT_FALSE(IsRowPaired(4)); 255 EXPECT_FALSE(IsRowPaired(4));
231 256
232 mock_chooser_controller_->OptionAdded( 257 mock_chooser_controller_->OptionAdded(
233 base::ASCIIToUTF16("f"), MockChooserController::kSignalStrengthLevel4Bar, 258 base::ASCIIToUTF16("f"), MockChooserController::kSignalStrengthLevel4Bar,
234 MockChooserController::ConnectedPairedStatus::NONE); 259 MockChooserController::ConnectedPairedStatus::NONE);
235 ExpectSignalStrengthLevelImageIs( 260 ExpectSignalStrengthLevelImageIs(
236 5, MockChooserController::kSignalStrengthLevel4Bar); 261 5, MockChooserController::kSignalStrengthLevel4Bar,
262 MockChooserController::kImageColorUnselected);
237 ExpectRowTextIs(5, @"f"); 263 ExpectRowTextIs(5, @"f");
238 EXPECT_FALSE(IsRowPaired(5)); 264 EXPECT_FALSE(IsRowPaired(5));
239 } 265 }
240 266
241 TEST_F(ChooserDialogCocoaControllerTest, RemoveOption) { 267 TEST_F(ChooserDialogCocoaControllerTest, RemoveOption) {
242 CreateChooserDialog(); 268 CreateChooserDialog();
243 269
244 mock_chooser_controller_->OptionAdded( 270 mock_chooser_controller_->OptionAdded(
245 base::ASCIIToUTF16("a"), 271 base::ASCIIToUTF16("a"),
246 MockChooserController::kNoSignalStrengthLevelImage, 272 MockChooserController::kNoSignalStrengthLevelImage,
247 MockChooserController::ConnectedPairedStatus::CONNECTED | 273 MockChooserController::ConnectedPairedStatus::CONNECTED |
248 MockChooserController::ConnectedPairedStatus::PAIRED); 274 MockChooserController::ConnectedPairedStatus::PAIRED);
249 mock_chooser_controller_->OptionAdded( 275 mock_chooser_controller_->OptionAdded(
250 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar, 276 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar,
251 MockChooserController::ConnectedPairedStatus::NONE); 277 MockChooserController::ConnectedPairedStatus::NONE);
252 mock_chooser_controller_->OptionAdded( 278 mock_chooser_controller_->OptionAdded(
253 base::ASCIIToUTF16("c"), MockChooserController::kSignalStrengthLevel1Bar, 279 base::ASCIIToUTF16("c"), MockChooserController::kSignalStrengthLevel1Bar,
254 MockChooserController::ConnectedPairedStatus::NONE); 280 MockChooserController::ConnectedPairedStatus::NONE);
255 281
256 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("b")); 282 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("b"));
257 EXPECT_EQ(2, table_view_.numberOfRows); 283 EXPECT_EQ(2, table_view_.numberOfRows);
258 EXPECT_EQ(1, table_view_.numberOfColumns); 284 EXPECT_EQ(1, table_view_.numberOfColumns);
259 EXPECT_TRUE(table_view_.enabled); 285 EXPECT_TRUE(table_view_.enabled);
260 EXPECT_EQ(-1, table_view_.selectedRow); 286 EXPECT_EQ(-1, table_view_.selectedRow);
261 ExpectRowImageIsConnectedImage(0); 287 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
262 ExpectRowTextIs(0, @"a"); 288 ExpectRowTextIs(0, @"a");
263 EXPECT_TRUE(IsRowPaired(0)); 289 EXPECT_TRUE(IsRowPaired(0));
264 ExpectSignalStrengthLevelImageIs( 290 ExpectSignalStrengthLevelImageIs(
265 1, MockChooserController::kSignalStrengthLevel1Bar); 291 1, MockChooserController::kSignalStrengthLevel1Bar,
292 MockChooserController::kImageColorUnselected);
266 ExpectRowTextIs(1, @"c"); 293 ExpectRowTextIs(1, @"c");
267 EXPECT_FALSE(IsRowPaired(1)); 294 EXPECT_FALSE(IsRowPaired(1));
268 295
269 // Remove a non-existent option, the number of rows should not change. 296 // Remove a non-existent option, the number of rows should not change.
270 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("non-existent")); 297 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("non-existent"));
271 EXPECT_EQ(2, table_view_.numberOfRows); 298 EXPECT_EQ(2, table_view_.numberOfRows);
272 EXPECT_EQ(1, table_view_.numberOfColumns); 299 EXPECT_EQ(1, table_view_.numberOfColumns);
273 EXPECT_TRUE(table_view_.enabled); 300 EXPECT_TRUE(table_view_.enabled);
274 EXPECT_EQ(-1, table_view_.selectedRow); 301 EXPECT_EQ(-1, table_view_.selectedRow);
275 ExpectRowTextIs(0, @"a"); 302 ExpectRowTextIs(0, @"a");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 mock_chooser_controller_->OptionUpdated( 341 mock_chooser_controller_->OptionUpdated(
315 base::ASCIIToUTF16("b"), base::ASCIIToUTF16("d"), 342 base::ASCIIToUTF16("b"), base::ASCIIToUTF16("d"),
316 MockChooserController::kNoSignalStrengthLevelImage, 343 MockChooserController::kNoSignalStrengthLevelImage,
317 MockChooserController::ConnectedPairedStatus::CONNECTED | 344 MockChooserController::ConnectedPairedStatus::CONNECTED |
318 MockChooserController::ConnectedPairedStatus::PAIRED); 345 MockChooserController::ConnectedPairedStatus::PAIRED);
319 346
320 EXPECT_EQ(3, table_view_.numberOfRows); 347 EXPECT_EQ(3, table_view_.numberOfRows);
321 EXPECT_EQ(1, table_view_.numberOfColumns); 348 EXPECT_EQ(1, table_view_.numberOfColumns);
322 EXPECT_TRUE(table_view_.enabled); 349 EXPECT_TRUE(table_view_.enabled);
323 EXPECT_EQ(-1, table_view_.selectedRow); 350 EXPECT_EQ(-1, table_view_.selectedRow);
324 ExpectRowImageIsConnectedImage(0); 351 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
325 ExpectRowTextIs(0, @"a"); 352 ExpectRowTextIs(0, @"a");
326 EXPECT_TRUE(IsRowPaired(0)); 353 EXPECT_TRUE(IsRowPaired(0));
327 ExpectRowImageIsConnectedImage(1); 354 ExpectRowImageIsConnectedImage(1, gfx::kChromeIconGrey);
328 ExpectRowTextIs(1, @"d"); 355 ExpectRowTextIs(1, @"d");
329 EXPECT_TRUE(IsRowPaired(1)); 356 EXPECT_TRUE(IsRowPaired(1));
330 ExpectSignalStrengthLevelImageIs( 357 ExpectSignalStrengthLevelImageIs(
331 2, MockChooserController::kSignalStrengthLevel1Bar); 358 2, MockChooserController::kSignalStrengthLevel1Bar,
359 MockChooserController::kImageColorUnselected);
332 ExpectRowTextIs(2, @"c"); 360 ExpectRowTextIs(2, @"c");
333 EXPECT_FALSE(IsRowPaired(2)); 361 EXPECT_FALSE(IsRowPaired(2));
334 } 362 }
335 363
336 TEST_F(ChooserDialogCocoaControllerTest, AddAndRemoveOption) { 364 TEST_F(ChooserDialogCocoaControllerTest, AddAndRemoveOption) {
337 CreateChooserDialog(); 365 CreateChooserDialog();
338 366
339 mock_chooser_controller_->OptionAdded( 367 mock_chooser_controller_->OptionAdded(
340 base::ASCIIToUTF16("a"), 368 base::ASCIIToUTF16("a"),
341 MockChooserController::kNoSignalStrengthLevelImage, 369 MockChooserController::kNoSignalStrengthLevelImage,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 MockChooserController::kNoSignalStrengthLevelImage, 410 MockChooserController::kNoSignalStrengthLevelImage,
383 MockChooserController::ConnectedPairedStatus::CONNECTED | 411 MockChooserController::ConnectedPairedStatus::CONNECTED |
384 MockChooserController::ConnectedPairedStatus::PAIRED); 412 MockChooserController::ConnectedPairedStatus::PAIRED);
385 413
386 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("d")); 414 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("d"));
387 415
388 EXPECT_EQ(2, table_view_.numberOfRows); 416 EXPECT_EQ(2, table_view_.numberOfRows);
389 EXPECT_EQ(1, table_view_.numberOfColumns); 417 EXPECT_EQ(1, table_view_.numberOfColumns);
390 EXPECT_TRUE(table_view_.enabled); 418 EXPECT_TRUE(table_view_.enabled);
391 EXPECT_EQ(-1, table_view_.selectedRow); 419 EXPECT_EQ(-1, table_view_.selectedRow);
392 ExpectRowImageIsConnectedImage(0); 420 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
393 ExpectRowTextIs(0, @"a"); 421 ExpectRowTextIs(0, @"a");
394 EXPECT_TRUE(IsRowPaired(0)); 422 EXPECT_TRUE(IsRowPaired(0));
395 ExpectSignalStrengthLevelImageIs( 423 ExpectSignalStrengthLevelImageIs(
396 1, MockChooserController::kSignalStrengthLevel1Bar); 424 1, MockChooserController::kSignalStrengthLevel1Bar,
425 MockChooserController::kImageColorUnselected);
397 ExpectRowTextIs(1, @"c"); 426 ExpectRowTextIs(1, @"c");
398 EXPECT_FALSE(IsRowPaired(1)); 427 EXPECT_FALSE(IsRowPaired(1));
399 } 428 }
400 429
430 TEST_F(ChooserDialogCocoaControllerTest,
431 RowImageAndTextChangeColorWhenSelectionChanges) {
432 CreateChooserDialog();
433
434 mock_chooser_controller_->OptionAdded(
435 base::ASCIIToUTF16("a"),
436 MockChooserController::kNoSignalStrengthLevelImage,
437 MockChooserController::ConnectedPairedStatus::CONNECTED |
438 MockChooserController::ConnectedPairedStatus::PAIRED);
439 mock_chooser_controller_->OptionAdded(
440 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar,
441 MockChooserController::ConnectedPairedStatus::NONE);
442 mock_chooser_controller_->OptionAdded(
443 base::ASCIIToUTF16("c"), MockChooserController::kSignalStrengthLevel1Bar,
444 MockChooserController::ConnectedPairedStatus::NONE);
445
446 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
447 ExpectSignalStrengthLevelImageIs(
448 1, MockChooserController::kSignalStrengthLevel0Bar,
449 MockChooserController::kImageColorUnselected);
450 ExpectSignalStrengthLevelImageIs(
451 2, MockChooserController::kSignalStrengthLevel1Bar,
452 MockChooserController::kImageColorUnselected);
453 ExpectRowTextColorIs(0, [NSColor blackColor]);
454 ExpectRowTextColorIs(1, [NSColor blackColor]);
455 ExpectRowTextColorIs(2, [NSColor blackColor]);
456 ExpectPairedTextColorIs(
457 0, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700));
458
459 // Option 0 shows a Bluetooth connected image, the following code tests the
460 // color of that image and text change when the option is selected or
461 // deselected.
462 // Select option 0.
463 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0]
464 byExtendingSelection:NO];
465 EXPECT_EQ(0, table_view_.selectedRow);
466 ExpectRowImageIsConnectedImage(0, SK_ColorWHITE);
467 ExpectSignalStrengthLevelImageIs(
468 1, MockChooserController::kSignalStrengthLevel0Bar,
469 MockChooserController::kImageColorUnselected);
470 ExpectSignalStrengthLevelImageIs(
471 2, MockChooserController::kSignalStrengthLevel1Bar,
472 MockChooserController::kImageColorUnselected);
473 ExpectRowTextColorIs(0, [NSColor whiteColor]);
474 ExpectRowTextColorIs(1, [NSColor blackColor]);
475 ExpectRowTextColorIs(2, [NSColor blackColor]);
476 ExpectPairedTextColorIs(
477 0, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen300));
478
479 // Deselect option 0.
480 [table_view_ deselectRow:0];
481 EXPECT_EQ(-1, table_view_.selectedRow);
482 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
483 ExpectSignalStrengthLevelImageIs(
484 1, MockChooserController::kSignalStrengthLevel0Bar,
485 MockChooserController::kImageColorUnselected);
486 ExpectSignalStrengthLevelImageIs(
487 2, MockChooserController::kSignalStrengthLevel1Bar,
488 MockChooserController::kImageColorUnselected);
489 ExpectRowTextColorIs(0, [NSColor blackColor]);
490 ExpectRowTextColorIs(1, [NSColor blackColor]);
491 ExpectRowTextColorIs(2, [NSColor blackColor]);
492 ExpectPairedTextColorIs(
493 0, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700));
494
495 // Option 1 shows a signal strengh level image, the following code tests the
496 // color of that image and text change when the option is selected or
497 // deselected.
498 // Select option 1.
499 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:1]
500 byExtendingSelection:NO];
501 EXPECT_EQ(1, table_view_.selectedRow);
502 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
503 ExpectSignalStrengthLevelImageIs(
504 1, MockChooserController::kSignalStrengthLevel0Bar,
505 MockChooserController::kImageColorSelected);
506 ExpectSignalStrengthLevelImageIs(
507 2, MockChooserController::kSignalStrengthLevel1Bar,
508 MockChooserController::kImageColorUnselected);
509 ExpectRowTextColorIs(0, [NSColor blackColor]);
510 ExpectRowTextColorIs(1, [NSColor whiteColor]);
511 ExpectRowTextColorIs(2, [NSColor blackColor]);
512 ExpectPairedTextColorIs(
513 0, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700));
514
515 // Deselect option 1.
516 [table_view_ deselectRow:1];
517 EXPECT_EQ(-1, table_view_.selectedRow);
518 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
519 ExpectSignalStrengthLevelImageIs(
520 1, MockChooserController::kSignalStrengthLevel0Bar,
521 MockChooserController::kImageColorUnselected);
522 ExpectSignalStrengthLevelImageIs(
523 2, MockChooserController::kSignalStrengthLevel1Bar,
524 MockChooserController::kImageColorUnselected);
525 ExpectRowTextColorIs(0, [NSColor blackColor]);
526 ExpectRowTextColorIs(1, [NSColor blackColor]);
527 ExpectRowTextColorIs(2, [NSColor blackColor]);
528 ExpectPairedTextColorIs(
529 0, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700));
530
531 // The following code tests the color of the image and text change when
532 // selecting another option without deselecting the first.
533 // Select option 0.
534 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0]
535 byExtendingSelection:NO];
536
537 // Select option 1.
538 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:1]
539 byExtendingSelection:NO];
540 EXPECT_EQ(1, table_view_.selectedRow);
541 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
542 ExpectSignalStrengthLevelImageIs(
543 1, MockChooserController::kSignalStrengthLevel0Bar,
544 MockChooserController::kImageColorSelected);
545 ExpectSignalStrengthLevelImageIs(
546 2, MockChooserController::kSignalStrengthLevel1Bar,
547 MockChooserController::kImageColorUnselected);
548 ExpectRowTextColorIs(0, [NSColor blackColor]);
549 ExpectRowTextColorIs(1, [NSColor whiteColor]);
550 ExpectRowTextColorIs(2, [NSColor blackColor]);
551 ExpectPairedTextColorIs(
552 0, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700));
553
554 // The following code tests the color of the image and text of a selected
555 // option when it is updated.
556 // Select option 2.
557 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:2]
558 byExtendingSelection:NO];
559
560 // Update option 2 from one signal strength to another.
561 mock_chooser_controller_->OptionUpdated(
562 base::ASCIIToUTF16("c"), base::ASCIIToUTF16("e"),
563 MockChooserController::kSignalStrengthLevel2Bar,
564 MockChooserController::ConnectedPairedStatus::NONE);
565 ExpectSignalStrengthLevelImageIs(
566 2, MockChooserController::kSignalStrengthLevel2Bar,
567 MockChooserController::kImageColorSelected);
568 ExpectRowTextColorIs(0, [NSColor blackColor]);
569 ExpectRowTextColorIs(1, [NSColor blackColor]);
570 ExpectRowTextColorIs(2, [NSColor whiteColor]);
571
572 // Update option 2 again from non-connected and non-paired to connected
573 // and paired.
574 mock_chooser_controller_->OptionUpdated(
575 base::ASCIIToUTF16("e"), base::ASCIIToUTF16("f"),
576 MockChooserController::kNoSignalStrengthLevelImage,
577 MockChooserController::ConnectedPairedStatus::CONNECTED |
578 MockChooserController::ConnectedPairedStatus::PAIRED);
579 ExpectRowImageIsConnectedImage(2, SK_ColorWHITE);
580 ExpectRowTextColorIs(0, [NSColor blackColor]);
581 ExpectRowTextColorIs(1, [NSColor blackColor]);
582 ExpectRowTextColorIs(2, [NSColor whiteColor]);
583 ExpectPairedTextColorIs(
584 2, skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen300));
585 }
586
401 TEST_F(ChooserDialogCocoaControllerTest, SelectAndDeselectAnOption) { 587 TEST_F(ChooserDialogCocoaControllerTest, SelectAndDeselectAnOption) {
402 CreateChooserDialog(); 588 CreateChooserDialog();
403 589
404 mock_chooser_controller_->OptionAdded( 590 mock_chooser_controller_->OptionAdded(
405 base::ASCIIToUTF16("a"), 591 base::ASCIIToUTF16("a"),
406 MockChooserController::kNoSignalStrengthLevelImage, 592 MockChooserController::kNoSignalStrengthLevelImage,
407 MockChooserController::ConnectedPairedStatus::CONNECTED | 593 MockChooserController::ConnectedPairedStatus::CONNECTED |
408 MockChooserController::ConnectedPairedStatus::PAIRED); 594 MockChooserController::ConnectedPairedStatus::PAIRED);
409 mock_chooser_controller_->OptionAdded( 595 mock_chooser_controller_->OptionAdded(
410 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar, 596 base::ASCIIToUTF16("b"), MockChooserController::kSignalStrengthLevel0Bar,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 byExtendingSelection:NO]; 746 byExtendingSelection:NO];
561 747
562 // Update option 1. 748 // Update option 1.
563 mock_chooser_controller_->OptionUpdated( 749 mock_chooser_controller_->OptionUpdated(
564 base::ASCIIToUTF16("b"), base::ASCIIToUTF16("d"), 750 base::ASCIIToUTF16("b"), base::ASCIIToUTF16("d"),
565 MockChooserController::kNoSignalStrengthLevelImage, 751 MockChooserController::kNoSignalStrengthLevelImage,
566 MockChooserController::ConnectedPairedStatus::CONNECTED | 752 MockChooserController::ConnectedPairedStatus::CONNECTED |
567 MockChooserController::ConnectedPairedStatus::PAIRED); 753 MockChooserController::ConnectedPairedStatus::PAIRED);
568 754
569 EXPECT_EQ(1, table_view_.selectedRow); 755 EXPECT_EQ(1, table_view_.selectedRow);
570 ExpectRowImageIsConnectedImage(0); 756 ExpectRowImageIsConnectedImage(0, gfx::kChromeIconGrey);
571 ExpectRowTextIs(0, @"a"); 757 ExpectRowTextIs(0, @"a");
572 EXPECT_TRUE(IsRowPaired(0)); 758 EXPECT_TRUE(IsRowPaired(0));
573 ExpectRowImageIsConnectedImage(1); 759 ExpectRowImageIsConnectedImage(1, SK_ColorWHITE);
574 ExpectRowTextIs(1, @"d"); 760 ExpectRowTextIs(1, @"d");
575 EXPECT_TRUE(IsRowPaired(1)); 761 EXPECT_TRUE(IsRowPaired(1));
576 ExpectSignalStrengthLevelImageIs( 762 ExpectSignalStrengthLevelImageIs(
577 2, MockChooserController::kSignalStrengthLevel1Bar); 763 2, MockChooserController::kSignalStrengthLevel1Bar,
764 MockChooserController::kImageColorUnselected);
578 ExpectRowTextIs(2, @"c"); 765 ExpectRowTextIs(2, @"c");
579 EXPECT_FALSE(IsRowPaired(2)); 766 EXPECT_FALSE(IsRowPaired(2));
580 EXPECT_TRUE(connect_button_.enabled); 767 EXPECT_TRUE(connect_button_.enabled);
581 } 768 }
582 769
583 TEST_F(ChooserDialogCocoaControllerTest, 770 TEST_F(ChooserDialogCocoaControllerTest,
584 AddAnOptionAndSelectItAndRemoveTheSelectedOption) { 771 AddAnOptionAndSelectItAndRemoveTheSelectedOption) {
585 CreateChooserDialog(); 772 CreateChooserDialog();
586 773
587 mock_chooser_controller_->OptionAdded( 774 mock_chooser_controller_->OptionAdded(
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 mock_chooser_controller_->OptionAdded( 1035 mock_chooser_controller_->OptionAdded(
849 base::ASCIIToUTF16("d"), MockChooserController::kSignalStrengthLevel2Bar, 1036 base::ASCIIToUTF16("d"), MockChooserController::kSignalStrengthLevel2Bar,
850 MockChooserController::ConnectedPairedStatus::NONE); 1037 MockChooserController::ConnectedPairedStatus::NONE);
851 EXPECT_FALSE(table_view_.hidden); 1038 EXPECT_FALSE(table_view_.hidden);
852 // |table_view_| should be enabled since there is an option. 1039 // |table_view_| should be enabled since there is an option.
853 EXPECT_TRUE(table_view_.enabled); 1040 EXPECT_TRUE(table_view_.enabled);
854 EXPECT_EQ(1, table_view_.numberOfRows); 1041 EXPECT_EQ(1, table_view_.numberOfRows);
855 // No option selected. 1042 // No option selected.
856 EXPECT_EQ(-1, table_view_.selectedRow); 1043 EXPECT_EQ(-1, table_view_.selectedRow);
857 ExpectSignalStrengthLevelImageIs( 1044 ExpectSignalStrengthLevelImageIs(
858 0, MockChooserController::kSignalStrengthLevel2Bar); 1045 0, MockChooserController::kSignalStrengthLevel2Bar,
1046 MockChooserController::kImageColorUnselected);
859 ExpectRowTextIs(0, @"d"); 1047 ExpectRowTextIs(0, @"d");
860 EXPECT_FALSE(IsRowPaired(0)); 1048 EXPECT_FALSE(IsRowPaired(0));
861 EXPECT_TRUE(spinner_.hidden); 1049 EXPECT_TRUE(spinner_.hidden);
862 EXPECT_FALSE(status_.hidden); 1050 EXPECT_FALSE(status_.hidden);
863 EXPECT_TRUE(rescan_button_.hidden); 1051 EXPECT_TRUE(rescan_button_.hidden);
864 // OK button is disabled since no option is selected. 1052 // OK button is disabled since no option is selected.
865 EXPECT_FALSE(connect_button_.enabled); 1053 EXPECT_FALSE(connect_button_.enabled);
866 EXPECT_TRUE(cancel_button_.enabled); 1054 EXPECT_TRUE(cancel_button_.enabled);
867 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0] 1055 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0]
868 byExtendingSelection:NO]; 1056 byExtendingSelection:NO];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 MockChooserController::ConnectedPairedStatus::NONE); 1096 MockChooserController::ConnectedPairedStatus::NONE);
909 1097
910 // Select option 0 and press "Get help" button. 1098 // Select option 0 and press "Get help" button.
911 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0] 1099 [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:0]
912 byExtendingSelection:NO]; 1100 byExtendingSelection:NO];
913 EXPECT_CALL(*mock_chooser_controller_, Select(testing::_)).Times(0); 1101 EXPECT_CALL(*mock_chooser_controller_, Select(testing::_)).Times(0);
914 EXPECT_CALL(*mock_chooser_controller_, Cancel()).Times(0); 1102 EXPECT_CALL(*mock_chooser_controller_, Cancel()).Times(0);
915 EXPECT_CALL(*mock_chooser_controller_, OpenHelpCenterUrl()).Times(1); 1103 EXPECT_CALL(*mock_chooser_controller_, OpenHelpCenterUrl()).Times(1);
916 [help_button_ performClick:chooser_dialog_controller_]; 1104 [help_button_ performClick:chooser_dialog_controller_];
917 } 1105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698