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

Side by Side Diff: blimp/client/core/contents/blimp_contents_manager_unittest.cc

Issue 2371503002: Add Blimp feedback data about visible BlimpContents. (Closed)
Patch Set: Rebased for good measure Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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 "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" 10 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h"
(...skipping 13 matching lines...) Expand all
24 using testing::_; 24 using testing::_;
25 25
26 namespace { 26 namespace {
27 const int kDummyBlimpContentsId = 0; 27 const int kDummyBlimpContentsId = 0;
28 } 28 }
29 29
30 namespace blimp { 30 namespace blimp {
31 namespace client { 31 namespace client {
32 namespace { 32 namespace {
33 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
34 class BlimpContentsManagerTest : public testing::Test { 46 class BlimpContentsManagerTest : public testing::Test {
35 public: 47 public:
36 BlimpContentsManagerTest() = default; 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_) {}
37 55
38 #if defined(OS_ANDROID) 56 #if defined(OS_ANDROID)
39 void SetUp() override { window_ = ui::WindowAndroid::CreateForTesting(); } 57 void SetUp() override { window_ = ui::WindowAndroid::CreateForTesting(); }
40 58
41 void TearDown() override { window_->DestroyForTesting(); } 59 void TearDown() override { window_->DestroyForTesting(); }
42 #endif // defined(OS_ANDROID) 60 #endif // defined(OS_ANDROID)
43 61
44 protected: 62 protected:
45 gfx::NativeWindow window_ = nullptr; 63 gfx::NativeWindow window_ = nullptr;
46 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
47 private: 72 private:
48 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManagerTest); 73 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManagerTest);
49 }; 74 };
50 75
51 class MockTabControlFeature : public TabControlFeature {
52 public:
53 MockTabControlFeature() {}
54 ~MockTabControlFeature() override = default;
55
56 MOCK_METHOD1(CreateTab, void(int));
57 MOCK_METHOD1(CloseTab, void(int));
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature);
61 };
62
63 TEST_F(BlimpContentsManagerTest, GetExistingBlimpContents) { 76 TEST_F(BlimpContentsManagerTest, GetExistingBlimpContents) {
64 base::MessageLoop loop; 77 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(1);
65 ImeFeature ime_feature;
66 RenderWidgetFeature render_widget_feature;
67 MockTabControlFeature tab_control_feature;
68
69 BlimpCompositorDependencies compositor_deps(
70 base::MakeUnique<MockCompositorDependencies>());
71 BlimpContentsManager blimp_contents_manager(&compositor_deps, &ime_feature,
72 nullptr, &render_widget_feature,
73 &tab_control_feature);
74
75 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1);
76 std::unique_ptr<BlimpContentsImpl> blimp_contents = 78 std::unique_ptr<BlimpContentsImpl> blimp_contents =
77 blimp_contents_manager.CreateBlimpContents(window_); 79 blimp_contents_manager_.CreateBlimpContents(window_);
78 int id = blimp_contents->id(); 80 int id = blimp_contents->id();
79 BlimpContentsImpl* existing_contents = 81 BlimpContentsImpl* existing_contents =
80 blimp_contents_manager.GetBlimpContents(id); 82 blimp_contents_manager_.GetBlimpContents(id);
81 EXPECT_EQ(blimp_contents.get(), existing_contents); 83 EXPECT_EQ(blimp_contents.get(), existing_contents);
82 } 84 }
83 85
84 TEST_F(BlimpContentsManagerTest, GetNonExistingBlimpContents) { 86 TEST_F(BlimpContentsManagerTest, GetNonExistingBlimpContents) {
85 ImeFeature ime_feature;
86 RenderWidgetFeature render_widget_feature;
87 MockTabControlFeature tab_control_feature;
88
89 BlimpCompositorDependencies compositor_deps(
90 base::MakeUnique<MockCompositorDependencies>());
91 BlimpContentsManager blimp_contents_manager(&compositor_deps, &ime_feature,
92 nullptr, &render_widget_feature,
93 &tab_control_feature);
94
95 BlimpContentsImpl* existing_contents = 87 BlimpContentsImpl* existing_contents =
96 blimp_contents_manager.GetBlimpContents(kDummyBlimpContentsId); 88 blimp_contents_manager_.GetBlimpContents(kDummyBlimpContentsId);
97 EXPECT_EQ(nullptr, existing_contents); 89 EXPECT_EQ(nullptr, existing_contents);
98 } 90 }
99 91
100 TEST_F(BlimpContentsManagerTest, GetDestroyedBlimpContents) { 92 TEST_F(BlimpContentsManagerTest, GetDestroyedBlimpContents) {
101 base::MessageLoop loop; 93 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(1);
102 ImeFeature ime_feature;
103 RenderWidgetFeature render_widget_feature;
104 MockTabControlFeature tab_control_feature;
105 BlimpCompositorDependencies compositor_deps(
106 base::MakeUnique<MockCompositorDependencies>());
107 BlimpContentsManager blimp_contents_manager(&compositor_deps, &ime_feature,
108 nullptr, &render_widget_feature,
109 &tab_control_feature);
110 int id;
111
112 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1);
113 std::unique_ptr<BlimpContentsImpl> blimp_contents = 94 std::unique_ptr<BlimpContentsImpl> blimp_contents =
114 blimp_contents_manager.CreateBlimpContents(window_); 95 blimp_contents_manager_.CreateBlimpContents(window_);
115 id = blimp_contents.get()->id(); 96 int id = blimp_contents.get()->id();
116 BlimpContentsImpl* existing_contents = 97 BlimpContentsImpl* existing_contents =
117 blimp_contents_manager.GetBlimpContents(id); 98 blimp_contents_manager_.GetBlimpContents(id);
118 EXPECT_EQ(blimp_contents.get(), existing_contents); 99 EXPECT_EQ(blimp_contents.get(), existing_contents);
119 100
120 EXPECT_CALL(tab_control_feature, CloseTab(id)).Times(1); 101 EXPECT_CALL(tab_control_feature_, CloseTab(id)).Times(1);
121 blimp_contents.reset(); 102 blimp_contents.reset();
122 103
123 base::RunLoop().RunUntilIdle(); 104 base::RunLoop().RunUntilIdle();
124 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id)); 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());
125 } 133 }
126 134
127 // TODO(mlliu): remove this test case (http://crbug.com/642558) 135 // TODO(mlliu): remove this test case (http://crbug.com/642558)
128 TEST_F(BlimpContentsManagerTest, CreateTwoBlimpContentsDestroyAndCreate) { 136 TEST_F(BlimpContentsManagerTest, CreateTwoBlimpContentsDestroyAndCreate) {
129 base::MessageLoop loop; 137 EXPECT_CALL(tab_control_feature_, CreateTab(_)).Times(2);
130 ImeFeature ime_feature;
131 RenderWidgetFeature render_widget_feature;
132 MockTabControlFeature tab_control_feature;
133 BlimpCompositorDependencies compositor_deps(
134 base::MakeUnique<MockCompositorDependencies>());
135 BlimpContentsManager blimp_contents_manager(&compositor_deps, &ime_feature,
136 nullptr, &render_widget_feature,
137 &tab_control_feature);
138
139 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(2);
140 std::unique_ptr<BlimpContentsImpl> blimp_contents = 138 std::unique_ptr<BlimpContentsImpl> blimp_contents =
141 blimp_contents_manager.CreateBlimpContents(window_); 139 blimp_contents_manager_.CreateBlimpContents(window_);
142 EXPECT_NE(blimp_contents, nullptr); 140 EXPECT_NE(blimp_contents, nullptr);
143 141
144 std::unique_ptr<BlimpContentsImpl> second_blimp_contents = 142 std::unique_ptr<BlimpContentsImpl> second_blimp_contents =
145 blimp_contents_manager.CreateBlimpContents(window_); 143 blimp_contents_manager_.CreateBlimpContents(window_);
146 EXPECT_EQ(second_blimp_contents, nullptr); 144 EXPECT_EQ(second_blimp_contents, nullptr);
147 145
148 blimp_contents.reset(); 146 blimp_contents.reset();
149 std::unique_ptr<BlimpContentsImpl> third_blimp_contents = 147 std::unique_ptr<BlimpContentsImpl> third_blimp_contents =
150 blimp_contents_manager.CreateBlimpContents(window_); 148 blimp_contents_manager_.CreateBlimpContents(window_);
151 EXPECT_NE(third_blimp_contents, nullptr); 149 EXPECT_NE(third_blimp_contents, nullptr);
152 } 150 }
153 151
154 } // namespace 152 } // namespace
155 } // namespace client 153 } // namespace client
156 } // namespace blimp 154 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/contents/blimp_contents_manager.cc ('k') | blimp/client/core/feedback/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698