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 "chrome/browser/media_gallery/media_galleries_dialog_controller.h" | 5 #include "chrome/browser/media_gallery/media_galleries_dialog_controller_mock.h" |
6 #include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h" | 6 #include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 using ::testing::_; | |
10 using ::testing::NiceMock; | |
11 using ::testing::ReturnRef; | |
12 | |
9 namespace chrome { | 13 namespace chrome { |
10 | 14 |
11 class MediaGalleriesDialogTest : public testing::Test, | 15 class MediaGalleriesDialogTest : public testing::Test { |
12 public MediaGalleriesDialogController { | |
13 public: | |
14 MediaGalleriesDialogTest() : toggles_(0) {} | |
15 virtual ~MediaGalleriesDialogTest() {} | |
16 | |
17 virtual void DialogFinished(bool accepted) OVERRIDE {} | |
18 virtual void GalleryToggled(const MediaGalleryPrefInfo* pref_info, | |
19 bool enabled) OVERRIDE { | |
20 toggles_++; | |
21 MediaGalleriesDialogController::GalleryToggled(pref_info, enabled); | |
22 } | |
23 | |
24 protected: | |
25 // Counter that tracks the number of times a checkbox has been toggled. | |
26 size_t toggles_; | |
27 }; | 16 }; |
28 | 17 |
29 // Tests that checkboxes are initialized according to the contents of | 18 // Tests that checkboxes are initialized according to the contents of |
30 // |known_galleries|. | 19 // permissions(). |
31 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { | 20 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { |
21 NiceMock<MediaGalleriesDialogControllerMock> controller; | |
22 | |
23 MediaGalleriesDialogController::KnownGalleryPermissions permissions; | |
32 MediaGalleryPrefInfo gallery1; | 24 MediaGalleryPrefInfo gallery1; |
33 gallery1.pref_id = 1; | 25 gallery1.pref_id = 1; |
34 known_galleries_[1] = GalleryPermission(gallery1, true); | 26 permissions[1] = |
27 MediaGalleriesDialogController::GalleryPermission(gallery1, true); | |
35 MediaGalleryPrefInfo gallery2; | 28 MediaGalleryPrefInfo gallery2; |
36 gallery2.pref_id = 2; | 29 gallery2.pref_id = 2; |
37 known_galleries_[2] = GalleryPermission(gallery2, false); | 30 permissions[2] = |
31 MediaGalleriesDialogController::GalleryPermission(gallery2, false); | |
32 EXPECT_CALL(controller, permissions()). | |
33 WillRepeatedly(ReturnRef(permissions)); | |
34 | |
35 // Initializing checkboxes should not cause them to be toggled. | |
36 EXPECT_CALL(controller, DidToggleGallery(_, _)). | |
37 Times(0); | |
38 | 38 |
39 scoped_ptr<MediaGalleriesDialogGtk> | 39 scoped_ptr<MediaGalleriesDialogGtk> |
40 dialog_(new MediaGalleriesDialogGtk(this)); | 40 dialog_(new MediaGalleriesDialogGtk(&controller)); |
Evan Stade
2012/08/15 23:01:00
it strikes me that this doesn't need to be a scope
sail
2012/08/15 23:07:31
Done.
| |
41 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); | 41 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); |
42 | 42 |
43 GtkWidget* checkbox1 = dialog_->checkbox_map_[&known_galleries_[1].pref_info]; | 43 GtkWidget* checkbox1 = dialog_->checkbox_map_[&permissions[1].pref_info]; |
44 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox1)); | 44 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox1)); |
45 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox1))); | 45 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox1))); |
46 | 46 |
47 GtkWidget* checkbox2 = dialog_->checkbox_map_[&known_galleries_[2].pref_info]; | 47 GtkWidget* checkbox2 = dialog_->checkbox_map_[&permissions[2].pref_info]; |
48 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox2)); | 48 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox2)); |
49 EXPECT_FALSE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox2))); | 49 EXPECT_FALSE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox2))); |
50 | |
51 // Initializing checkboxes should not cause them to be toggled. | |
52 EXPECT_EQ(0U, toggles_); | |
53 } | 50 } |
54 | 51 |
55 // Tests that toggling checkboxes updates the controller. | 52 // Tests that toggling checkboxes updates the controller. |
56 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { | 53 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { |
54 NiceMock<MediaGalleriesDialogControllerMock> controller; | |
55 | |
56 MediaGalleriesDialogController::KnownGalleryPermissions permissions; | |
57 MediaGalleryPrefInfo gallery1; | 57 MediaGalleryPrefInfo gallery1; |
58 gallery1.pref_id = 1; | 58 gallery1.pref_id = 1; |
59 known_galleries_[1] = GalleryPermission(gallery1, true); | 59 permissions[1] = |
60 MediaGalleriesDialogController::GalleryPermission(gallery1, true); | |
61 EXPECT_CALL(controller, permissions()). | |
62 WillRepeatedly(ReturnRef(permissions)); | |
60 | 63 |
61 scoped_ptr<MediaGalleriesDialogGtk> | 64 scoped_ptr<MediaGalleriesDialogGtk> |
62 dialog_(new MediaGalleriesDialogGtk(this)); | 65 dialog_(new MediaGalleriesDialogGtk(&controller)); |
63 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); | 66 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); |
64 GtkWidget* checkbox = | 67 GtkWidget* checkbox = |
65 dialog_->checkbox_map_[&known_galleries_[1].pref_info]; | 68 dialog_->checkbox_map_[&permissions[1].pref_info]; |
66 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox)); | 69 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox)); |
67 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox))); | 70 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox))); |
68 | 71 |
72 EXPECT_CALL(controller, DidToggleGallery(_, false)); | |
69 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), FALSE); | 73 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), FALSE); |
70 EXPECT_FALSE(known_galleries_[1].allowed); | 74 |
75 EXPECT_CALL(controller, DidToggleGallery(_, true)); | |
71 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), TRUE); | 76 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), TRUE); |
72 EXPECT_TRUE(known_galleries_[1].allowed); | |
73 | |
74 EXPECT_EQ(2U, toggles_); | |
75 } | 77 } |
76 | 78 |
77 // Tests that UpdateGallery will add a new checkbox, but only if it refers to | 79 // Tests that UpdateGallery will add a new checkbox, but only if it refers to |
78 // a gallery that the dialog hasn't seen before. | 80 // a gallery that the dialog hasn't seen before. |
79 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { | 81 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { |
82 NiceMock<MediaGalleriesDialogControllerMock> controller; | |
83 | |
84 MediaGalleriesDialogController::KnownGalleryPermissions permissions; | |
85 EXPECT_CALL(controller, permissions()). | |
86 WillRepeatedly(ReturnRef(permissions)); | |
87 | |
80 scoped_ptr<MediaGalleriesDialogGtk> | 88 scoped_ptr<MediaGalleriesDialogGtk> |
81 dialog_(new MediaGalleriesDialogGtk(this)); | 89 dialog_(new MediaGalleriesDialogGtk(&controller)); |
82 | 90 |
83 EXPECT_TRUE(dialog_->checkbox_map_.empty()); | 91 EXPECT_TRUE(dialog_->checkbox_map_.empty()); |
84 | 92 |
85 MediaGalleryPrefInfo gallery1; | 93 MediaGalleryPrefInfo gallery1; |
86 dialog_->UpdateGallery(&gallery1, true); | 94 dialog_->UpdateGallery(&gallery1, true); |
87 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); | 95 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); |
88 | 96 |
89 MediaGalleryPrefInfo gallery2; | 97 MediaGalleryPrefInfo gallery2; |
90 dialog_->UpdateGallery(&gallery2, true); | 98 dialog_->UpdateGallery(&gallery2, true); |
91 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); | 99 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); |
92 | 100 |
93 dialog_->UpdateGallery(&gallery2, false); | 101 dialog_->UpdateGallery(&gallery2, false); |
94 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); | 102 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); |
95 } | 103 } |
96 | 104 |
97 } // namespace chrome | 105 } // namespace chrome |
OLD | NEW |