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

Unified Diff: chrome/browser/ui/views/desktop_media_picker_views_unittest.cc

Issue 393653004: Add unit tests for DesktopMediaPickerViews. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/desktop_media_picker_views_unittest.cc
diff --git a/chrome/browser/ui/views/desktop_media_picker_views_unittest.cc b/chrome/browser/ui/views/desktop_media_picker_views_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c280ad2abec8e25ea1c8784179b3c267e1725ab0
--- /dev/null
+++ b/chrome/browser/ui/views/desktop_media_picker_views_unittest.cc
@@ -0,0 +1,181 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/media/fake_desktop_media_list.cc"
+#include "chrome/browser/ui/views/desktop_media_picker_views.h"
+#include "components/web_modal/test_web_contents_modal_dialog_host.h"
+#include "content/public/test/test_browser_thread.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "ui/aura/window.h"
+#include "ui/views/test/views_test_base.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/window/dialog_delegate.h"
+
+namespace views {
+
+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.
+
+class DesktopMediaPickerViewsTest : public ViewsTestBase {
+ public:
+ DesktopMediaPickerViewsTest()
+ : browser_ui_thread_(
+ 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
+ base::MessageLoop::current())) {}
+ virtual ~DesktopMediaPickerViewsTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ ViewsTestBase::SetUp();
+
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ parent_widget_.reset(new Widget);
+ parent_widget_->Init(params);
+
+ media_list_ = new FakeDesktopMediaList();
+ scoped_ptr<FakeDesktopMediaList> media_list(media_list_);
+
+ base::string16 app_name = base::ASCIIToUTF16(kFakeAppName);
+
+ picker_views_.reset(new DesktopMediaPickerViews());
+ picker_views_->Show(NULL,
+ NULL,
+ 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.
+ app_name,
+ app_name,
+ media_list.PassAs<DesktopMediaList>(),
+ base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone,
+ base::Unretained(this)));
+ }
+
+ DesktopMediaPickerDialogView* GetPickerDialogView() const {
+ return picker_views_->GetDialogViewForTesting();
+ }
+
+ 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
+
+ protected:
+ scoped_ptr<content::TestBrowserThread> browser_ui_thread_;
+ FakeDesktopMediaList* media_list_;
+ scoped_ptr<Widget> parent_widget_;
+ scoped_ptr<DesktopMediaPickerViews> picker_views_;
+};
+
+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.
+ EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID()));
+
+ delete GetPickerDialogView()->GetWidget()->GetNativeWindow();
+ RunPendingMessages();
+}
+
+TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnOkButtonPressed) {
+ const int kFakeId = 222;
+ EXPECT_CALL(*this,
+ OnPickerDone(content::DesktopMediaID(
+ content::DesktopMediaID::TYPE_WINDOW, kFakeId)));
+
+ media_list_->AddSource(kFakeId);
+
+ EXPECT_FALSE(
+ 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.
+
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus();
+ EXPECT_TRUE(
+ GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ GetPickerDialogView()->Accept();
+ RunPendingMessages();
+}
+
+TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleClick) {
+ const int kFakeId = 222;
+ EXPECT_CALL(*this,
+ OnPickerDone(content::DesktopMediaID(
+ content::DesktopMediaID::TYPE_WINDOW, kFakeId)));
+
+ media_list_->AddSource(kFakeId);
+
+ ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED,
+ gfx::Point(),
+ gfx::Point(),
+ ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
+ ui::EF_LEFT_MOUSE_BUTTON);
+
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnMousePressed(
+ double_click);
+ RunPendingMessages();
+}
+
+TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) {
+ const int kFakeId = 222;
+ EXPECT_CALL(*this,
+ OnPickerDone(content::DesktopMediaID(
+ content::DesktopMediaID::TYPE_WINDOW, kFakeId)));
+
+ media_list_->AddSource(kFakeId);
+
+ ui::GestureEvent double_tap(ui::ET_GESTURE_TAP,
+ 10,
+ 10,
+ 0,
+ base::TimeDelta(),
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP, 2, 0),
+ 1);
+
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent(
+ &double_tap);
+ RunPendingMessages();
+}
+
+TEST_F(DesktopMediaPickerViewsTest, CancelButtonAlwaysEnabled) {
+ EXPECT_TRUE(
+ GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
+}
+
+// Verifies that the MediaSourceView is added or removed when |media_list_| is
+// updated.
+TEST_F(DesktopMediaPickerViewsTest, AddAndRemoveMediaSource) {
+ // No media source at first.
+ EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(0));
+
+ for (int i = 0; i < 3; ++i) {
+ media_list_->AddSource(i);
+ EXPECT_TRUE(GetPickerDialogView()->GetMediaSourceViewForTesting(i));
+ }
+
+ for (int i = 2; i >= 0; --i) {
+ media_list_->RemoveSource(i);
+ EXPECT_EQ(NULL, GetPickerDialogView()->GetMediaSourceViewForTesting(i));
+ }
+}
+
+// Verifies that focusing the MediaSourceView marks it selected and the
+// original selected MediaSourceView gets unselected.
+TEST_F(DesktopMediaPickerViewsTest, FocusMediaSourceViewToSelect) {
+ media_list_->AddSource(0);
+ media_list_->AddSource(1);
+
+ DesktopMediaSourceView* source_view_0 =
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0);
+
+ DesktopMediaSourceView* source_view_1 =
+ GetPickerDialogView()->GetMediaSourceViewForTesting(1);
+
+ EXPECT_FALSE(source_view_0->is_selected());
+ EXPECT_FALSE(source_view_1->is_selected());
+
+ 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.
+ EXPECT_TRUE(source_view_0->is_selected());
+
+ // Removing the focus does not undo the selection.
+ source_view_0->OnBlur();
+ EXPECT_TRUE(source_view_0->is_selected());
+
+ source_view_1->OnFocus();
+ EXPECT_FALSE(source_view_0->is_selected());
+ EXPECT_TRUE(source_view_1->is_selected());
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698