| 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.h" | 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h" |
| 6 | 6 |
| 7 #include <map> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/media/fake_desktop_media_list.h" | 13 #include "chrome/browser/media/fake_desktop_media_list.h" |
| 13 #include "components/web_modal/test_web_contents_modal_dialog_host.h" | 14 #include "components/web_modal/test_web_contents_modal_dialog_host.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 20 #include "ui/views/controls/button/checkbox.h" |
| 21 #include "ui/views/controls/button/label_button.h" |
| 19 #include "ui/views/test/scoped_views_test_helper.h" | 22 #include "ui/views/test/scoped_views_test_helper.h" |
| 20 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/window/dialog_client_view.h" | 24 #include "ui/views/window/dialog_client_view.h" |
| 22 #include "ui/views/window/dialog_delegate.h" | 25 #include "ui/views/window/dialog_delegate.h" |
| 23 | 26 |
| 27 using content::DesktopMediaID; |
| 28 |
| 24 namespace views { | 29 namespace views { |
| 30 const std::vector<DesktopMediaID::Type> kSourceTypes = { |
| 31 DesktopMediaID::TYPE_SCREEN, DesktopMediaID::TYPE_WINDOW, |
| 32 DesktopMediaID::TYPE_WEB_CONTENTS}; |
| 25 | 33 |
| 26 class DesktopMediaPickerViewsTest : public testing::Test { | 34 class DesktopMediaPickerViewsTest : public testing::Test { |
| 27 public: | 35 public: |
| 28 DesktopMediaPickerViewsTest() {} | 36 DesktopMediaPickerViewsTest() {} |
| 29 ~DesktopMediaPickerViewsTest() override {} | 37 ~DesktopMediaPickerViewsTest() override {} |
| 30 | 38 |
| 31 void SetUp() override { | 39 void SetUp() override { |
| 32 screen_list_ = new FakeDesktopMediaList(); | 40 media_lists_[DesktopMediaID::TYPE_SCREEN] = new FakeDesktopMediaList(); |
| 33 window_list_ = new FakeDesktopMediaList(); | 41 media_lists_[DesktopMediaID::TYPE_WINDOW] = new FakeDesktopMediaList(); |
| 34 tab_list_ = new FakeDesktopMediaList(); | 42 media_lists_[DesktopMediaID::TYPE_WEB_CONTENTS] = |
| 35 std::unique_ptr<FakeDesktopMediaList> screen_list(screen_list_); | 43 new FakeDesktopMediaList(); |
| 36 std::unique_ptr<FakeDesktopMediaList> window_list(window_list_); | 44 std::unique_ptr<FakeDesktopMediaList> screen_list( |
| 37 std::unique_ptr<FakeDesktopMediaList> tab_list(tab_list_); | 45 media_lists_[DesktopMediaID::TYPE_SCREEN]); |
| 46 std::unique_ptr<FakeDesktopMediaList> window_list( |
| 47 media_lists_[DesktopMediaID::TYPE_WINDOW]); |
| 48 std::unique_ptr<FakeDesktopMediaList> tab_list( |
| 49 media_lists_[DesktopMediaID::TYPE_WEB_CONTENTS]); |
| 38 | 50 |
| 39 base::string16 app_name = base::ASCIIToUTF16("foo"); | 51 base::string16 app_name = base::ASCIIToUTF16("foo"); |
| 40 | 52 |
| 41 picker_views_.reset(new DesktopMediaPickerViews()); | 53 picker_views_.reset(new DesktopMediaPickerViews()); |
| 42 picker_views_->Show(NULL, test_helper_.GetContext(), NULL, app_name, | 54 picker_views_->Show(NULL, test_helper_.GetContext(), NULL, app_name, |
| 43 app_name, std::move(screen_list), | 55 app_name, std::move(screen_list), |
| 44 std::move(window_list), std::move(tab_list), false, | 56 std::move(window_list), std::move(tab_list), true, |
| 45 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone, | 57 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone, |
| 46 base::Unretained(this))); | 58 base::Unretained(this))); |
| 47 } | 59 } |
| 48 | 60 |
| 49 void TearDown() override { | 61 void TearDown() override { |
| 50 if (GetPickerDialogView()) { | 62 if (GetPickerDialogView()) { |
| 51 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); | 63 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); |
| 52 GetPickerDialogView()->GetWidget()->CloseNow(); | 64 GetPickerDialogView()->GetWidget()->CloseNow(); |
| 53 } | 65 } |
| 54 } | 66 } |
| 55 | 67 |
| 56 DesktopMediaPickerDialogView* GetPickerDialogView() const { | 68 DesktopMediaPickerDialogView* GetPickerDialogView() const { |
| 57 return picker_views_->GetDialogViewForTesting(); | 69 return picker_views_->GetDialogViewForTesting(); |
| 58 } | 70 } |
| 59 | 71 |
| 72 bool ClickSourceTypeButton(DesktopMediaID::Type source_type) { |
| 73 LabelButton* button = |
| 74 GetPickerDialogView()->GetSourceTypeButtonForTesting(source_type); |
| 75 if (!button) |
| 76 return false; |
| 77 gfx::Rect bound = button->GetLocalBounds(); |
| 78 button->OnMouseReleased(ui::MouseEvent( |
| 79 ui::EventType::ET_MOUSE_RELEASED, gfx::Point(bound.x(), bound.y()), |
| 80 gfx::Point(bound.x(), bound.y()), base::TimeDelta(), |
| 81 ui::EventFlags::EF_LEFT_MOUSE_BUTTON, 0)); |
| 82 return true; |
| 83 } |
| 84 |
| 60 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID)); | 85 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID)); |
| 61 | 86 |
| 62 protected: | 87 protected: |
| 63 content::TestBrowserThreadBundle thread_bundle_; | 88 content::TestBrowserThreadBundle thread_bundle_; |
| 64 views::ScopedViewsTestHelper test_helper_; | 89 views::ScopedViewsTestHelper test_helper_; |
| 65 FakeDesktopMediaList* screen_list_; | 90 std::map<DesktopMediaID::Type, FakeDesktopMediaList*> media_lists_; |
| 66 FakeDesktopMediaList* window_list_; | |
| 67 FakeDesktopMediaList* tab_list_; | |
| 68 std::unique_ptr<DesktopMediaPickerViews> picker_views_; | 91 std::unique_ptr<DesktopMediaPickerViews> picker_views_; |
| 69 }; | 92 }; |
| 70 | 93 |
| 71 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) { | 94 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) { |
| 72 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); | 95 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); |
| 73 | 96 |
| 74 GetPickerDialogView()->GetWidget()->Close(); | 97 GetPickerDialogView()->GetWidget()->Close(); |
| 75 base::RunLoop().RunUntilIdle(); | 98 base::RunLoop().RunUntilIdle(); |
| 76 } | 99 } |
| 77 | 100 |
| 78 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnOkButtonPressed) { | 101 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnOkButtonPressed) { |
| 79 const int kFakeId = 222; | 102 const DesktopMediaID kFakeId(DesktopMediaID::TYPE_WINDOW, 222); |
| 80 EXPECT_CALL(*this, | 103 EXPECT_CALL(*this, OnPickerDone(kFakeId)); |
| 81 OnPickerDone(content::DesktopMediaID( | 104 |
| 82 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); | 105 media_lists_[DesktopMediaID::TYPE_WINDOW]->AddSourceByFullMediaID(kFakeId); |
| 83 window_list_->AddSource(kFakeId); | 106 GetPickerDialogView()->GetCheckboxForTesting()->SetChecked(true); |
| 84 | 107 |
| 85 EXPECT_FALSE( | 108 EXPECT_FALSE( |
| 86 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 109 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 87 | 110 |
| 111 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_WINDOW)); |
| 112 |
| 88 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); | 113 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); |
| 114 |
| 89 EXPECT_TRUE( | 115 EXPECT_TRUE( |
| 90 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 116 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 91 | 117 |
| 92 GetPickerDialogView()->GetDialogClientView()->AcceptWindow(); | 118 GetPickerDialogView()->GetDialogClientView()->AcceptWindow(); |
| 93 base::RunLoop().RunUntilIdle(); | 119 base::RunLoop().RunUntilIdle(); |
| 94 } | 120 } |
| 95 | 121 |
| 96 // Verifies that a MediaSourceView is selected with mouse left click and | 122 // Verifies that a MediaSourceView is selected with mouse left click and |
| 97 // original selected MediaSourceView gets unselected. | 123 // original selected MediaSourceView gets unselected. |
| 98 TEST_F(DesktopMediaPickerViewsTest, SelectMediaSourceViewOnSingleClick) { | 124 TEST_F(DesktopMediaPickerViewsTest, SelectMediaSourceViewOnSingleClick) { |
| 99 window_list_->AddSource(0); | 125 for (auto source_type : kSourceTypes) { |
| 100 window_list_->AddSource(1); | 126 EXPECT_TRUE(ClickSourceTypeButton(source_type)); |
| 127 media_lists_[source_type]->AddSource(0); |
| 128 media_lists_[source_type]->AddSource(1); |
| 101 | 129 |
| 102 DesktopMediaSourceView* source_view_0 = | 130 DesktopMediaSourceView* source_view_0 = |
| 103 GetPickerDialogView()->GetMediaSourceViewForTesting(0); | 131 GetPickerDialogView()->GetMediaSourceViewForTesting(0); |
| 104 | 132 |
| 105 DesktopMediaSourceView* source_view_1 = | 133 DesktopMediaSourceView* source_view_1 = |
| 106 GetPickerDialogView()->GetMediaSourceViewForTesting(1); | 134 GetPickerDialogView()->GetMediaSourceViewForTesting(1); |
| 107 | 135 |
| 108 // Both media source views are not selected initially. | 136 // Both media source views are not selected initially. |
| 109 EXPECT_FALSE(source_view_0->is_selected()); | 137 EXPECT_FALSE(source_view_0->is_selected()); |
| 110 EXPECT_FALSE(source_view_1->is_selected()); | 138 EXPECT_FALSE(source_view_1->is_selected()); |
| 111 | 139 |
| 112 // Source view 0 is selected with mouse click. | 140 // Source view 0 is selected with mouse click. |
| 113 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 141 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 114 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 142 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 115 | 143 |
| 116 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed(press); | 144 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed( |
| 145 press); |
| 117 | 146 |
| 118 EXPECT_TRUE(source_view_0->is_selected()); | 147 EXPECT_TRUE(source_view_0->is_selected()); |
| 119 EXPECT_FALSE(source_view_1->is_selected()); | 148 EXPECT_FALSE(source_view_1->is_selected()); |
| 120 | 149 |
| 121 // Source view 1 is selected and source view 0 is unselected with mouse click. | 150 // Source view 1 is selected and source view 0 is unselected with mouse |
| 122 GetPickerDialogView()->GetMediaSourceViewForTesting(1)->OnMousePressed(press); | 151 // click. |
| 152 GetPickerDialogView()->GetMediaSourceViewForTesting(1)->OnMousePressed( |
| 153 press); |
| 123 | 154 |
| 124 EXPECT_FALSE(source_view_0->is_selected()); | 155 EXPECT_FALSE(source_view_0->is_selected()); |
| 125 EXPECT_TRUE(source_view_1->is_selected()); | 156 EXPECT_TRUE(source_view_1->is_selected()); |
| 157 } |
| 126 } | 158 } |
| 127 | 159 |
| 128 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleClick) { | 160 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleClick) { |
| 129 const int kFakeId = 222; | 161 const DesktopMediaID kFakeId(DesktopMediaID::TYPE_WEB_CONTENTS, 222); |
| 130 EXPECT_CALL(*this, | 162 EXPECT_CALL(*this, OnPickerDone(kFakeId)); |
| 131 OnPickerDone(content::DesktopMediaID( | |
| 132 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); | |
| 133 | 163 |
| 134 window_list_->AddSource(kFakeId); | 164 media_lists_[DesktopMediaID::TYPE_WEB_CONTENTS]->AddSourceByFullMediaID( |
| 165 kFakeId); |
| 166 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_WEB_CONTENTS)); |
| 167 GetPickerDialogView()->GetCheckboxForTesting()->SetChecked(false); |
| 135 | 168 |
| 136 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 169 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 137 ui::EventTimeForNow(), | 170 ui::EventTimeForNow(), |
| 138 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, | 171 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
| 139 ui::EF_LEFT_MOUSE_BUTTON); | 172 ui::EF_LEFT_MOUSE_BUTTON); |
| 140 | 173 |
| 141 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed( | 174 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed( |
| 142 double_click); | 175 double_click); |
| 143 base::RunLoop().RunUntilIdle(); | 176 base::RunLoop().RunUntilIdle(); |
| 144 } | 177 } |
| 145 | 178 |
| 146 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) { | 179 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) { |
| 147 const int kFakeId = 222; | 180 const DesktopMediaID kFakeId(DesktopMediaID::TYPE_SCREEN, 222); |
| 148 EXPECT_CALL(*this, | 181 EXPECT_CALL(*this, OnPickerDone(kFakeId)); |
| 149 OnPickerDone(content::DesktopMediaID( | |
| 150 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); | |
| 151 | 182 |
| 152 window_list_->AddSource(kFakeId); | 183 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_SCREEN)); |
| 184 GetPickerDialogView()->GetCheckboxForTesting()->SetChecked(false); |
| 185 |
| 186 media_lists_[DesktopMediaID::TYPE_SCREEN]->AddSourceByFullMediaID(kFakeId); |
| 153 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); | 187 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); |
| 154 details.set_tap_count(2); | 188 details.set_tap_count(2); |
| 155 ui::GestureEvent double_tap(10, 10, 0, base::TimeDelta(), details); | 189 ui::GestureEvent double_tap(10, 10, 0, base::TimeDelta(), details); |
| 156 | 190 |
| 157 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent( | 191 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent( |
| 158 &double_tap); | 192 &double_tap); |
| 159 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
| 160 } | 194 } |
| 161 | 195 |
| 162 TEST_F(DesktopMediaPickerViewsTest, CancelButtonAlwaysEnabled) { | 196 TEST_F(DesktopMediaPickerViewsTest, CancelButtonAlwaysEnabled) { |
| 163 EXPECT_TRUE( | 197 EXPECT_TRUE( |
| 164 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 198 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
| 165 } | 199 } |
| 166 | 200 |
| 167 // Verifies that the MediaSourceView is added or removed when |media_list_| is | 201 // Verifies that the MediaSourceView is added or removed when |media_list_| is |
| 168 // updated. | 202 // updated. |
| 169 TEST_F(DesktopMediaPickerViewsTest, AddAndRemoveMediaSource) { | 203 TEST_F(DesktopMediaPickerViewsTest, AddAndRemoveMediaSource) { |
| 170 // No media source at first. | 204 for (auto source_type : kSourceTypes) { |
| 171 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(0)); | 205 EXPECT_TRUE(ClickSourceTypeButton(source_type)); |
| 206 // No media source at first. |
| 207 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(0)); |
| 172 | 208 |
| 173 for (int i = 0; i < 3; ++i) { | 209 for (int i = 0; i < 3; ++i) { |
| 174 window_list_->AddSource(i); | 210 media_lists_[source_type]->AddSourceByFullMediaID( |
| 175 EXPECT_TRUE(GetPickerDialogView()->GetMediaSourceViewForTesting(i)); | 211 DesktopMediaID(source_type, i)); |
| 176 } | 212 EXPECT_TRUE(GetPickerDialogView()->GetMediaSourceViewForTesting(i)); |
| 213 } |
| 177 | 214 |
| 178 for (int i = 2; i >= 0; --i) { | 215 for (int i = 2; i >= 0; --i) { |
| 179 window_list_->RemoveSource(i); | 216 media_lists_[source_type]->RemoveSource(i); |
| 180 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(i)); | 217 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(i)); |
| 218 } |
| 181 } | 219 } |
| 182 } | 220 } |
| 183 | 221 |
| 184 // Verifies that focusing the MediaSourceView marks it selected and the | 222 // Verifies that focusing the MediaSourceView marks it selected and the |
| 185 // original selected MediaSourceView gets unselected. | 223 // original selected MediaSourceView gets unselected. |
| 186 TEST_F(DesktopMediaPickerViewsTest, FocusMediaSourceViewToSelect) { | 224 TEST_F(DesktopMediaPickerViewsTest, FocusMediaSourceViewToSelect) { |
| 187 window_list_->AddSource(0); | 225 for (auto source_type : kSourceTypes) { |
| 188 window_list_->AddSource(1); | 226 ClickSourceTypeButton(source_type); |
| 227 media_lists_[source_type]->AddSourceByFullMediaID( |
| 228 DesktopMediaID(source_type, 0)); |
| 229 media_lists_[source_type]->AddSourceByFullMediaID( |
| 230 DesktopMediaID(source_type, 1)); |
| 189 | 231 |
| 190 DesktopMediaSourceView* source_view_0 = | 232 DesktopMediaSourceView* source_view_0 = |
| 191 GetPickerDialogView()->GetMediaSourceViewForTesting(0); | 233 GetPickerDialogView()->GetMediaSourceViewForTesting(0); |
| 192 | 234 |
| 193 DesktopMediaSourceView* source_view_1 = | 235 DesktopMediaSourceView* source_view_1 = |
| 194 GetPickerDialogView()->GetMediaSourceViewForTesting(1); | 236 GetPickerDialogView()->GetMediaSourceViewForTesting(1); |
| 195 | 237 |
| 196 EXPECT_FALSE(source_view_0->is_selected()); | 238 // Default choose the first screen for screen share. |
| 197 EXPECT_FALSE(source_view_1->is_selected()); | 239 if (source_type == DesktopMediaID::TYPE_SCREEN) { |
| 240 EXPECT_TRUE(source_view_0->is_selected()); |
| 241 } else { |
| 242 EXPECT_FALSE(source_view_0->is_selected()); |
| 243 } |
| 244 EXPECT_FALSE(source_view_1->is_selected()); |
| 198 | 245 |
| 199 source_view_0->OnFocus(); | 246 source_view_0->OnFocus(); |
| 200 EXPECT_TRUE(source_view_0->is_selected()); | 247 EXPECT_TRUE(source_view_0->is_selected()); |
| 201 | 248 |
| 202 // Removing the focus does not undo the selection. | 249 // Removing the focus does not undo the selection. |
| 203 source_view_0->OnBlur(); | 250 source_view_0->OnBlur(); |
| 204 EXPECT_TRUE(source_view_0->is_selected()); | 251 EXPECT_TRUE(source_view_0->is_selected()); |
| 205 | 252 |
| 206 source_view_1->OnFocus(); | 253 source_view_1->OnFocus(); |
| 207 EXPECT_FALSE(source_view_0->is_selected()); | 254 EXPECT_FALSE(source_view_0->is_selected()); |
| 208 EXPECT_TRUE(source_view_1->is_selected()); | 255 EXPECT_TRUE(source_view_1->is_selected()); |
| 256 } |
| 209 } | 257 } |
| 210 | 258 |
| 211 TEST_F(DesktopMediaPickerViewsTest, OkButtonDisabledWhenNoSelection) { | 259 TEST_F(DesktopMediaPickerViewsTest, OkButtonDisabledWhenNoSelection) { |
| 212 window_list_->AddSource(111); | 260 for (auto source_type : kSourceTypes) { |
| 261 EXPECT_TRUE(ClickSourceTypeButton(source_type)); |
| 262 media_lists_[source_type]->AddSourceByFullMediaID( |
| 263 DesktopMediaID(source_type, 111)); |
| 213 | 264 |
| 214 EXPECT_FALSE( | 265 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); |
| 215 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 266 EXPECT_TRUE( |
| 267 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 216 | 268 |
| 217 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); | 269 media_lists_[source_type]->RemoveSource(0); |
| 218 EXPECT_TRUE( | 270 EXPECT_FALSE( |
| 219 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 271 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 220 | 272 } |
| 221 window_list_->RemoveSource(0); | |
| 222 EXPECT_FALSE( | |
| 223 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | |
| 224 } | 273 } |
| 225 | 274 |
| 226 // Verifies that the MediaListView get the initial focus. | 275 // Verifies that the MediaListView get the initial focus. |
| 227 TEST_F(DesktopMediaPickerViewsTest, ListViewHasInitialFocus) { | 276 TEST_F(DesktopMediaPickerViewsTest, ListViewHasInitialFocus) { |
| 228 EXPECT_TRUE(GetPickerDialogView()->GetMediaListViewForTesting()->HasFocus()); | 277 EXPECT_TRUE(GetPickerDialogView()->GetMediaListViewForTesting()->HasFocus()); |
| 229 } | 278 } |
| 230 | 279 |
| 280 // Verifies the visible status of audio checkbox. |
| 281 TEST_F(DesktopMediaPickerViewsTest, AudioCheckboxState) { |
| 282 bool expect_value; |
| 283 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_SCREEN)); |
| 284 #if defined(OS_WIN) || defined(USE_CRAS) |
| 285 expect_value = true; |
| 286 #else |
| 287 expect_value = false; |
| 288 #endif |
| 289 EXPECT_EQ(expect_value, |
| 290 GetPickerDialogView()->GetCheckboxForTesting()->visible()); |
| 291 |
| 292 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_WINDOW)); |
| 293 EXPECT_EQ(false, GetPickerDialogView()->GetCheckboxForTesting()->visible()); |
| 294 |
| 295 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_WEB_CONTENTS)); |
| 296 EXPECT_EQ(true, GetPickerDialogView()->GetCheckboxForTesting()->visible()); |
| 297 } |
| 298 |
| 299 // Verifies that audio share information is recorded in the ID if the checkbox |
| 300 // is checked. |
| 301 TEST_F(DesktopMediaPickerViewsTest, DoneWithAudioShare) { |
| 302 DesktopMediaID originId(DesktopMediaID::TYPE_WEB_CONTENTS, 222); |
| 303 DesktopMediaID returnId = originId; |
| 304 returnId.audio_share = true; |
| 305 |
| 306 // It is also the real workflow when a source is generated in media_list, |
| 307 // its |audio_share| bit is not set. The bit is set by the picker UI if the |
| 308 // audio checkbox is checked. |
| 309 EXPECT_CALL(*this, OnPickerDone(returnId)); |
| 310 media_lists_[DesktopMediaID::TYPE_WEB_CONTENTS]->AddSourceByFullMediaID( |
| 311 originId); |
| 312 |
| 313 EXPECT_TRUE(ClickSourceTypeButton(DesktopMediaID::TYPE_WEB_CONTENTS)); |
| 314 GetPickerDialogView()->GetCheckboxForTesting()->SetChecked(true); |
| 315 |
| 316 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 317 ui::EventTimeForNow(), |
| 318 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
| 319 ui::EF_LEFT_MOUSE_BUTTON); |
| 320 |
| 321 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed( |
| 322 double_click); |
| 323 base::RunLoop().RunUntilIdle(); |
| 324 } |
| 325 |
| 231 } // namespace views | 326 } // namespace views |
| OLD | NEW |