Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/ui/views/desktop_media_picker_views_unittest.cc

Issue 1880693002: Desktop Capture Picker New UI: Preliminary Refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/views/desktop_media_picker_views.h" 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 11 matching lines...) Expand all
22 #include "ui/views/window/dialog_delegate.h" 22 #include "ui/views/window/dialog_delegate.h"
23 23
24 namespace views { 24 namespace views {
25 25
26 class DesktopMediaPickerViewsTest : public testing::Test { 26 class DesktopMediaPickerViewsTest : public testing::Test {
27 public: 27 public:
28 DesktopMediaPickerViewsTest() {} 28 DesktopMediaPickerViewsTest() {}
29 ~DesktopMediaPickerViewsTest() override {} 29 ~DesktopMediaPickerViewsTest() override {}
30 30
31 void SetUp() override { 31 void SetUp() override {
32 media_list_ = new FakeDesktopMediaList(); 32 screen_list_ = new FakeDesktopMediaList();
33 std::unique_ptr<FakeDesktopMediaList> media_list(media_list_); 33 window_list_ = new FakeDesktopMediaList();
34 tab_list_ = new FakeDesktopMediaList();
35 std::unique_ptr<FakeDesktopMediaList> screen_list(screen_list_);
36 std::unique_ptr<FakeDesktopMediaList> window_list(window_list_);
37 std::unique_ptr<FakeDesktopMediaList> tab_list(tab_list_);
34 38
35 base::string16 app_name = base::ASCIIToUTF16("foo"); 39 base::string16 app_name = base::ASCIIToUTF16("foo");
36 40
37 picker_views_.reset(new DesktopMediaPickerViews()); 41 picker_views_.reset(new DesktopMediaPickerViews());
38 picker_views_->Show(NULL, test_helper_.GetContext(), NULL, app_name, 42 picker_views_->Show(NULL, test_helper_.GetContext(), NULL, app_name,
39 app_name, std::move(media_list), false, 43 app_name, std::move(screen_list),
44 std::move(window_list), std::move(tab_list), false,
40 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone, 45 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone,
41 base::Unretained(this))); 46 base::Unretained(this)));
42 } 47 }
43 48
44 void TearDown() override { 49 void TearDown() override {
45 if (GetPickerDialogView()) { 50 if (GetPickerDialogView()) {
46 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); 51 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID()));
47 GetPickerDialogView()->GetWidget()->CloseNow(); 52 GetPickerDialogView()->GetWidget()->CloseNow();
48 } 53 }
49 } 54 }
50 55
51 DesktopMediaPickerDialogView* GetPickerDialogView() const { 56 DesktopMediaPickerDialogView* GetPickerDialogView() const {
52 return picker_views_->GetDialogViewForTesting(); 57 return picker_views_->GetDialogViewForTesting();
53 } 58 }
54 59
55 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID)); 60 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID));
56 61
57 protected: 62 protected:
58 content::TestBrowserThreadBundle thread_bundle_; 63 content::TestBrowserThreadBundle thread_bundle_;
59 views::ScopedViewsTestHelper test_helper_; 64 views::ScopedViewsTestHelper test_helper_;
60 FakeDesktopMediaList* media_list_; 65 FakeDesktopMediaList* screen_list_;
66 FakeDesktopMediaList* window_list_;
67 FakeDesktopMediaList* tab_list_;
61 std::unique_ptr<DesktopMediaPickerViews> picker_views_; 68 std::unique_ptr<DesktopMediaPickerViews> picker_views_;
62 }; 69 };
63 70
64 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) { 71 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) {
65 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); 72 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID()));
66 73
67 GetPickerDialogView()->GetWidget()->Close(); 74 GetPickerDialogView()->GetWidget()->Close();
68 base::RunLoop().RunUntilIdle(); 75 base::RunLoop().RunUntilIdle();
69 } 76 }
70 77
71 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnOkButtonPressed) { 78 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnOkButtonPressed) {
72 const int kFakeId = 222; 79 const int kFakeId = 222;
73 EXPECT_CALL(*this, 80 EXPECT_CALL(*this,
74 OnPickerDone(content::DesktopMediaID( 81 OnPickerDone(content::DesktopMediaID(
75 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); 82 content::DesktopMediaID::TYPE_WINDOW, kFakeId)));
76 media_list_->AddSource(kFakeId); 83 window_list_->AddSource(kFakeId);
77 84
78 EXPECT_FALSE( 85 EXPECT_FALSE(
79 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 86 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
80 87
81 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); 88 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus();
82 EXPECT_TRUE( 89 EXPECT_TRUE(
83 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 90 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
84 91
85 GetPickerDialogView()->GetDialogClientView()->AcceptWindow(); 92 GetPickerDialogView()->GetDialogClientView()->AcceptWindow();
86 base::RunLoop().RunUntilIdle(); 93 base::RunLoop().RunUntilIdle();
87 } 94 }
88 95
89 // Verifies that a MediaSourceView is selected with mouse left click and 96 // Verifies that a MediaSourceView is selected with mouse left click and
90 // original selected MediaSourceView gets unselected. 97 // original selected MediaSourceView gets unselected.
91 TEST_F(DesktopMediaPickerViewsTest, SelectMediaSourceViewOnSingleClick) { 98 TEST_F(DesktopMediaPickerViewsTest, SelectMediaSourceViewOnSingleClick) {
92 media_list_->AddSource(0); 99 window_list_->AddSource(0);
93 media_list_->AddSource(1); 100 window_list_->AddSource(1);
94 101
95 DesktopMediaSourceView* source_view_0 = 102 DesktopMediaSourceView* source_view_0 =
96 GetPickerDialogView()->GetMediaSourceViewForTesting(0); 103 GetPickerDialogView()->GetMediaSourceViewForTesting(0);
97 104
98 DesktopMediaSourceView* source_view_1 = 105 DesktopMediaSourceView* source_view_1 =
99 GetPickerDialogView()->GetMediaSourceViewForTesting(1); 106 GetPickerDialogView()->GetMediaSourceViewForTesting(1);
100 107
101 // Both media source views are not selected initially. 108 // Both media source views are not selected initially.
102 EXPECT_FALSE(source_view_0->is_selected()); 109 EXPECT_FALSE(source_view_0->is_selected());
103 EXPECT_FALSE(source_view_1->is_selected()); 110 EXPECT_FALSE(source_view_1->is_selected());
(...skipping 13 matching lines...) Expand all
117 EXPECT_FALSE(source_view_0->is_selected()); 124 EXPECT_FALSE(source_view_0->is_selected());
118 EXPECT_TRUE(source_view_1->is_selected()); 125 EXPECT_TRUE(source_view_1->is_selected());
119 } 126 }
120 127
121 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleClick) { 128 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleClick) {
122 const int kFakeId = 222; 129 const int kFakeId = 222;
123 EXPECT_CALL(*this, 130 EXPECT_CALL(*this,
124 OnPickerDone(content::DesktopMediaID( 131 OnPickerDone(content::DesktopMediaID(
125 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); 132 content::DesktopMediaID::TYPE_WINDOW, kFakeId)));
126 133
127 media_list_->AddSource(kFakeId); 134 window_list_->AddSource(kFakeId);
128 135
129 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 136 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
130 ui::EventTimeForNow(), 137 ui::EventTimeForNow(),
131 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, 138 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
132 ui::EF_LEFT_MOUSE_BUTTON); 139 ui::EF_LEFT_MOUSE_BUTTON);
133 140
134 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed( 141 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed(
135 double_click); 142 double_click);
136 base::RunLoop().RunUntilIdle(); 143 base::RunLoop().RunUntilIdle();
137 } 144 }
138 145
139 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) { 146 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) {
140 const int kFakeId = 222; 147 const int kFakeId = 222;
141 EXPECT_CALL(*this, 148 EXPECT_CALL(*this,
142 OnPickerDone(content::DesktopMediaID( 149 OnPickerDone(content::DesktopMediaID(
143 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); 150 content::DesktopMediaID::TYPE_WINDOW, kFakeId)));
144 151
145 media_list_->AddSource(kFakeId); 152 window_list_->AddSource(kFakeId);
146 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 153 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
147 details.set_tap_count(2); 154 details.set_tap_count(2);
148 ui::GestureEvent double_tap(10, 10, 0, base::TimeDelta(), details); 155 ui::GestureEvent double_tap(10, 10, 0, base::TimeDelta(), details);
149 156
150 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent( 157 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent(
151 &double_tap); 158 &double_tap);
152 base::RunLoop().RunUntilIdle(); 159 base::RunLoop().RunUntilIdle();
153 } 160 }
154 161
155 TEST_F(DesktopMediaPickerViewsTest, CancelButtonAlwaysEnabled) { 162 TEST_F(DesktopMediaPickerViewsTest, CancelButtonAlwaysEnabled) {
156 EXPECT_TRUE( 163 EXPECT_TRUE(
157 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); 164 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
158 } 165 }
159 166
160 // Verifies that the MediaSourceView is added or removed when |media_list_| is 167 // Verifies that the MediaSourceView is added or removed when |media_list_| is
161 // updated. 168 // updated.
162 TEST_F(DesktopMediaPickerViewsTest, AddAndRemoveMediaSource) { 169 TEST_F(DesktopMediaPickerViewsTest, AddAndRemoveMediaSource) {
163 // No media source at first. 170 // No media source at first.
164 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(0)); 171 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(0));
165 172
166 for (int i = 0; i < 3; ++i) { 173 for (int i = 0; i < 3; ++i) {
167 media_list_->AddSource(i); 174 window_list_->AddSource(i);
168 EXPECT_TRUE(GetPickerDialogView()->GetMediaSourceViewForTesting(i)); 175 EXPECT_TRUE(GetPickerDialogView()->GetMediaSourceViewForTesting(i));
169 } 176 }
170 177
171 for (int i = 2; i >= 0; --i) { 178 for (int i = 2; i >= 0; --i) {
172 media_list_->RemoveSource(i); 179 window_list_->RemoveSource(i);
173 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(i)); 180 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(i));
174 } 181 }
175 } 182 }
176 183
177 // Verifies that focusing the MediaSourceView marks it selected and the 184 // Verifies that focusing the MediaSourceView marks it selected and the
178 // original selected MediaSourceView gets unselected. 185 // original selected MediaSourceView gets unselected.
179 TEST_F(DesktopMediaPickerViewsTest, FocusMediaSourceViewToSelect) { 186 TEST_F(DesktopMediaPickerViewsTest, FocusMediaSourceViewToSelect) {
180 media_list_->AddSource(0); 187 window_list_->AddSource(0);
181 media_list_->AddSource(1); 188 window_list_->AddSource(1);
182 189
183 DesktopMediaSourceView* source_view_0 = 190 DesktopMediaSourceView* source_view_0 =
184 GetPickerDialogView()->GetMediaSourceViewForTesting(0); 191 GetPickerDialogView()->GetMediaSourceViewForTesting(0);
185 192
186 DesktopMediaSourceView* source_view_1 = 193 DesktopMediaSourceView* source_view_1 =
187 GetPickerDialogView()->GetMediaSourceViewForTesting(1); 194 GetPickerDialogView()->GetMediaSourceViewForTesting(1);
188 195
189 EXPECT_FALSE(source_view_0->is_selected()); 196 EXPECT_FALSE(source_view_0->is_selected());
190 EXPECT_FALSE(source_view_1->is_selected()); 197 EXPECT_FALSE(source_view_1->is_selected());
191 198
192 source_view_0->OnFocus(); 199 source_view_0->OnFocus();
193 EXPECT_TRUE(source_view_0->is_selected()); 200 EXPECT_TRUE(source_view_0->is_selected());
194 201
195 // Removing the focus does not undo the selection. 202 // Removing the focus does not undo the selection.
196 source_view_0->OnBlur(); 203 source_view_0->OnBlur();
197 EXPECT_TRUE(source_view_0->is_selected()); 204 EXPECT_TRUE(source_view_0->is_selected());
198 205
199 source_view_1->OnFocus(); 206 source_view_1->OnFocus();
200 EXPECT_FALSE(source_view_0->is_selected()); 207 EXPECT_FALSE(source_view_0->is_selected());
201 EXPECT_TRUE(source_view_1->is_selected()); 208 EXPECT_TRUE(source_view_1->is_selected());
202 } 209 }
203 210
204 TEST_F(DesktopMediaPickerViewsTest, OkButtonDisabledWhenNoSelection) { 211 TEST_F(DesktopMediaPickerViewsTest, OkButtonDisabledWhenNoSelection) {
205 media_list_->AddSource(111); 212 window_list_->AddSource(111);
206 213
207 EXPECT_FALSE( 214 EXPECT_FALSE(
208 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 215 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
209 216
210 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); 217 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus();
211 EXPECT_TRUE( 218 EXPECT_TRUE(
212 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 219 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
213 220
214 media_list_->RemoveSource(0); 221 window_list_->RemoveSource(0);
215 EXPECT_FALSE( 222 EXPECT_FALSE(
216 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 223 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
217 } 224 }
218 225
219 // Verifies that the MediaListView get the initial focus. 226 // Verifies that the MediaListView get the initial focus.
220 TEST_F(DesktopMediaPickerViewsTest, ListViewHasInitialFocus) { 227 TEST_F(DesktopMediaPickerViewsTest, ListViewHasInitialFocus) {
221 EXPECT_TRUE(GetPickerDialogView()->GetMediaListViewForTesting()->HasFocus()); 228 EXPECT_TRUE(GetPickerDialogView()->GetMediaListViewForTesting()->HasFocus());
222 } 229 }
223 230
224 } // namespace views 231 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698