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 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 }; |
| 28 |
| 29 // Tests that checkboxes are initialized according to the contents of |
| 30 // |known_galleries|. |
| 31 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { |
| 32 MediaGalleryPrefInfo gallery1; |
| 33 gallery1.pref_id = 1; |
| 34 known_galleries_[1] = GalleryPermission(gallery1, true); |
| 35 MediaGalleryPrefInfo gallery2; |
| 36 gallery2.pref_id = 2; |
| 37 known_galleries_[2] = GalleryPermission(gallery2, false); |
| 38 |
| 39 scoped_ptr<MediaGalleriesDialogGtk> |
| 40 dialog_(new MediaGalleriesDialogGtk(this)); |
| 41 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); |
| 42 |
| 43 GtkWidget* checkbox1 = dialog_->checkbox_map_[&known_galleries_[1].pref_info]; |
| 44 ASSERT_TRUE(GTK_IS_TOGGLE_BUTTON(checkbox1)); |
| 45 EXPECT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox1))); |
| 46 |
| 47 GtkWidget* checkbox2 = dialog_->checkbox_map_[&known_galleries_[2].pref_info]; |
| 48 ASSERT_TRUE(GTK_IS_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 } |
| 54 |
| 55 // Tests that toggling checkboxes updates the controller. |
| 56 TEST_F(MediaGalleriesDialogTest, ToggleCheckboxes) { |
| 57 MediaGalleryPrefInfo gallery1; |
| 58 gallery1.pref_id = 1; |
| 59 known_galleries_[1] = GalleryPermission(gallery1, true); |
| 60 |
| 61 scoped_ptr<MediaGalleriesDialogGtk> |
| 62 dialog_(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 scoped_ptr<MediaGalleriesDialogGtk> |
| 81 dialog_(new MediaGalleriesDialogGtk(this)); |
| 82 |
| 83 EXPECT_TRUE(dialog_->checkbox_map_.empty()); |
| 84 |
| 85 MediaGalleryPrefInfo gallery1; |
| 86 dialog_->UpdateGallery(&gallery1, true); |
| 87 EXPECT_EQ(1U, dialog_->checkbox_map_.size()); |
| 88 |
| 89 MediaGalleryPrefInfo gallery2; |
| 90 dialog_->UpdateGallery(&gallery2, true); |
| 91 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); |
| 92 |
| 93 dialog_->UpdateGallery(&gallery2, false); |
| 94 EXPECT_EQ(2U, dialog_->checkbox_map_.size()); |
| 95 } |
| 96 |
| 97 } // namespace chrome |
OLD | NEW |