| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/media/fake_desktop_media_list.h" | 8 #include "chrome/browser/media/fake_desktop_media_list.h" |
| 9 #include "chrome/browser/ui/views/desktop_media_picker_views.h" | 9 #include "chrome/browser/ui/views/desktop_media_picker_views.h" |
| 10 #include "components/web_modal/test_web_contents_modal_dialog_host.h" | 10 #include "components/web_modal/test_web_contents_modal_dialog_host.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" | 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/compositor/test/context_factories_for_test.h" | |
| 16 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 17 #include "ui/views/test/views_test_helper.h" | 16 #include "ui/views/test/scoped_views_test_helper.h" |
| 18 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/window/dialog_delegate.h" | 18 #include "ui/views/window/dialog_delegate.h" |
| 20 | 19 |
| 21 namespace views { | 20 namespace views { |
| 22 | 21 |
| 23 class DesktopMediaPickerViewsTest : public testing::Test { | 22 class DesktopMediaPickerViewsTest : public testing::Test { |
| 24 public: | 23 public: |
| 25 DesktopMediaPickerViewsTest() {} | 24 DesktopMediaPickerViewsTest() {} |
| 26 ~DesktopMediaPickerViewsTest() override {} | 25 ~DesktopMediaPickerViewsTest() override {} |
| 27 | 26 |
| 28 void SetUp() override { | 27 void SetUp() override { |
| 29 bool enable_pixel_output = false; | |
| 30 ui::ContextFactory* context_factory = | |
| 31 ui::InitializeContextFactoryForTests(enable_pixel_output); | |
| 32 test_helper_.reset( | |
| 33 ViewsTestHelper::Create(base::MessageLoopForUI::current(), | |
| 34 context_factory)); | |
| 35 test_helper_->SetUp(); | |
| 36 | |
| 37 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 28 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 38 params.context = test_helper_->GetContext(); | 29 params.context = test_helper_.GetContext(); |
| 39 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 30 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 40 parent_widget_.reset(new Widget); | 31 parent_widget_.reset(new Widget); |
| 41 parent_widget_->Init(params); | 32 parent_widget_->Init(params); |
| 42 | 33 |
| 43 media_list_ = new FakeDesktopMediaList(); | 34 media_list_ = new FakeDesktopMediaList(); |
| 44 scoped_ptr<FakeDesktopMediaList> media_list(media_list_); | 35 scoped_ptr<FakeDesktopMediaList> media_list(media_list_); |
| 45 | 36 |
| 46 base::string16 app_name = base::ASCIIToUTF16("foo"); | 37 base::string16 app_name = base::ASCIIToUTF16("foo"); |
| 47 | 38 |
| 48 picker_views_.reset(new DesktopMediaPickerViews()); | 39 picker_views_.reset(new DesktopMediaPickerViews()); |
| 49 picker_views_->Show(NULL, | 40 picker_views_->Show(NULL, |
| 50 parent_widget_->GetNativeWindow(), | 41 parent_widget_->GetNativeWindow(), |
| 51 NULL, | 42 NULL, |
| 52 app_name, | 43 app_name, |
| 53 app_name, | 44 app_name, |
| 54 media_list.Pass(), | 45 media_list.Pass(), |
| 55 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone, | 46 base::Bind(&DesktopMediaPickerViewsTest::OnPickerDone, |
| 56 base::Unretained(this))); | 47 base::Unretained(this))); |
| 57 } | 48 } |
| 58 | 49 |
| 59 void TearDown() override { | |
| 60 test_helper_->TearDown(); | |
| 61 ui::TerminateContextFactoryForTests(); | |
| 62 } | |
| 63 | |
| 64 DesktopMediaPickerDialogView* GetPickerDialogView() const { | 50 DesktopMediaPickerDialogView* GetPickerDialogView() const { |
| 65 return picker_views_->GetDialogViewForTesting(); | 51 return picker_views_->GetDialogViewForTesting(); |
| 66 } | 52 } |
| 67 | 53 |
| 68 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID)); | 54 MOCK_METHOD1(OnPickerDone, void(content::DesktopMediaID)); |
| 69 | 55 |
| 70 protected: | 56 protected: |
| 71 content::TestBrowserThreadBundle thread_bundle_; | 57 content::TestBrowserThreadBundle thread_bundle_; |
| 72 scoped_ptr<views::ViewsTestHelper> test_helper_; | 58 views::ScopedViewsTestHelper test_helper_; |
| 73 FakeDesktopMediaList* media_list_; | 59 FakeDesktopMediaList* media_list_; |
| 74 scoped_ptr<Widget> parent_widget_; | 60 scoped_ptr<Widget> parent_widget_; |
| 75 scoped_ptr<DesktopMediaPickerViews> picker_views_; | 61 scoped_ptr<DesktopMediaPickerViews> picker_views_; |
| 76 }; | 62 }; |
| 77 | 63 |
| 78 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) { | 64 TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledWhenWindowClosed) { |
| 79 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); | 65 EXPECT_CALL(*this, OnPickerDone(content::DesktopMediaID())); |
| 80 | 66 |
| 81 GetPickerDialogView()->GetWidget()->Close(); | 67 GetPickerDialogView()->GetWidget()->Close(); |
| 82 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); | 179 GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnFocus(); |
| 194 EXPECT_TRUE( | 180 EXPECT_TRUE( |
| 195 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 181 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 196 | 182 |
| 197 media_list_->RemoveSource(0); | 183 media_list_->RemoveSource(0); |
| 198 EXPECT_FALSE( | 184 EXPECT_FALSE( |
| 199 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 185 GetPickerDialogView()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 200 } | 186 } |
| 201 | 187 |
| 202 } // namespace views | 188 } // namespace views |
| OLD | NEW |