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

Side by Side Diff: services/ui/view_manager/tests/view_manager_test.cc

Issue 1949233002: Create a RegisterViewAssociate method in ViewManager (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add tests to mojo tests Created 4 years, 7 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
(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 "mojo/public/cpp/application/application_impl.h"
6 #include "mojo/public/cpp/application/connect.h"
7 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h"
8 #include "mojo/services/ui/views/interfaces/views.mojom.h"
9 #include "services/ui/view_manager/tests/mock_view_associate.h"
10 #include "services/ui/view_manager/tests/view_manager_test_base.h"
11
12 namespace view_manager {
13 namespace test {
14
15 class MockViewListener : public mojo::ui::ViewListener {
16 public:
17 MockViewListener() {}
18 ~MockViewListener() override {}
19
20 void OnPropertiesChanged(
21 uint32_t scene_version,
22 mojo::ui::ViewPropertiesPtr properties,
23 const OnPropertiesChangedCallback& callback) override {}
24 };
25
26 class ViewManagerTest : public ViewManagerTestBase {
27 public:
28 ViewManagerTest() {}
29 ~ViewManagerTest() override {}
30
31 void SetUp() override {
32 ViewManagerTestBase::SetUp();
33
34 // Connect to view manager
35 mojo::ConnectToService(shell(), "mojo:view_manager_service",
36 mojo::GetProxy(&view_manager_));
37 }
38
39 protected:
40 mojo::ui::ViewManagerPtr view_manager_;
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
44 };
45
46 TEST_F(ViewManagerTest, CreateAViewManagerAndView) {
47 // Create and bind a mock view listener
48 mojo::ui::ViewListenerPtr view_listener;
49 MockViewListener mock_view_listener;
50 mojo::Binding<mojo::ui::ViewListener> view_listener_binding(
51 &mock_view_listener, mojo::GetProxy(&view_listener));
52
53 // Create a view
54 mojo::ui::ViewPtr view;
55 mojo::ui::ViewOwnerPtr client_view_owner;
56 view_manager_->CreateView(mojo::GetProxy(&view),
57 mojo::GetProxy(&client_view_owner),
58 view_listener.Pass(), "test_view");
59
60 // Call View::GetToken. Check that you get the callback.
61 int view_token_callback_invokecount = 0;
62 auto view_token_callback = [&view_token_callback_invokecount](
63 mojo::ui::ViewTokenPtr token) { view_token_callback_invokecount++; };
64
65 EXPECT_EQ(0, view_token_callback_invokecount);
66 view->GetToken(view_token_callback);
67
68 KICK_MESSAGE_LOOP_WHILE(view_token_callback_invokecount != 1);
69
70 EXPECT_EQ(1, view_token_callback_invokecount);
71 }
72
73 TEST_F(ViewManagerTest, ConnectAMockViewAssociate) {
74 // Create and bind a MockViewAssociate
75 mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate;
76 MockViewAssociate mock_view_associate;
77 mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding(
78 &mock_view_associate, mojo::GetProxy(&associate));
79
80 // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect
81 // should be called back
82 EXPECT_EQ(0, mock_view_associate.connect_invokecount);
83 mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
84 view_manager_->RegisterViewAssociate(associate.Pass(),
85 mojo::GetProxy(&view_associate_owner),
86 "test_view_associate");
87
88 KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1);
89
90 EXPECT_EQ(1, mock_view_associate.connect_invokecount);
91 }
92
93 TEST_F(ViewManagerTest, DisconnectAMockViewAssociate) {
94 mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
95 int owner_connection_error_callback_invokecount = 0;
96
97 {
98 // Create and bind a MockViewAssociate
99 mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate;
100 MockViewAssociate mock_view_associate;
101 mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding(
102 &mock_view_associate, mojo::GetProxy(&associate));
103
104 // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect
105 // should be called back
106 EXPECT_EQ(0, mock_view_associate.connect_invokecount);
107
108 view_manager_->RegisterViewAssociate(associate.Pass(),
109 mojo::GetProxy(&view_associate_owner),
110 "test_view_associate_xyz");
111
112 // set a callback for errors
113 view_associate_owner.set_connection_error_handler(
114 // use lambda function as callback
115 [&owner_connection_error_callback_invokecount]() {
116 owner_connection_error_callback_invokecount++;
117 });
118
119 KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1);
120
121 EXPECT_EQ(1, mock_view_associate.connect_invokecount);
122
123 EXPECT_EQ(0, owner_connection_error_callback_invokecount);
124 }
125
126 // mock_view_associate is out of scope, should be destroyed
127 // we expect to get a connection error from the owner
128 KICK_MESSAGE_LOOP_WHILE(owner_connection_error_callback_invokecount != 1)
129
130 EXPECT_EQ(1, owner_connection_error_callback_invokecount);
131 }
132
133 TEST_F(ViewManagerTest, DisconnectAViewAssociateOwner) {
134 // Create and bind a MockViewAssociate
135 mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate;
136 MockViewAssociate mock_view_associate;
137 mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding(
138 &mock_view_associate, mojo::GetProxy(&associate));
139
140 // set a callback for errors
141 int connection_error_callback_invokecount = 0;
142 view_associate_binding.set_connection_error_handler(
143 // use lambda function as callback
144 [&connection_error_callback_invokecount]() {
145 connection_error_callback_invokecount++;
146 });
147
148 {
149 mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
150
151 // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect
152 // should be called back
153 EXPECT_EQ(0, mock_view_associate.connect_invokecount);
154
155 view_manager_->RegisterViewAssociate(associate.Pass(),
156 mojo::GetProxy(&view_associate_owner),
157 "test_view_associate_xyz");
158
159 KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1);
160
161 EXPECT_EQ(1, mock_view_associate.connect_invokecount);
162
163 EXPECT_EQ(0, connection_error_callback_invokecount);
164 }
165
166 // view_associate_owner is out of scope, should be destroyed
167 // we expect to get a connection error from the view associate
168 KICK_MESSAGE_LOOP_WHILE(connection_error_callback_invokecount != 1)
169
170 EXPECT_EQ(1, connection_error_callback_invokecount);
171 }
172
173 } // namespace test
174 } // namespace view_manager
OLDNEW
« no previous file with comments | « services/ui/view_manager/tests/view_associate_table_test.cc ('k') | services/ui/view_manager/tests/view_manager_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698