OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media_gallery/media_galleries_dialog_controller_mock.h" |
| 6 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 using ::testing::_; |
| 10 using ::testing::NiceMock; |
| 11 using ::testing::Return; |
| 12 using ::testing::ReturnRef; |
| 13 |
| 14 namespace chrome { |
| 15 |
| 16 class MediaGalleriesDialogTest : public testing::Test { |
| 17 }; |
| 18 |
| 19 // Tests that checkboxes are initialized according to the contents of |
| 20 // permissions(). |
| 21 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { |
| 22 NiceMock<MediaGalleriesDialogControllerMock> controller; |
| 23 |
| 24 MediaGalleriesDialogController::KnownGalleryPermissions permissions; |
| 25 MediaGalleryPrefInfo gallery1; |
| 26 gallery1.device_id = "/a"; |
| 27 permissions[1] = MediaGalleriesDialogController::GalleryPermission( |
| 28 gallery1, true); |
| 29 MediaGalleryPrefInfo gallery2; |
| 30 gallery2.device_id = "/b"; |
| 31 permissions[2] = MediaGalleriesDialogController::GalleryPermission( |
| 32 gallery2, false); |
| 33 EXPECT_CALL(controller, permissions()). |
| 34 WillRepeatedly(ReturnRef(permissions)); |
| 35 |
| 36 // Initializing checkboxes should not cause them to be toggled. |
| 37 EXPECT_CALL(controller, DidToggleGallery(_, _)). |
| 38 Times(0); |
| 39 |
| 40 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
| 41 static_cast<MediaGalleriesDialogCocoa*>( |
| 42 MediaGalleriesDialog::Create(&controller))); |
| 43 EXPECT_EQ(2U, [dialog->checkboxes_ count]); |
| 44 |
| 45 // Note that checkboxes_ is sorted from bottom up. |
| 46 NSButton* checkbox1 = [dialog->checkboxes_ objectAtIndex:1]; |
| 47 EXPECT_EQ([checkbox1 state], NSOnState); |
| 48 |
| 49 NSButton* checkbox2 = [dialog->checkboxes_ objectAtIndex:0]; |
| 50 EXPECT_EQ([checkbox2 state], NSOffState); |
| 51 } |
| 52 |
| 53 // Tests that toggling checkboxes updates the controller. |
| 54 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { |
| 55 NiceMock<MediaGalleriesDialogControllerMock> controller; |
| 56 |
| 57 MediaGalleriesDialogController::KnownGalleryPermissions permissions; |
| 58 MediaGalleryPrefInfo gallery; |
| 59 permissions[1] = MediaGalleriesDialogController::GalleryPermission( |
| 60 gallery, true); |
| 61 EXPECT_CALL(controller, permissions()). |
| 62 WillRepeatedly(ReturnRef(permissions)); |
| 63 |
| 64 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
| 65 static_cast<MediaGalleriesDialogCocoa*>( |
| 66 MediaGalleriesDialog::Create(&controller))); |
| 67 EXPECT_EQ(1U, [dialog->checkboxes_ count]); |
| 68 |
| 69 NSButton* checkbox = [dialog->checkboxes_ objectAtIndex:0]; |
| 70 EXPECT_EQ([checkbox state], NSOnState); |
| 71 |
| 72 EXPECT_CALL(controller, DidToggleGallery(_, false)); |
| 73 [checkbox performClick:nil]; |
| 74 EXPECT_EQ([checkbox state], NSOffState); |
| 75 |
| 76 EXPECT_CALL(controller, DidToggleGallery(_, true)); |
| 77 [checkbox performClick:nil]; |
| 78 EXPECT_EQ([checkbox state], NSOnState); |
| 79 } |
| 80 |
| 81 // Tests that UpdateGallery will add a new checkbox, but only if it refers to |
| 82 // a gallery that the dialog hasn't seen before. |
| 83 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { |
| 84 NiceMock<MediaGalleriesDialogControllerMock> controller; |
| 85 |
| 86 MediaGalleriesDialogController::KnownGalleryPermissions permissions; |
| 87 EXPECT_CALL(controller, permissions()). |
| 88 WillRepeatedly(ReturnRef(permissions)); |
| 89 |
| 90 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
| 91 static_cast<MediaGalleriesDialogCocoa*>( |
| 92 MediaGalleriesDialog::Create(&controller))); |
| 93 |
| 94 EXPECT_EQ(0U, [dialog->checkboxes_ count]); |
| 95 CGFloat old_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 96 |
| 97 MediaGalleryPrefInfo gallery1; |
| 98 gallery1.device_id = "/a"; |
| 99 dialog->UpdateGallery(&gallery1, true); |
| 100 EXPECT_EQ(1U, [dialog->checkboxes_ count]); |
| 101 |
| 102 // The checkbox container should be taller. |
| 103 CGFloat new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 104 EXPECT_GT(new_container_height, old_container_height); |
| 105 old_container_height = new_container_height; |
| 106 |
| 107 MediaGalleryPrefInfo gallery2; |
| 108 gallery2.device_id = "/b"; |
| 109 dialog->UpdateGallery(&gallery2, true); |
| 110 EXPECT_EQ(2U, [dialog->checkboxes_ count]); |
| 111 |
| 112 // The checkbox container should be taller. |
| 113 new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 114 EXPECT_GT(new_container_height, old_container_height); |
| 115 old_container_height = new_container_height; |
| 116 |
| 117 dialog->UpdateGallery(&gallery2, false); |
| 118 EXPECT_EQ(2U, [dialog->checkboxes_ count]); |
| 119 |
| 120 // The checkbox container height should not have changed. |
| 121 new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 122 EXPECT_EQ(new_container_height, old_container_height); |
| 123 } |
| 124 |
| 125 } // namespace chrome |
OLD | NEW |