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

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
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..268435d2aeefc88a29626ca05489113d007edfac
--- /dev/null
+++ b/chrome/browser/ui/views/desktop_media_picker_views_unittest.cc
@@ -0,0 +1,206 @@
+// 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/run_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/media/fake_desktop_media_list.h"
+#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_bundle.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/aura/window.h"
+#include "ui/compositor/test/context_factories_for_test.h"
+#include "ui/views/test/views_test_helper.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/window/dialog_delegate.h"
+
+namespace views {
+
+class DesktopMediaPickerViewsTest : public testing::Test {
+ public:
+ DesktopMediaPickerViewsTest() {}
+ virtual ~DesktopMediaPickerViewsTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ bool enable_pixel_output = false;
+ ui::ContextFactory* context_factory =
+ ui::InitializeContextFactoryForTests(enable_pixel_output);
+ test_helper_.reset(
+ ViewsTestHelper::Create(base::MessageLoopForUI::current(),
+ context_factory));
+ test_helper_->SetUp();
+
+ Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
+ params.context = test_helper_->GetContext();
+ 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("foo");
+
+ picker_views_.reset(new DesktopMediaPickerViews());
+ picker_views_->Show(NULL,
+ NULL,
+ parent_widget_->GetNativeWindow(),
+ app_name,
+ app_name,
+ media_list.PassAs<DesktopMediaList>(),
+ base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone,
+ base::Unretained(this)));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ test_helper_->TearDown();
+ ui::TerminateContextFactoryForTests();
+ }
+
+ DesktopMediaPickerDialogView* GetPickerDialogView() const {
+ return picker_views_->GetDialogViewForTesting();
+ }
+
+ MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID));
+
+ protected:
+ content::TestBrowserThreadBundle thread_bundle_;
+ scoped_ptr<views::ViewsTestHelper> test_helper_;
+ FakeDesktopMediaList* media_list_;
+ scoped_ptr<Widget> parent_widget_;
+ scoped_ptr<DesktopMediaPickerViews> picker_views_;
+};
+
+TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) {
+ EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID()));
+
+ GetPickerDialogView()->GetWidget()->Close();
+ base::RunLoop().RunUntilIdle();
+}
+
+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));
+
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus();
+ EXPECT_TRUE(
+ GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ GetPickerDialogView()->Accept();
+ base::RunLoop().RunUntilIdle();
+}
+
+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);
+ base::RunLoop().RunUntilIdle();
+}
+
+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(
+ 10,
+ 10,
+ 0,
+ base::TimeDelta(),
+ ui::GestureEventDetails(ui::ET_GESTURE_TAP, 2, 0));
+
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent(
+ &double_tap);
+ base::RunLoop().RunUntilIdle();
+}
+
+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();
+ 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());
+}
+
+TEST_F(DesktopMediaPickerViewsTest, OkButtonDisabledWhenNoSelection) {
+ media_list_->AddSource(111);
+
+ EXPECT_FALSE(
+ GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus();
+ EXPECT_TRUE(
+ GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+
+ media_list_->RemoveSource(0);
+ EXPECT_FALSE(
+ GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
+}
+
+} // namespace views
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698