Chromium Code Reviews| 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.h" | |
| 6 #include "chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace chrome { | |
| 10 | |
| 11 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 return MediaGalleriesDialogController::GalleryToggled(pref_info, enabled); | |
|
sail
2012/08/14 21:00:33
no need for return
Evan Stade
2012/08/14 21:15:52
Done.
| |
| 22 } | |
| 23 | |
| 24 protected: | |
| 25 // Counter that tracks the number of times a checkbox has been toggled. | |
| 26 size_t toggles_; | |
| 27 | |
| 28 scoped_ptr<MediaGalleriesDialogGtk> dialog_; | |
|
sail
2012/08/14 21:00:33
This is not used by the class so it should probabl
Evan Stade
2012/08/14 21:15:52
Done.
| |
| 29 }; | |
| 30 | |
| 31 // Tests that checkboxes are initialized according to the contents of | |
| 32 // |known_galleries|. | |
| 33 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { | |
| 34 MediaGalleryPrefInfo gallery1; | |
| 35 gallery1.pref_id = 1; | |
| 36 known_galleries_[1] = GalleryPermission(gallery1, true); | |
| 37 MediaGalleryPrefInfo gallery2; | |
| 38 gallery2.pref_id = 2; | |
| 39 known_galleries_[2] = GalleryPermission(gallery2, false); | |
| 40 | |
| 41 dialog_.reset(new MediaGalleriesDialogGtk(this)); | |
| 42 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); | |
| 43 | |
| 44 GtkWidget* checkbox1 = dialog_->checkbox_map_[&known_galleries_[1].pref_info]; | |
| 45 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox1)); | |
| 46 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox1))); | |
| 47 | |
| 48 GtkWidget* checkbox2 = dialog_->checkbox_map_[&known_galleries_[2].pref_info]; | |
| 49 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox2)); | |
| 50 EXPECT_FALSE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox2))); | |
| 51 | |
| 52 // Initializing checkboxes should not cause them to be toggled. | |
| 53 EXPECT_EQ(0U, toggles_); | |
| 54 } | |
| 55 | |
| 56 // Tests that toggling checkboxes updates the controller. | |
| 57 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { | |
| 58 MediaGalleryPrefInfo gallery1; | |
| 59 gallery1.pref_id = 1; | |
| 60 known_galleries_[1] = GalleryPermission(gallery1, true); | |
| 61 | |
| 62 dialog_.reset(new MediaGalleriesDialogGtk(this)); | |
| 63 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); | |
| 64 GtkWidget* checkbox = | |
| 65 dialog_->checkbox_map_[&known_galleries_[1].pref_info]; | |
| 66 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox)); | |
| 67 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox))); | |
| 68 | |
| 69 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), FALSE); | |
| 70 EXPECT_FALSE(known_galleries_[1].allowed); | |
| 71 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), TRUE); | |
| 72 EXPECT_TRUE(known_galleries_[1].allowed); | |
| 73 | |
| 74 EXPECT_EQ(2U, toggles_); | |
| 75 } | |
| 76 | |
| 77 // Tests that UpdateGallery will add a new checkbox, but only if it refers to | |
| 78 // a gallery that the dialog hasn't seen before. | |
| 79 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { | |
| 80 dialog_.reset(new MediaGalleriesDialogGtk(this)); | |
| 81 | |
| 82 EXPECT_TRUE(dialog_->checkbox_map_.empty()); | |
| 83 | |
| 84 MediaGalleryPrefInfo gallery1; | |
| 85 dialog_->UpdateGallery(&gallery1, true); | |
| 86 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); | |
| 87 | |
| 88 MediaGalleryPrefInfo gallery2; | |
| 89 dialog_->UpdateGallery(&gallery2, true); | |
| 90 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); | |
| 91 | |
| 92 dialog_->UpdateGallery(&gallery2, false); | |
| 93 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); | |
| 94 } | |
| 95 | |
| 96 } // namespace chrome | |
| OLD | NEW |