Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/bind.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "chrome/browser/media/fake_desktop_media_list.cc" | |
| 8 #include "chrome/browser/ui/views/desktop_media_picker_views.h" | |
| 9 #include "components/web_modal/test_web_contents_modal_dialog_host.h" | |
| 10 #include "content/public/test/test_browser_thread.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "ui/aura/window.h" | |
| 13 #include "ui/views/test/views_test_base.h" | |
| 14 #include "ui/views/widget/widget.h" | |
| 15 #include "ui/views/window/dialog_delegate.h" | |
| 16 | |
| 17 namespace views { | |
| 18 | |
| 19 static const char* kFakeAppName = "foo"; | |
|
msw
2014/07/15 03:29:56
nit: inline this in SetUp: base::string16 app_name
jiayl
2014/07/15 16:59:43
Done.
| |
| 20 | |
| 21 class DesktopMediaPickerViewsTest : public ViewsTestBase { | |
| 22 public: | |
| 23 DesktopMediaPickerViewsTest() | |
| 24 : browser_ui_thread_( | |
| 25 new content::TestBrowserThread(content::BrowserThread::UI, | |
|
msw
2014/07/15 03:29:56
Supposedly this is "DEPRECATED: use TestBrowserThr
jiayl
2014/07/15 16:59:43
TestBrowserThreadBundle does not work here, becaus
msw
2014/07/15 18:59:58
Please ping a reviewer knowledgeable about that de
jiayl
2014/07/15 19:22:39
I removed the use of TestBrowserThread by removing
| |
| 26 base::MessageLoop::current())) {} | |
| 27 virtual ~DesktopMediaPickerViewsTest() {} | |
| 28 | |
| 29 virtual void SetUp() OVERRIDE { | |
| 30 ViewsTestBase::SetUp(); | |
| 31 | |
| 32 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 33 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 34 parent_widget_.reset(new Widget); | |
| 35 parent_widget_->Init(params); | |
| 36 | |
| 37 media_list_ = new FakeDesktopMediaList(); | |
| 38 scoped_ptr<FakeDesktopMediaList> media_list(media_list_); | |
| 39 | |
| 40 base::string16 app_name = base::ASCIIToUTF16(kFakeAppName); | |
| 41 | |
| 42 picker_views_.reset(new DesktopMediaPickerViews()); | |
| 43 picker_views_->Show(NULL, | |
| 44 NULL, | |
| 45 parent_widget_->GetNativeWindow(), | |
|
msw
2014/07/15 03:29:56
Would DesktopMediaPickerViews work okay if you jus
jiayl
2014/07/15 16:59:43
No, it will fire an assert in creating the widget.
msw
2014/07/15 18:59:58
Acknowledged.
| |
| 46 app_name, | |
| 47 app_name, | |
| 48 media_list.PassAs<DesktopMediaList>(), | |
| 49 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone, | |
| 50 base::Unretained(this))); | |
| 51 } | |
| 52 | |
| 53 DesktopMediaPickerDialogView* GetPickerDialogView() const { | |
| 54 return picker_views_->GetDialogViewForTesting(); | |
| 55 } | |
| 56 | |
| 57 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID)); | |
|
msw
2014/07/15 03:29:56
Hmm, I've been discouraged from using MOCK_METHOD*
jiayl
2014/07/15 16:59:43
Why? MOCK_METHOD seems a cleaner solution.
msw
2014/07/15 18:59:58
I don't recall the concerns, so I won't advocate f
| |
| 58 | |
| 59 protected: | |
| 60 scoped_ptr<content::TestBrowserThread> browser_ui_thread_; | |
| 61 FakeDesktopMediaList* media_list_; | |
| 62 scoped_ptr<Widget> parent_widget_; | |
| 63 scoped_ptr<DesktopMediaPickerViews> picker_views_; | |
| 64 }; | |
| 65 | |
| 66 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowDeleted) { | |
|
msw
2014/07/15 03:29:56
This seems odd, why do we need a test for this? Pe
jiayl
2014/07/15 16:59:43
Done.
| |
| 67 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); | |
| 68 | |
| 69 delete GetPickerDialogView()->GetWidget()->GetNativeWindow(); | |
| 70 RunPendingMessages(); | |
| 71 } | |
| 72 | |
| 73 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnOkButtonPressed) { | |
| 74 const int kFakeId = 222; | |
| 75 EXPECT_CALL(*this, | |
| 76 OnPickerDone(content::DesktopMediaID( | |
| 77 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); | |
| 78 | |
| 79 media_list_->AddSource(kFakeId); | |
| 80 | |
| 81 EXPECT_FALSE( | |
| 82 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | |
|
Sergey Ulanov
2014/07/15 00:28:16
I think it's also good idea to verify that OK butt
jiayl
2014/07/15 16:59:42
Done.
| |
| 83 | |
| 84 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); | |
| 85 EXPECT_TRUE( | |
| 86 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | |
| 87 | |
| 88 GetPickerDialogView()->Accept(); | |
| 89 RunPendingMessages(); | |
| 90 } | |
| 91 | |
| 92 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleClick) { | |
| 93 const int kFakeId = 222; | |
| 94 EXPECT_CALL(*this, | |
| 95 OnPickerDone(content::DesktopMediaID( | |
| 96 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); | |
| 97 | |
| 98 media_list_->AddSource(kFakeId); | |
| 99 | |
| 100 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, | |
| 101 gfx::Point(), | |
| 102 gfx::Point(), | |
| 103 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, | |
| 104 ui::EF_LEFT_MOUSE_BUTTON); | |
| 105 | |
| 106 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed( | |
| 107 double_click); | |
| 108 RunPendingMessages(); | |
| 109 } | |
| 110 | |
| 111 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) { | |
| 112 const int kFakeId = 222; | |
| 113 EXPECT_CALL(*this, | |
| 114 OnPickerDone(content::DesktopMediaID( | |
| 115 content::DesktopMediaID::TYPE_WINDOW, kFakeId))); | |
| 116 | |
| 117 media_list_->AddSource(kFakeId); | |
| 118 | |
| 119 ui::GestureEvent double_tap(ui::ET_GESTURE_TAP, | |
| 120 10, | |
| 121 10, | |
| 122 0, | |
| 123 base::TimeDelta(), | |
| 124 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 2, 0), | |
| 125 1); | |
| 126 | |
| 127 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent( | |
| 128 &double_tap); | |
| 129 RunPendingMessages(); | |
| 130 } | |
| 131 | |
| 132 TEST_F(DesktopMediaPickerViewsTest, CancelButtonAlwaysEnabled) { | |
| 133 EXPECT_TRUE( | |
| 134 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | |
| 135 } | |
| 136 | |
| 137 // Verifies that the MediaSourceView is added or removed when |media_list_| is | |
| 138 // updated. | |
| 139 TEST_F(DesktopMediaPickerViewsTest, AddAndRemoveMediaSource) { | |
| 140 // No media source at first. | |
| 141 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(0)); | |
| 142 | |
| 143 for (int i = 0; i < 3; ++i) { | |
| 144 media_list_->AddSource(i); | |
| 145 EXPECT_TRUE(GetPickerDialogView()->GetMediaSourceViewForTesting(i)); | |
| 146 } | |
| 147 | |
| 148 for (int i = 2; i >= 0; --i) { | |
| 149 media_list_->RemoveSource(i); | |
| 150 EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(i)); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 // Verifies that focusing the MediaSourceView marks it selected and the | |
| 155 // original selected MediaSourceView gets unselected. | |
| 156 TEST_F(DesktopMediaPickerViewsTest, FocusMediaSourceViewToSelect) { | |
| 157 media_list_->AddSource(0); | |
| 158 media_list_->AddSource(1); | |
| 159 | |
| 160 DesktopMediaSourceView* source_view_0 = | |
| 161 GetPickerDialogView()->GetMediaSourceViewForTesting(0); | |
| 162 | |
| 163 DesktopMediaSourceView* source_view_1 = | |
| 164 GetPickerDialogView()->GetMediaSourceViewForTesting(1); | |
| 165 | |
| 166 EXPECT_FALSE(source_view_0->is_selected()); | |
| 167 EXPECT_FALSE(source_view_1->is_selected()); | |
| 168 | |
| 169 source_view_0->OnFocus(); | |
|
msw
2014/07/15 03:29:56
Any tests involving focus or activation should be
jiayl
2014/07/15 16:59:42
It does not depends on the actual UI focus. We onl
msw
2014/07/15 18:59:58
Acknowledged.
| |
| 170 EXPECT_TRUE(source_view_0->is_selected()); | |
| 171 | |
| 172 // Removing the focus does not undo the selection. | |
| 173 source_view_0->OnBlur(); | |
| 174 EXPECT_TRUE(source_view_0->is_selected()); | |
| 175 | |
| 176 source_view_1->OnFocus(); | |
| 177 EXPECT_FALSE(source_view_0->is_selected()); | |
| 178 EXPECT_TRUE(source_view_1->is_selected()); | |
| 179 } | |
| 180 | |
| 181 } // namespace views | |
| OLD | NEW |