OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/client/core/contents/blimp_contents_manager.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/run_loop.h" | |
10 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | |
11 #include "blimp/client/core/contents/blimp_contents_impl.h" | |
12 #include "blimp/client/core/contents/ime_feature.h" | |
13 #include "blimp/client/core/contents/tab_control_feature.h" | |
14 #include "blimp/client/core/render_widget/render_widget_feature.h" | |
15 #include "blimp/client/test/compositor/mock_compositor_dependencies.h" | |
16 #include "testing/gmock/include/gmock/gmock.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 #include "ui/gfx/native_widget_types.h" | |
19 | |
20 #if defined(OS_ANDROID) | |
21 #include "ui/android/window_android.h" | |
22 #endif // defined(OS_ANDROID) | |
23 | |
24 using testing::_; | |
25 | |
26 namespace { | |
27 const int kDummyBlimpContentsId = 0; | |
28 } | |
29 | |
30 namespace blimp { | |
31 namespace client { | |
32 namespace { | |
33 | |
34 class MockTabControlFeature : public TabControlFeature { | |
35 public: | |
36 MockTabControlFeature() {} | |
37 ~MockTabControlFeature() override = default; | |
38 | |
39 MOCK_METHOD1(CreateTab, void(int)); | |
40 MOCK_METHOD1(CloseTab, void(int)); | |
41 | |
42 private: | |
43 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); | |
44 }; | |
45 | |
46 class BlimpContentsManagerTest : public testing::Test { | |
47 public: | |
48 BlimpContentsManagerTest() | |
49 : compositor_deps_(base::MakeUnique<MockCompositorDependencies>()), | |
50 blimp_contents_manager_(&compositor_deps_, | |
51 &ime_feature_, | |
52 nullptr, | |
53 &render_widget_feature_, | |
54 &tab_control_feature_) {} | |
55 | |
56 #if defined(OS_ANDROID) | |
57 void SetUp() override { window_ = ui::WindowAndroid::CreateForTesting(); } | |
58 | |
59 void TearDown() override { window_->DestroyForTesting(); } | |
60 #endif // defined(OS_ANDROID) | |
61 | |
62 protected: | |
63 gfx::NativeWindow window_ = nullptr; | |
64 | |
65 base::MessageLoop loop_; | |
66 ImeFeature ime_feature_; | |
67 RenderWidgetFeature render_widget_feature_; | |
68 MockTabControlFeature tab_control_feature_; | |
69 BlimpCompositorDependencies compositor_deps_; | |
70 BlimpContentsManager blimp_contents_manager_; | |
71 | |
72 private: | |
73 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManagerTest); | |
74 }; | |
75 | |
76 TEST_F(BlimpContentsManagerTest, GetExistingBlimpContents) { | |
77 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(1); | |
78 std::unique_ptr<BlimpContentsImpl> blimp_contents = | |
79 blimp_contents_manager_.CreateBlimpContents(window_); | |
80 int id = blimp_contents->id(); | |
81 BlimpContentsImpl* existing_contents = | |
82 blimp_contents_manager_.GetBlimpContents(id); | |
83 EXPECT_EQ(blimp_contents.get(), existing_contents); | |
84 } | |
85 | |
86 TEST_F(BlimpContentsManagerTest, GetNonExistingBlimpContents) { | |
87 BlimpContentsImpl* existing_contents = | |
88 blimp_contents_manager_.GetBlimpContents(kDummyBlimpContentsId); | |
89 EXPECT_EQ(nullptr, existing_contents); | |
90 } | |
91 | |
92 TEST_F(BlimpContentsManagerTest, GetDestroyedBlimpContents) { | |
93 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(1); | |
94 std::unique_ptr<BlimpContentsImpl> blimp_contents = | |
95 blimp_contents_manager_.CreateBlimpContents(window_); | |
96 int id = blimp_contents.get()->id(); | |
97 BlimpContentsImpl* existing_contents = | |
98 blimp_contents_manager_.GetBlimpContents(id); | |
99 EXPECT_EQ(blimp_contents.get(), existing_contents); | |
100 | |
101 EXPECT_CALL(tab_control_feature_, CloseTab(id)).Times(1); | |
102 blimp_contents.reset(); | |
103 | |
104 base::RunLoop().RunUntilIdle(); | |
105 EXPECT_EQ(nullptr, blimp_contents_manager_.GetBlimpContents(id)); | |
106 } | |
107 | |
108 // TODO(mlliu): Increase the number of BlimpContentsImpl in this test case. | |
109 // (See http://crbug.com/642558) | |
110 TEST_F(BlimpContentsManagerTest, RetrieveAllBlimpContents) { | |
111 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(1); | |
112 std::unique_ptr<BlimpContentsImpl> blimp_contents = | |
113 blimp_contents_manager_.CreateBlimpContents(window_); | |
114 int created_id = blimp_contents->id(); | |
115 | |
116 std::vector<BlimpContentsImpl*> all_blimp_contents = | |
117 blimp_contents_manager_.GetAllActiveBlimpContents(); | |
118 ASSERT_EQ(1U, all_blimp_contents.size()); | |
119 EXPECT_EQ(created_id, (*all_blimp_contents.begin())->id()); | |
120 } | |
121 | |
122 // TODO(mlliu): Increase the number of BlimpContentsImpl in this test case. | |
123 // (See http://crbug.com/642558) | |
124 TEST_F(BlimpContentsManagerTest, NoRetrievedBlimpContentsAreDestroyed) { | |
125 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(1); | |
126 std::unique_ptr<BlimpContentsImpl> blimp_contents = | |
127 blimp_contents_manager_.CreateBlimpContents(window_); | |
128 blimp_contents.reset(); | |
129 | |
130 std::vector<BlimpContentsImpl*> all_blimp_contents = | |
131 blimp_contents_manager_.GetAllActiveBlimpContents(); | |
132 EXPECT_EQ(0U, all_blimp_contents.size()); | |
133 } | |
134 | |
135 // TODO(mlliu): remove this test case (http://crbug.com/642558) | |
136 TEST_F(BlimpContentsManagerTest, CreateTwoBlimpContentsDestroyAndCreate) { | |
137 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(2); | |
138 std::unique_ptr<BlimpContentsImpl> blimp_contents = | |
139 blimp_contents_manager_.CreateBlimpContents(window_); | |
140 EXPECT_NE(blimp_contents, nullptr); | |
141 | |
142 std::unique_ptr<BlimpContentsImpl> second_blimp_contents = | |
143 blimp_contents_manager_.CreateBlimpContents(window_); | |
144 EXPECT_EQ(second_blimp_contents, nullptr); | |
145 | |
146 blimp_contents.reset(); | |
147 std::unique_ptr<BlimpContentsImpl> third_blimp_contents = | |
148 blimp_contents_manager_.CreateBlimpContents(window_); | |
149 EXPECT_NE(third_blimp_contents, nullptr); | |
150 } | |
151 | |
152 } // namespace | |
153 } // namespace client | |
154 } // namespace blimp | |
OLD | NEW |