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

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

Issue 2270323004: Add BlimpView to a Chrome tab when Blimp is enabled. (Closed)
Patch Set: addressed nit, renamed CreateForTesting and piped through touch handling Created 4 years, 3 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 "blimp/client/core/compositor/blimp_compositor_dependencies.h" 9 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h"
10 #include "blimp/client/core/contents/blimp_contents_impl.h" 10 #include "blimp/client/core/contents/blimp_contents_impl.h"
11 #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" 12 #include "blimp/client/core/render_widget/render_widget_feature.h"
13 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" 13 #include "blimp/client/support/compositor/mock_compositor_dependencies.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/native_widget_types.h"
17
18 #if defined(OS_ANDROID)
19 #include "ui/android/window_android.h"
20 #endif // defined(OS_ANDROID)
16 21
17 using testing::_; 22 using testing::_;
18 23
19 namespace { 24 namespace {
20 const int kDummyTabId = 0; 25 const int kDummyTabId = 0;
21 } 26 }
22 27
23 namespace blimp { 28 namespace blimp {
24 namespace client { 29 namespace client {
25 namespace { 30 namespace {
26 31
32 class BlimpContentsManagerTest : public testing::Test {
33 public:
34 BlimpContentsManagerTest() = default;
35
36 #if defined(OS_ANDROID)
37 void SetUp() override { window_ = ui::WindowAndroid::CreateForTesting(); }
38
39 void TearDown() override { window_->DestroyForTesting(); }
40 #endif // defined(OS_ANDROID)
41
42 protected:
43 gfx::NativeWindow window_ = nullptr;
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManagerTest);
47 };
48
27 class MockTabControlFeature : public TabControlFeature { 49 class MockTabControlFeature : public TabControlFeature {
28 public: 50 public:
29 MockTabControlFeature() {} 51 MockTabControlFeature() {}
30 ~MockTabControlFeature() override = default; 52 ~MockTabControlFeature() override = default;
31 53
32 MOCK_METHOD1(CreateTab, void(int)); 54 MOCK_METHOD1(CreateTab, void(int));
33 MOCK_METHOD1(CloseTab, void(int)); 55 MOCK_METHOD1(CloseTab, void(int));
34 56
35 private: 57 private:
36 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); 58 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature);
37 }; 59 };
38 60
39 TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { 61 TEST_F(BlimpContentsManagerTest, GetExistingBlimpContents) {
40 base::MessageLoop loop; 62 base::MessageLoop loop;
41 RenderWidgetFeature render_widget_feature; 63 RenderWidgetFeature render_widget_feature;
42 MockTabControlFeature tab_control_feature; 64 MockTabControlFeature tab_control_feature;
43 65
44 BlimpCompositorDependencies compositor_deps( 66 BlimpCompositorDependencies compositor_deps(
45 base::MakeUnique<MockCompositorDependencies>()); 67 base::MakeUnique<MockCompositorDependencies>());
46 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, 68 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr,
47 nullptr, &render_widget_feature, 69 nullptr, &render_widget_feature,
48 &tab_control_feature); 70 &tab_control_feature);
49 71
50 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); 72 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1);
51 std::unique_ptr<BlimpContentsImpl> blimp_contents = 73 std::unique_ptr<BlimpContentsImpl> blimp_contents =
52 blimp_contents_manager.CreateBlimpContents(); 74 blimp_contents_manager.CreateBlimpContents(window_);
53 int id = blimp_contents->id(); 75 int id = blimp_contents->id();
54 BlimpContentsImpl* existing_contents = 76 BlimpContentsImpl* existing_contents =
55 blimp_contents_manager.GetBlimpContents(id); 77 blimp_contents_manager.GetBlimpContents(id);
56 EXPECT_EQ(blimp_contents.get(), existing_contents); 78 EXPECT_EQ(blimp_contents.get(), existing_contents);
57 } 79 }
58 80
59 TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { 81 TEST_F(BlimpContentsManagerTest, GetNonExistingBlimpContents) {
60 RenderWidgetFeature render_widget_feature; 82 RenderWidgetFeature render_widget_feature;
61 MockTabControlFeature tab_control_feature; 83 MockTabControlFeature tab_control_feature;
62 84
63 BlimpCompositorDependencies compositor_deps( 85 BlimpCompositorDependencies compositor_deps(
64 base::MakeUnique<MockCompositorDependencies>()); 86 base::MakeUnique<MockCompositorDependencies>());
65 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, 87 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr,
66 nullptr, &render_widget_feature, 88 nullptr, &render_widget_feature,
67 &tab_control_feature); 89 &tab_control_feature);
68 90
69 BlimpContentsImpl* existing_contents = 91 BlimpContentsImpl* existing_contents =
70 blimp_contents_manager.GetBlimpContents(kDummyTabId); 92 blimp_contents_manager.GetBlimpContents(kDummyTabId);
71 EXPECT_EQ(nullptr, existing_contents); 93 EXPECT_EQ(nullptr, existing_contents);
72 } 94 }
73 95
74 TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) { 96 TEST_F(BlimpContentsManagerTest, GetDestroyedBlimpContents) {
75 base::MessageLoop loop; 97 base::MessageLoop loop;
76 RenderWidgetFeature render_widget_feature; 98 RenderWidgetFeature render_widget_feature;
77 MockTabControlFeature tab_control_feature; 99 MockTabControlFeature tab_control_feature;
78 BlimpCompositorDependencies compositor_deps( 100 BlimpCompositorDependencies compositor_deps(
79 base::MakeUnique<MockCompositorDependencies>()); 101 base::MakeUnique<MockCompositorDependencies>());
80 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, 102 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr,
81 nullptr, &render_widget_feature, 103 nullptr, &render_widget_feature,
82 &tab_control_feature); 104 &tab_control_feature);
83 int id; 105 int id;
84 106
85 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); 107 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1);
86 std::unique_ptr<BlimpContentsImpl> blimp_contents = 108 std::unique_ptr<BlimpContentsImpl> blimp_contents =
87 blimp_contents_manager.CreateBlimpContents(); 109 blimp_contents_manager.CreateBlimpContents(window_);
88 id = blimp_contents.get()->id(); 110 id = blimp_contents.get()->id();
89 BlimpContentsImpl* existing_contents = 111 BlimpContentsImpl* existing_contents =
90 blimp_contents_manager.GetBlimpContents(id); 112 blimp_contents_manager.GetBlimpContents(id);
91 EXPECT_EQ(blimp_contents.get(), existing_contents); 113 EXPECT_EQ(blimp_contents.get(), existing_contents);
92 114
93 EXPECT_CALL(tab_control_feature, CloseTab(id)).Times(1); 115 EXPECT_CALL(tab_control_feature, CloseTab(id)).Times(1);
94 blimp_contents.reset(); 116 blimp_contents.reset();
95 117
96 loop.RunUntilIdle(); 118 loop.RunUntilIdle();
97 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id)); 119 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id));
98 } 120 }
99 121
100 // TODO(mlliu): remove this test case (http://crbug.com/642558) 122 // TODO(mlliu): remove this test case (http://crbug.com/642558)
101 TEST(BlimpContentsManagerUnittest, CreateTwoBlimpContentsDestroyAndCreate) { 123 TEST_F(BlimpContentsManagerTest, CreateTwoBlimpContentsDestroyAndCreate) {
102 base::MessageLoop loop; 124 base::MessageLoop loop;
103 RenderWidgetFeature render_widget_feature; 125 RenderWidgetFeature render_widget_feature;
104 MockTabControlFeature tab_control_feature; 126 MockTabControlFeature tab_control_feature;
105 BlimpCompositorDependencies compositor_deps( 127 BlimpCompositorDependencies compositor_deps(
106 base::MakeUnique<MockCompositorDependencies>()); 128 base::MakeUnique<MockCompositorDependencies>());
107 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr, 129 BlimpContentsManager blimp_contents_manager(&compositor_deps, nullptr,
108 nullptr, &render_widget_feature, 130 nullptr, &render_widget_feature,
109 &tab_control_feature); 131 &tab_control_feature);
110 132
111 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(2); 133 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(2);
112 std::unique_ptr<BlimpContentsImpl> blimp_contents = 134 std::unique_ptr<BlimpContentsImpl> blimp_contents =
113 blimp_contents_manager.CreateBlimpContents(); 135 blimp_contents_manager.CreateBlimpContents(window_);
114 EXPECT_NE(blimp_contents, nullptr); 136 EXPECT_NE(blimp_contents, nullptr);
115 137
116 std::unique_ptr<BlimpContentsImpl> second_blimp_contents = 138 std::unique_ptr<BlimpContentsImpl> second_blimp_contents =
117 blimp_contents_manager.CreateBlimpContents(); 139 blimp_contents_manager.CreateBlimpContents(window_);
118 EXPECT_EQ(second_blimp_contents, nullptr); 140 EXPECT_EQ(second_blimp_contents, nullptr);
119 141
120 blimp_contents.reset(); 142 blimp_contents.reset();
121 std::unique_ptr<BlimpContentsImpl> third_blimp_contents = 143 std::unique_ptr<BlimpContentsImpl> third_blimp_contents =
122 blimp_contents_manager.CreateBlimpContents(); 144 blimp_contents_manager.CreateBlimpContents(window_);
123 EXPECT_NE(third_blimp_contents, nullptr); 145 EXPECT_NE(third_blimp_contents, nullptr);
124 } 146 }
125 147
126 } // namespace 148 } // namespace
127 } // namespace client 149 } // namespace client
128 } // namespace blimp 150 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/contents/blimp_contents_manager.cc ('k') | blimp/client/core/contents/blimp_contents_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698