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