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

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

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

Powered by Google App Engine
This is Rietveld 408576698