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 "base/gtest_prod_util.h" | |
6 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" | |
7 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace chrome { | |
11 | |
12 class MediaGalleriesDialogTest : public testing::Test, | |
13 public MediaGalleriesDialogController { | |
Nico
2012/08/14 21:23:36
It's confusing me that the test fixture class is a
| |
14 public: | |
15 MediaGalleriesDialogTest() : toggles_(0) {} | |
16 virtual ~MediaGalleriesDialogTest() {} | |
17 | |
18 virtual void DialogFinished(bool accepted) OVERRIDE {} | |
19 virtual void DidToggleGallery(const MediaGalleryPrefInfo* pref_info, | |
20 bool enabled) OVERRIDE { | |
21 toggles_++; | |
22 MediaGalleriesDialogController::DidToggleGallery(pref_info, enabled); | |
23 } | |
24 | |
25 protected: | |
26 // Counter that tracks the number of times a checkbox has been toggled. | |
27 size_t toggles_; | |
28 }; | |
29 | |
30 // Tests that checkboxes are initialized according to the contents of | |
31 // |known_galleries|. | |
32 TEST_F(MediaGalleriesDialogTest, InitializeCheckboxes) { | |
33 MediaGalleryPrefInfo gallery1; | |
34 gallery1.device_id = "/a"; | |
35 known_galleries_[1] = GalleryPermission(gallery1, true); | |
36 MediaGalleryPrefInfo gallery2; | |
37 gallery2.device_id = "/b"; | |
38 known_galleries_[2] = GalleryPermission(gallery2, false); | |
39 | |
40 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | |
41 static_cast<MediaGalleriesDialogCocoa*>( | |
42 MediaGalleriesDialog::Create(this))); | |
43 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | |
44 | |
45 // Note that checkboxes_ is sorted from bottom up. | |
46 NSButton* checkbox1 = [dialog->checkboxes_ objectAtIndex:1]; | |
47 EXPECT_EQ([checkbox1 state], NSOnState); | |
48 | |
49 NSButton* checkbox2 = [dialog->checkboxes_ objectAtIndex:0]; | |
50 EXPECT_EQ([checkbox2 state], NSOffState); | |
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 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | |
63 static_cast<MediaGalleriesDialogCocoa*>( | |
64 MediaGalleriesDialog::Create(this))); | |
65 EXPECT_EQ(1U, [dialog->checkboxes_ count]); | |
66 | |
67 NSButton* checkbox = [dialog->checkboxes_ objectAtIndex:0]; | |
68 EXPECT_EQ([checkbox state], NSOnState); | |
69 | |
70 [checkbox performClick:nil]; | |
71 EXPECT_EQ([checkbox state], NSOffState); | |
72 [checkbox performClick:nil]; | |
73 EXPECT_EQ([checkbox state], NSOnState); | |
74 | |
75 EXPECT_EQ(2U, toggles_); | |
76 } | |
77 | |
78 // Tests that UpdateGallery will add a new checkbox, but only if it refers to | |
79 // a gallery that the dialog hasn't seen before. | |
80 TEST_F(MediaGalleriesDialogTest, UpdateAdds) { | |
81 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | |
82 static_cast<MediaGalleriesDialogCocoa*>( | |
83 MediaGalleriesDialog::Create(this))); | |
84 | |
85 EXPECT_EQ(0U, [dialog->checkboxes_ count]); | |
86 | |
87 MediaGalleryPrefInfo gallery1; | |
88 gallery1.device_id = "/a"; | |
89 dialog->UpdateGallery(&gallery1, true); | |
90 EXPECT_EQ(1U, [dialog->checkboxes_ count]); | |
91 | |
92 MediaGalleryPrefInfo gallery2; | |
93 gallery2.device_id = "/b"; | |
94 dialog->UpdateGallery(&gallery2, true); | |
95 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | |
96 | |
97 dialog->UpdateGallery(&gallery2, false); | |
98 EXPECT_EQ(2U, [dialog->checkboxes_ count]); | |
99 } | |
100 | |
101 | |
102 } // namespace chrome | |
OLD | NEW |