| 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 #include "base/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.
h" | 7 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.
h" |
| 8 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" | 8 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" |
| 9 #include "components/storage_monitor/storage_info.h" | 9 #include "components/storage_monitor/storage_info.h" |
| 10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
| 11 #include "extensions/common/test_util.h" | 11 #include "extensions/common/test_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using ::testing::_; | 14 using ::testing::_; |
| 15 using ::testing::NiceMock; | 15 using ::testing::NiceMock; |
| 16 using ::testing::Return; | 16 using ::testing::Return; |
| 17 using ::testing::ReturnPointee; | 17 using ::testing::ReturnPointee; |
| 18 using ::testing::ReturnRef; | 18 using ::testing::ReturnRef; |
| 19 | 19 |
| 20 @interface MediaGalleryListEntry (testing) |
| 21 - (NSInteger)state; |
| 22 - (void)performClick:(id)sender; |
| 23 @end |
| 24 |
| 25 @implementation MediaGalleryListEntry (testing) |
| 26 |
| 27 - (NSInteger)state { |
| 28 return [checkbox_ state]; |
| 29 } |
| 30 |
| 31 - (void)performClick:(id)sender { |
| 32 [checkbox_ performClick:sender]; |
| 33 } |
| 34 |
| 35 @end |
| 36 |
| 37 |
| 20 MediaGalleryPrefInfo MakePrefInfoForTesting(MediaGalleryPrefId pref_id) { | 38 MediaGalleryPrefInfo MakePrefInfoForTesting(MediaGalleryPrefId pref_id) { |
| 21 MediaGalleryPrefInfo gallery; | 39 MediaGalleryPrefInfo gallery; |
| 22 gallery.pref_id = pref_id; | 40 gallery.pref_id = pref_id; |
| 23 gallery.device_id = storage_monitor::StorageInfo::MakeDeviceId( | 41 gallery.device_id = storage_monitor::StorageInfo::MakeDeviceId( |
| 24 storage_monitor::StorageInfo::FIXED_MASS_STORAGE, | 42 storage_monitor::StorageInfo::FIXED_MASS_STORAGE, |
| 25 base::Int64ToString(pref_id)); | 43 base::Int64ToString(pref_id)); |
| 26 gallery.display_name = base::ASCIIToUTF16("name"); | 44 gallery.display_name = base::ASCIIToUTF16("name"); |
| 27 return gallery; | 45 return gallery; |
| 28 } | 46 } |
| 29 | 47 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 EXPECT_CALL(controller, UnattachedPermissions()). | 86 EXPECT_CALL(controller, UnattachedPermissions()). |
| 69 WillRepeatedly(Return(unattached_permissions)); | 87 WillRepeatedly(Return(unattached_permissions)); |
| 70 | 88 |
| 71 // Initializing checkboxes should not cause them to be toggled. | 89 // Initializing checkboxes should not cause them to be toggled. |
| 72 EXPECT_CALL(controller, DidToggleGallery(_, _)). | 90 EXPECT_CALL(controller, DidToggleGallery(_, _)). |
| 73 Times(0); | 91 Times(0); |
| 74 | 92 |
| 75 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | 93 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
| 76 static_cast<MediaGalleriesDialogCocoa*>( | 94 static_cast<MediaGalleriesDialogCocoa*>( |
| 77 MediaGalleriesDialog::Create(&controller))); | 95 MediaGalleriesDialog::Create(&controller))); |
| 78 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | 96 EXPECT_EQ(2U, [[dialog->checkbox_container_ subviews] count]); |
| 79 | 97 |
| 80 NSButton* checkbox1 = [dialog->checkboxes_ objectAtIndex:0]; | 98 NSButton* checkbox1 = |
| 99 [[dialog->checkbox_container_ subviews] objectAtIndex:0]; |
| 81 EXPECT_EQ([checkbox1 state], NSOnState); | 100 EXPECT_EQ([checkbox1 state], NSOnState); |
| 82 | 101 |
| 83 NSButton* checkbox2 = [dialog->checkboxes_ objectAtIndex:1]; | 102 NSButton* checkbox2 = |
| 103 [[dialog->checkbox_container_ subviews] objectAtIndex:1]; |
| 84 EXPECT_EQ([checkbox2 state], NSOffState); | 104 EXPECT_EQ([checkbox2 state], NSOffState); |
| 85 } | 105 } |
| 86 | 106 |
| 87 // Tests that toggling checkboxes updates the controller. | 107 // Tests that toggling checkboxes updates the controller. |
| 88 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { | 108 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { |
| 89 NiceMock<MediaGalleriesDialogControllerMock> controller(dummy_extension()); | 109 NiceMock<MediaGalleriesDialogControllerMock> controller(dummy_extension()); |
| 90 | 110 |
| 91 MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions; | 111 MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions; |
| 92 attached_permissions.push_back( | 112 attached_permissions.push_back( |
| 93 MediaGalleriesDialogController::GalleryPermission( | 113 MediaGalleriesDialogController::GalleryPermission( |
| 94 1, MakePrefInfoForTesting(10), true)); | 114 1, MakePrefInfoForTesting(10), true)); |
| 95 EXPECT_CALL(controller, AttachedPermissions()). | 115 EXPECT_CALL(controller, AttachedPermissions()). |
| 96 WillRepeatedly(Return(attached_permissions)); | 116 WillRepeatedly(Return(attached_permissions)); |
| 97 | 117 |
| 98 MediaGalleriesDialogController::GalleryPermissionsVector | 118 MediaGalleriesDialogController::GalleryPermissionsVector |
| 99 unattached_permissions; | 119 unattached_permissions; |
| 100 EXPECT_CALL(controller, UnattachedPermissions()). | 120 EXPECT_CALL(controller, UnattachedPermissions()). |
| 101 WillRepeatedly(Return(unattached_permissions)); | 121 WillRepeatedly(Return(unattached_permissions)); |
| 102 | 122 |
| 103 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | 123 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
| 104 static_cast<MediaGalleriesDialogCocoa*>( | 124 static_cast<MediaGalleriesDialogCocoa*>( |
| 105 MediaGalleriesDialog::Create(&controller))); | 125 MediaGalleriesDialog::Create(&controller))); |
| 106 EXPECT_EQ(1U, [dialog->checkboxes_ count]); | 126 EXPECT_EQ(1U, [[dialog->checkbox_container_ subviews] count]); |
| 107 | 127 |
| 108 NSButton* checkbox = [dialog->checkboxes_ objectAtIndex:0]; | 128 NSButton* checkbox = [[dialog->checkbox_container_ subviews] objectAtIndex:0]; |
| 109 EXPECT_EQ([checkbox state], NSOnState); | 129 EXPECT_EQ([checkbox state], NSOnState); |
| 110 | 130 |
| 111 EXPECT_CALL(controller, DidToggleGallery(1, false)); | 131 EXPECT_CALL(controller, DidToggleGallery(1, false)); |
| 112 [checkbox performClick:nil]; | 132 [checkbox performClick:nil]; |
| 113 EXPECT_EQ([checkbox state], NSOffState); | 133 EXPECT_EQ([checkbox state], NSOffState); |
| 114 | 134 |
| 115 EXPECT_CALL(controller, DidToggleGallery(1, true)); | 135 EXPECT_CALL(controller, DidToggleGallery(1, true)); |
| 116 [checkbox performClick:nil]; | 136 [checkbox performClick:nil]; |
| 117 EXPECT_EQ([checkbox state], NSOnState); | 137 EXPECT_EQ([checkbox state], NSOnState); |
| 118 } | 138 } |
| 119 | 139 |
| 120 // Tests that UpdateGalleries will add a new checkbox, but only if it refers to | 140 // Tests that UpdateGalleries will add a new checkbox, but only if it refers to |
| 121 // a gallery that the dialog hasn't seen before. | 141 // a gallery that the dialog hasn't seen before. |
| 122 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { | 142 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { |
| 123 NiceMock<MediaGalleriesDialogControllerMock> controller(dummy_extension()); | 143 NiceMock<MediaGalleriesDialogControllerMock> controller(dummy_extension()); |
| 124 | 144 |
| 125 MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions; | 145 MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions; |
| 126 EXPECT_CALL(controller, AttachedPermissions()). | 146 EXPECT_CALL(controller, AttachedPermissions()). |
| 127 WillRepeatedly(ReturnPointee(&attached_permissions)); | 147 WillRepeatedly(ReturnPointee(&attached_permissions)); |
| 128 | 148 |
| 129 MediaGalleriesDialogController::GalleryPermissionsVector | 149 MediaGalleriesDialogController::GalleryPermissionsVector |
| 130 unattached_permissions; | 150 unattached_permissions; |
| 131 EXPECT_CALL(controller, UnattachedPermissions()). | 151 EXPECT_CALL(controller, UnattachedPermissions()). |
| 132 WillRepeatedly(Return(unattached_permissions)); | 152 WillRepeatedly(Return(unattached_permissions)); |
| 133 | 153 |
| 134 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | 154 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
| 135 static_cast<MediaGalleriesDialogCocoa*>( | 155 static_cast<MediaGalleriesDialogCocoa*>( |
| 136 MediaGalleriesDialog::Create(&controller))); | 156 MediaGalleriesDialog::Create(&controller))); |
| 137 | 157 |
| 138 EXPECT_EQ(0U, [dialog->checkboxes_ count]); | 158 EXPECT_EQ(0U, [[dialog->checkbox_container_ subviews] count]); |
| 139 CGFloat old_container_height = NSHeight([dialog->checkbox_container_ frame]); | 159 CGFloat old_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 140 | 160 |
| 141 attached_permissions.push_back( | 161 attached_permissions.push_back( |
| 142 MediaGalleriesDialogController::GalleryPermission( | 162 MediaGalleriesDialogController::GalleryPermission( |
| 143 1, MakePrefInfoForTesting(10), true)); | 163 1, MakePrefInfoForTesting(10), true)); |
| 144 dialog->UpdateGalleries(); | 164 dialog->UpdateGalleries(); |
| 145 EXPECT_EQ(1U, [dialog->checkboxes_ count]); | 165 EXPECT_EQ(1U, [[dialog->checkbox_container_ subviews] count]); |
| 146 | 166 |
| 147 // The checkbox container should be taller. | 167 // The checkbox container should be taller. |
| 148 CGFloat new_container_height = NSHeight([dialog->checkbox_container_ frame]); | 168 CGFloat new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 149 EXPECT_GT(new_container_height, old_container_height); | 169 EXPECT_GT(new_container_height, old_container_height); |
| 150 old_container_height = new_container_height; | 170 old_container_height = new_container_height; |
| 151 | 171 |
| 152 attached_permissions.push_back( | 172 attached_permissions.push_back( |
| 153 MediaGalleriesDialogController::GalleryPermission( | 173 MediaGalleriesDialogController::GalleryPermission( |
| 154 2, MakePrefInfoForTesting(20), true)); | 174 2, MakePrefInfoForTesting(20), true)); |
| 155 dialog->UpdateGalleries(); | 175 dialog->UpdateGalleries(); |
| 156 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | 176 EXPECT_EQ(2U, [[dialog->checkbox_container_ subviews] count]); |
| 157 | 177 |
| 158 // The checkbox container should be taller. | 178 // The checkbox container should be taller. |
| 159 new_container_height = NSHeight([dialog->checkbox_container_ frame]); | 179 new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 160 EXPECT_GT(new_container_height, old_container_height); | 180 EXPECT_GT(new_container_height, old_container_height); |
| 161 old_container_height = new_container_height; | 181 old_container_height = new_container_height; |
| 162 | 182 |
| 163 attached_permissions[1].allowed = false; | 183 attached_permissions[1].allowed = false; |
| 164 dialog->UpdateGalleries(); | 184 dialog->UpdateGalleries(); |
| 165 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | 185 EXPECT_EQ(2U, [[dialog->checkbox_container_ subviews] count]); |
| 166 | 186 |
| 167 // The checkbox container height should not have changed. | 187 // The checkbox container height should not have changed. |
| 168 new_container_height = NSHeight([dialog->checkbox_container_ frame]); | 188 new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 169 EXPECT_EQ(new_container_height, old_container_height); | 189 EXPECT_EQ(new_container_height, old_container_height); |
| 170 } | 190 } |
| 171 | 191 |
| 172 TEST_F(MediaGalleriesDialogTest, ForgetDeletes) { | 192 TEST_F(MediaGalleriesDialogTest, ForgetDeletes) { |
| 173 NiceMock<MediaGalleriesDialogControllerMock> controller(dummy_extension()); | 193 NiceMock<MediaGalleriesDialogControllerMock> controller(dummy_extension()); |
| 174 | 194 |
| 175 MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions; | 195 MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 | 207 |
| 188 // Add a couple of galleries. | 208 // Add a couple of galleries. |
| 189 attached_permissions.push_back( | 209 attached_permissions.push_back( |
| 190 MediaGalleriesDialogController::GalleryPermission( | 210 MediaGalleriesDialogController::GalleryPermission( |
| 191 1, MakePrefInfoForTesting(10), true)); | 211 1, MakePrefInfoForTesting(10), true)); |
| 192 dialog->UpdateGalleries(); | 212 dialog->UpdateGalleries(); |
| 193 attached_permissions.push_back( | 213 attached_permissions.push_back( |
| 194 MediaGalleriesDialogController::GalleryPermission( | 214 MediaGalleriesDialogController::GalleryPermission( |
| 195 2, MakePrefInfoForTesting(20), true)); | 215 2, MakePrefInfoForTesting(20), true)); |
| 196 dialog->UpdateGalleries(); | 216 dialog->UpdateGalleries(); |
| 197 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | 217 EXPECT_EQ(2U, [[dialog->checkbox_container_ subviews] count]); |
| 198 CGFloat old_container_height = NSHeight([dialog->checkbox_container_ frame]); | 218 CGFloat old_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 199 | 219 |
| 200 // Remove a gallery. | 220 // Remove a gallery. |
| 201 attached_permissions.erase(attached_permissions.begin()); | 221 attached_permissions.erase(attached_permissions.begin()); |
| 202 dialog->UpdateGalleries(); | 222 dialog->UpdateGalleries(); |
| 203 EXPECT_EQ(1U, [dialog->checkboxes_ count]); | 223 EXPECT_EQ(1U, [[dialog->checkbox_container_ subviews] count]); |
| 204 | 224 |
| 205 // The checkbox container should be shorter. | 225 // The checkbox container should be shorter. |
| 206 CGFloat new_container_height = NSHeight([dialog->checkbox_container_ frame]); | 226 CGFloat new_container_height = NSHeight([dialog->checkbox_container_ frame]); |
| 207 EXPECT_LT(new_container_height, old_container_height); | 227 EXPECT_LT(new_container_height, old_container_height); |
| 208 } | 228 } |
| OLD | NEW |