| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <memory> |
| 6 | 7 |
| 7 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.
h" | 12 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.
h" |
| 11 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" | 13 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" |
| 12 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" | 14 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" |
| 13 #include "components/storage_monitor/storage_info.h" | 15 #include "components/storage_monitor/storage_info.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/views/controls/button/checkbox.h" | 17 #include "ui/views/controls/button/checkbox.h" |
| 18 #include "ui/views/test/test_views_delegate.h" |
| 16 | 19 |
| 17 using ::testing::_; | 20 using ::testing::_; |
| 18 using ::testing::AnyNumber; | 21 using ::testing::AnyNumber; |
| 19 using ::testing::Mock; | 22 using ::testing::Mock; |
| 20 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
| 21 using ::testing::Return; | 24 using ::testing::Return; |
| 22 using ::testing::ReturnPointee; | 25 using ::testing::ReturnPointee; |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| 25 | 28 |
| 26 MediaGalleryPrefInfo MakePrefInfoForTesting(MediaGalleryPrefId id) { | 29 MediaGalleryPrefInfo MakePrefInfoForTesting(MediaGalleryPrefId id) { |
| 27 MediaGalleryPrefInfo gallery; | 30 MediaGalleryPrefInfo gallery; |
| 28 gallery.pref_id = id; | 31 gallery.pref_id = id; |
| 29 gallery.device_id = storage_monitor::StorageInfo::MakeDeviceId( | 32 gallery.device_id = storage_monitor::StorageInfo::MakeDeviceId( |
| 30 storage_monitor::StorageInfo::FIXED_MASS_STORAGE, | 33 storage_monitor::StorageInfo::FIXED_MASS_STORAGE, |
| 31 base::Uint64ToString(id)); | 34 base::Uint64ToString(id)); |
| 32 gallery.display_name = base::ASCIIToUTF16("Display Name"); | 35 gallery.display_name = base::ASCIIToUTF16("Display Name"); |
| 33 return gallery; | 36 return gallery; |
| 34 } | 37 } |
| 35 | 38 |
| 36 } // namespace | 39 } // namespace |
| 37 | 40 |
| 38 class MediaGalleriesDialogTest : public testing::Test { | 41 class MediaGalleriesDialogTest : public testing::Test { |
| 39 public: | 42 public: |
| 40 MediaGalleriesDialogTest() {} | 43 MediaGalleriesDialogTest() {} |
| 41 ~MediaGalleriesDialogTest() override {} | 44 ~MediaGalleriesDialogTest() override {} |
| 42 void SetUp() override { | 45 void SetUp() override { |
| 43 std::vector<base::string16> headers; | 46 std::vector<base::string16> headers; |
| 47 views_delegate_ = base::MakeUnique<views::TestViewsDelegate>(); |
| 44 headers.push_back(base::string16()); | 48 headers.push_back(base::string16()); |
| 45 headers.push_back(base::ASCIIToUTF16("header2")); | 49 headers.push_back(base::ASCIIToUTF16("header2")); |
| 46 ON_CALL(controller_, GetSectionHeaders()). | 50 ON_CALL(controller_, GetSectionHeaders()). |
| 47 WillByDefault(Return(headers)); | 51 WillByDefault(Return(headers)); |
| 48 EXPECT_CALL(controller_, GetSectionEntries(_)). | 52 EXPECT_CALL(controller_, GetSectionEntries(_)). |
| 49 Times(AnyNumber()); | 53 Times(AnyNumber()); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void TearDown() override { | 56 void TearDown() override { |
| 53 Mock::VerifyAndClearExpectations(&controller_); | 57 Mock::VerifyAndClearExpectations(&controller_); |
| 54 } | 58 } |
| 55 | 59 |
| 56 NiceMock<MediaGalleriesDialogControllerMock>* controller() { | 60 NiceMock<MediaGalleriesDialogControllerMock>* controller() { |
| 57 return &controller_; | 61 return &controller_; |
| 58 } | 62 } |
| 59 | 63 |
| 60 private: | 64 private: |
| 61 // TODO(gbillock): Get rid of this mock; make something specialized. | 65 // TODO(gbillock): Get rid of this mock; make something specialized. |
| 62 NiceMock<MediaGalleriesDialogControllerMock> controller_; | 66 NiceMock<MediaGalleriesDialogControllerMock> controller_; |
| 67 std::unique_ptr<views::TestViewsDelegate> views_delegate_; |
| 63 | 68 |
| 64 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogTest); | 69 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogTest); |
| 65 }; | 70 }; |
| 66 | 71 |
| 67 // Tests that checkboxes are initialized according to the contents of | 72 // Tests that checkboxes are initialized according to the contents of |
| 68 // permissions in the registry. | 73 // permissions in the registry. |
| 69 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { | 74 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { |
| 70 MediaGalleriesDialogController::Entries attached_permissions; | 75 MediaGalleriesDialogController::Entries attached_permissions; |
| 71 attached_permissions.push_back( | 76 attached_permissions.push_back( |
| 72 MediaGalleriesDialogController::Entry(MakePrefInfoForTesting(1), true)); | 77 MediaGalleriesDialogController::Entry(MakePrefInfoForTesting(1), true)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 MediaGalleryPrefInfo gallery2 = MakePrefInfoForTesting(2); | 160 MediaGalleryPrefInfo gallery2 = MakePrefInfoForTesting(2); |
| 156 attached_permissions.push_back( | 161 attached_permissions.push_back( |
| 157 MediaGalleriesDialogController::Entry(gallery2, true)); | 162 MediaGalleriesDialogController::Entry(gallery2, true)); |
| 158 dialog.UpdateGalleries(); | 163 dialog.UpdateGalleries(); |
| 159 EXPECT_EQ(2U, dialog.checkbox_map_.size()); | 164 EXPECT_EQ(2U, dialog.checkbox_map_.size()); |
| 160 | 165 |
| 161 attached_permissions.pop_back(); | 166 attached_permissions.pop_back(); |
| 162 dialog.UpdateGalleries(); | 167 dialog.UpdateGalleries(); |
| 163 EXPECT_EQ(1U, dialog.checkbox_map_.size()); | 168 EXPECT_EQ(1U, dialog.checkbox_map_.size()); |
| 164 } | 169 } |
| OLD | NEW |