| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/core/contents/blimp_contents_manager.h" | 5 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
| 9 #include "blimp/client/core/contents/blimp_contents_impl.h" | 10 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 10 #include "blimp/client/core/contents/tab_control_feature.h" | 11 #include "blimp/client/core/contents/tab_control_feature.h" |
| 12 #include "blimp/client/core/render_widget/render_widget_feature.h" |
| 13 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 16 |
| 14 using testing::_; | 17 using testing::_; |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 const int kDummyTabId = 0; | 20 const int kDummyTabId = 0; |
| 18 } | 21 } |
| 19 | 22 |
| 20 namespace blimp { | 23 namespace blimp { |
| 21 namespace client { | 24 namespace client { |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 class MockTabControlFeature : public TabControlFeature { | 27 class MockTabControlFeature : public TabControlFeature { |
| 25 public: | 28 public: |
| 26 MockTabControlFeature() {} | 29 MockTabControlFeature() {} |
| 27 ~MockTabControlFeature() override = default; | 30 ~MockTabControlFeature() override = default; |
| 28 | 31 |
| 29 MOCK_METHOD1(CreateTab, void(int)); | 32 MOCK_METHOD1(CreateTab, void(int)); |
| 30 MOCK_METHOD1(CloseTab, void(int)); | 33 MOCK_METHOD1(CloseTab, void(int)); |
| 31 | 34 |
| 32 private: | 35 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); | 36 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); |
| 34 }; | 37 }; |
| 35 | 38 |
| 36 TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { | 39 TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { |
| 37 base::MessageLoop loop; | 40 base::MessageLoop loop; |
| 41 RenderWidgetFeature render_widget_feature; |
| 38 MockTabControlFeature tab_control_feature; | 42 MockTabControlFeature tab_control_feature; |
| 39 | 43 |
| 40 BlimpContentsManager blimp_contents_manager(nullptr, nullptr, | 44 BlimpCompositorDependencies compositor_deps( |
| 45 base::MakeUnique<MockCompositorDependencies>()); |
| 46 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, |
| 47 nullptr, &render_widget_feature, |
| 41 &tab_control_feature); | 48 &tab_control_feature); |
| 42 | 49 |
| 43 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); | 50 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); |
| 44 std::unique_ptr<BlimpContentsImpl> blimp_contents = | 51 std::unique_ptr<BlimpContentsImpl> blimp_contents = |
| 45 blimp_contents_manager.CreateBlimpContents(); | 52 blimp_contents_manager.CreateBlimpContents(); |
| 46 int id = blimp_contents->id(); | 53 int id = blimp_contents->id(); |
| 47 BlimpContentsImpl* existing_contents = | 54 BlimpContentsImpl* existing_contents = |
| 48 blimp_contents_manager.GetBlimpContents(id); | 55 blimp_contents_manager.GetBlimpContents(id); |
| 49 EXPECT_EQ(blimp_contents.get(), existing_contents); | 56 EXPECT_EQ(blimp_contents.get(), existing_contents); |
| 50 } | 57 } |
| 51 | 58 |
| 52 TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { | 59 TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { |
| 60 RenderWidgetFeature render_widget_feature; |
| 53 MockTabControlFeature tab_control_feature; | 61 MockTabControlFeature tab_control_feature; |
| 54 | 62 |
| 55 BlimpContentsManager blimp_contents_manager(nullptr, nullptr, | 63 BlimpCompositorDependencies compositor_deps( |
| 64 base::MakeUnique<MockCompositorDependencies>()); |
| 65 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, |
| 66 nullptr, &render_widget_feature, |
| 56 &tab_control_feature); | 67 &tab_control_feature); |
| 57 | 68 |
| 58 BlimpContentsImpl* existing_contents = | 69 BlimpContentsImpl* existing_contents = |
| 59 blimp_contents_manager.GetBlimpContents(kDummyTabId); | 70 blimp_contents_manager.GetBlimpContents(kDummyTabId); |
| 60 EXPECT_EQ(nullptr, existing_contents); | 71 EXPECT_EQ(nullptr, existing_contents); |
| 61 } | 72 } |
| 62 | 73 |
| 63 TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) { | 74 TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) { |
| 64 base::MessageLoop loop; | 75 base::MessageLoop loop; |
| 76 RenderWidgetFeature render_widget_feature; |
| 65 MockTabControlFeature tab_control_feature; | 77 MockTabControlFeature tab_control_feature; |
| 66 BlimpContentsManager blimp_contents_manager(nullptr, nullptr, | 78 BlimpCompositorDependencies compositor_deps( |
| 79 base::MakeUnique<MockCompositorDependencies>()); |
| 80 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, |
| 81 nullptr, &render_widget_feature, |
| 67 &tab_control_feature); | 82 &tab_control_feature); |
| 68 int id; | 83 int id; |
| 69 | 84 |
| 70 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); | 85 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); |
| 71 std::unique_ptr<BlimpContentsImpl> blimp_contents = | 86 std::unique_ptr<BlimpContentsImpl> blimp_contents = |
| 72 blimp_contents_manager.CreateBlimpContents(); | 87 blimp_contents_manager.CreateBlimpContents(); |
| 73 id = blimp_contents.get()->id(); | 88 id = blimp_contents.get()->id(); |
| 74 BlimpContentsImpl* existing_contents = | 89 BlimpContentsImpl* existing_contents = |
| 75 blimp_contents_manager.GetBlimpContents(id); | 90 blimp_contents_manager.GetBlimpContents(id); |
| 76 EXPECT_EQ(blimp_contents.get(), existing_contents); | 91 EXPECT_EQ(blimp_contents.get(), existing_contents); |
| 77 | 92 |
| 78 EXPECT_CALL(tab_control_feature, CloseTab(id)).Times(1); | 93 EXPECT_CALL(tab_control_feature, CloseTab(id)).Times(1); |
| 79 blimp_contents.reset(); | 94 blimp_contents.reset(); |
| 80 | 95 |
| 81 loop.RunUntilIdle(); | 96 loop.RunUntilIdle(); |
| 82 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id)); | 97 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id)); |
| 83 } | 98 } |
| 84 | 99 |
| 85 // TODO(mlliu): remove this test case (http://crbug.com/642558) | 100 // TODO(mlliu): remove this test case (http://crbug.com/642558) |
| 86 TEST(BlimpContentsManagerUnittest, CreateTwoBlimpContentsDestroyAndCreate) { | 101 TEST(BlimpContentsManagerUnittest, CreateTwoBlimpContentsDestroyAndCreate) { |
| 87 base::MessageLoop loop; | 102 base::MessageLoop loop; |
| 103 RenderWidgetFeature render_widget_feature; |
| 88 MockTabControlFeature tab_control_feature; | 104 MockTabControlFeature tab_control_feature; |
| 89 BlimpContentsManager blimp_contents_manager(nullptr, nullptr, | 105 BlimpCompositorDependencies compositor_deps( |
| 106 base::MakeUnique<MockCompositorDependencies>()); |
| 107 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, |
| 108 nullptr, &render_widget_feature, |
| 90 &tab_control_feature); | 109 &tab_control_feature); |
| 91 | 110 |
| 92 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(2); | 111 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(2); |
| 93 std::unique_ptr<BlimpContentsImpl> blimp_contents = | 112 std::unique_ptr<BlimpContentsImpl> blimp_contents = |
| 94 blimp_contents_manager.CreateBlimpContents(); | 113 blimp_contents_manager.CreateBlimpContents(); |
| 95 EXPECT_NE(blimp_contents, nullptr); | 114 EXPECT_NE(blimp_contents, nullptr); |
| 96 | 115 |
| 97 std::unique_ptr<BlimpContentsImpl> second_blimp_contents = | 116 std::unique_ptr<BlimpContentsImpl> second_blimp_contents = |
| 98 blimp_contents_manager.CreateBlimpContents(); | 117 blimp_contents_manager.CreateBlimpContents(); |
| 99 EXPECT_EQ(second_blimp_contents, nullptr); | 118 EXPECT_EQ(second_blimp_contents, nullptr); |
| 100 | 119 |
| 101 blimp_contents.reset(); | 120 blimp_contents.reset(); |
| 102 std::unique_ptr<BlimpContentsImpl> third_blimp_contents = | 121 std::unique_ptr<BlimpContentsImpl> third_blimp_contents = |
| 103 blimp_contents_manager.CreateBlimpContents(); | 122 blimp_contents_manager.CreateBlimpContents(); |
| 104 EXPECT_NE(third_blimp_contents, nullptr); | 123 EXPECT_NE(third_blimp_contents, nullptr); |
| 105 } | 124 } |
| 106 | 125 |
| 107 } // namespace | 126 } // namespace |
| 108 } // namespace client | 127 } // namespace client |
| 109 } // namespace blimp | 128 } // namespace blimp |
| OLD | NEW |