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

Side by Side Diff: mojo/services/view_manager/view_manager_service_apptest.cc

Issue 720883003: Adds a CloneAndAnimate function to WindowManagerInternalClient (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: tweaks Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/application_impl.h" 9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_test_base.h" 10 #include "mojo/public/cpp/application/application_test_base.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 bool result = false; 164 bool result = false;
165 Array<uint8_t> mojo_data; 165 Array<uint8_t> mojo_data;
166 if (data) 166 if (data)
167 mojo_data = Array<uint8_t>::From(*data); 167 mojo_data = Array<uint8_t>::From(*data);
168 vm->SetViewProperty(view_id, name, mojo_data.Pass(), 168 vm->SetViewProperty(view_id, name, mojo_data.Pass(),
169 base::Bind(&BoolResultCallback, &run_loop, &result)); 169 base::Bind(&BoolResultCallback, &run_loop, &result));
170 run_loop.Run(); 170 run_loop.Run();
171 return result; 171 return result;
172 } 172 }
173 173
174 bool CloneAndAnimate(WindowManagerInternalClient* wm, Id view_id) {
175 bool result = false;
176 base::RunLoop run_loop;
177 wm->CloneAndAnimate(view_id,
178 base::Bind(&BoolResultCallback, &run_loop, &result));
179 run_loop.Run();
180 return result;
181 }
182
183 // Utility functions -----------------------------------------------------------
184
185 // Waits for all messages to be received by |vm|. This is done by attempting to
186 // create a bogus view. When we get the response we know all messages have been
187 // processed.
188 bool WaitForAllMessages(ViewManagerService* vm) {
189 ErrorCode result = ERROR_CODE_NONE;
190 base::RunLoop run_loop;
191 vm->CreateView(BuildViewId(0, 1),
msw 2014/11/18 23:37:42 nit: Use RootViewId() (or why not InvalidViewId())
sky 2014/11/19 00:49:39 Done.
192 base::Bind(&ErrorCodeResultCallback, &run_loop, &result));
193 run_loop.Run();
194 return result != ERROR_CODE_NONE;
195 }
196
197 bool HasClonedView(const std::vector<TestView>& views) {
198 for (size_t i = 0; i < views.size(); ++i)
199 if (views[i].view_id == BuildViewId(kInvalidConnectionId, 1))
msw 2014/11/18 23:37:42 nit: use ClonedViewId().
sky 2014/11/19 00:49:39 Done.
200 return true;
201 return false;
202 }
203
174 // ----------------------------------------------------------------------------- 204 // -----------------------------------------------------------------------------
175 205
176 // A ViewManagerClient implementation that logs all changes to a tracker. 206 // A ViewManagerClient implementation that logs all changes to a tracker.
177 class ViewManagerClientImpl : public InterfaceImpl<ViewManagerClient>, 207 class ViewManagerClientImpl : public InterfaceImpl<ViewManagerClient>,
178 public TestChangeTracker::Delegate { 208 public TestChangeTracker::Delegate {
179 public: 209 public:
180 ViewManagerClientImpl() : got_embed_(false) { tracker_.set_delegate(this); } 210 ViewManagerClientImpl() : got_embed_(false) { tracker_.set_delegate(this); }
181 211
182 TestChangeTracker* tracker() { return &tracker_; } 212 TestChangeTracker* tracker() { return &tracker_; }
183 213
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 changes1()->clear(); 1347 changes1()->clear();
1318 vm_client2_.reset(); 1348 vm_client2_.reset();
1319 vm_client1_.WaitForChangeCount(1); 1349 vm_client1_.WaitForChangeCount(1);
1320 EXPECT_EQ("OnEmbeddedAppDisconnected view=1,1", 1350 EXPECT_EQ("OnEmbeddedAppDisconnected view=1,1",
1321 SingleChangeToDescription(*changes1())); 1351 SingleChangeToDescription(*changes1()));
1322 std::vector<TestView> views; 1352 std::vector<TestView> views;
1323 GetViewTree(vm1(), BuildViewId(1, 1), &views); 1353 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1324 EXPECT_FALSE(views.empty()); 1354 EXPECT_FALSE(views.empty());
1325 } 1355 }
1326 1356
1357 TEST_F(ViewManagerServiceAppTest, CloneAndAnimate) {
1358 // Create connection 2 and 3.
1359 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1360 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1)));
1361 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2)));
1362 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 3)));
1363 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
1364 ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 3)));
1365 changes2()->clear();
1366
1367 // Attempt to create a bad view so we know all messages have been received
msw 2014/11/18 23:37:42 nit: is WaitForAllMessages's impl worth noting? If
sky 2014/11/19 00:49:39 Done.
1368 ASSERT_TRUE(WaitForAllMessages(vm1()));
1369 changes1()->clear();
1370
1371 ASSERT_TRUE(CloneAndAnimate(wm_internal_.get(), BuildViewId(2, 3)));
1372
1373 ASSERT_TRUE(WaitForAllMessages(vm1()));
1374 ASSERT_TRUE(WaitForAllMessages(vm2()));
1375
1376 // No messages should have been received.
1377 EXPECT_TRUE(changes1()->empty());
1378 EXPECT_TRUE(changes2()->empty());
1379
1380 // No one should be able to see the cloned tree.
msw 2014/11/18 23:37:42 Hmm, I don't know if I fully understand the implic
sky 2014/11/19 00:49:40 Indeed. This is the most restrictive we can be. Ho
msw 2014/11/19 01:27:51 Acknowledged.
1381 std::vector<TestView> views;
1382 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1383 EXPECT_FALSE(HasClonedView(views));
1384 views.clear();
1385
1386 GetViewTree(vm2(), BuildViewId(1, 1), &views);
1387 EXPECT_FALSE(HasClonedView(views));
1388 }
1389
1327 // TODO(sky): need to better track changes to initial connection. For example, 1390 // TODO(sky): need to better track changes to initial connection. For example,
1328 // that SetBounsdViews/AddView and the like don't result in messages to the 1391 // that SetBounsdViews/AddView and the like don't result in messages to the
1329 // originating connection. 1392 // originating connection.
1330 1393
1331 // TODO(sky): make sure coverage of what was 1394 // TODO(sky): make sure coverage of what was
1332 // ViewManagerTest.SecondEmbedRoot_InitService and 1395 // ViewManagerTest.SecondEmbedRoot_InitService and
1333 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager 1396 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager
1334 // tests. 1397 // tests.
1335 1398
1336 } // namespace service 1399 } // namespace service
1337 } // namespace mojo 1400 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698