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

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: Add GetView(ClonedViewId) coverage 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 // Utility functions -----------------------------------------------------------
175
176 // Waits for all messages to be received by |vm|. This is done by attempting to
177 // create a bogus view. When we get the response we know all messages have been
178 // processed.
179 bool WaitForAllMessages(ViewManagerService* vm) {
180 ErrorCode result = ERROR_CODE_NONE;
181 base::RunLoop run_loop;
182 vm->CreateView(ViewIdToTransportId(InvalidViewId()),
183 base::Bind(&ErrorCodeResultCallback, &run_loop, &result));
184 run_loop.Run();
185 return result != ERROR_CODE_NONE;
186 }
187
188 bool HasClonedView(const std::vector<TestView>& views) {
189 for (size_t i = 0; i < views.size(); ++i)
190 if (views[i].view_id == ViewIdToTransportId(ClonedViewId()))
191 return true;
192 return false;
193 }
194
174 // ----------------------------------------------------------------------------- 195 // -----------------------------------------------------------------------------
175 196
176 // A ViewManagerClient implementation that logs all changes to a tracker. 197 // A ViewManagerClient implementation that logs all changes to a tracker.
177 class ViewManagerClientImpl : public InterfaceImpl<ViewManagerClient>, 198 class ViewManagerClientImpl : public InterfaceImpl<ViewManagerClient>,
178 public TestChangeTracker::Delegate { 199 public TestChangeTracker::Delegate {
179 public: 200 public:
180 ViewManagerClientImpl() : got_embed_(false) { tracker_.set_delegate(this); } 201 ViewManagerClientImpl() : got_embed_(false) { tracker_.set_delegate(this); }
181 202
182 TestChangeTracker* tracker() { return &tracker_; } 203 TestChangeTracker* tracker() { return &tracker_; }
183 204
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 changes1()->clear(); 1338 changes1()->clear();
1318 vm_client2_.reset(); 1339 vm_client2_.reset();
1319 vm_client1_.WaitForChangeCount(1); 1340 vm_client1_.WaitForChangeCount(1);
1320 EXPECT_EQ("OnEmbeddedAppDisconnected view=1,1", 1341 EXPECT_EQ("OnEmbeddedAppDisconnected view=1,1",
1321 SingleChangeToDescription(*changes1())); 1342 SingleChangeToDescription(*changes1()));
1322 std::vector<TestView> views; 1343 std::vector<TestView> views;
1323 GetViewTree(vm1(), BuildViewId(1, 1), &views); 1344 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1324 EXPECT_FALSE(views.empty()); 1345 EXPECT_FALSE(views.empty());
1325 } 1346 }
1326 1347
1348 TEST_F(ViewManagerServiceAppTest, CloneAndAnimate) {
1349 // Create connection 2 and 3.
1350 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1351 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1)));
1352 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2)));
1353 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 3)));
1354 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2)));
1355 ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 3)));
1356 changes2()->clear();
1357
1358 ASSERT_TRUE(WaitForAllMessages(vm1()));
1359 changes1()->clear();
1360
1361 wm_internal_->CloneAndAnimate(BuildViewId(2, 3));
1362 ASSERT_TRUE(WaitForAllMessages(vm1()));
1363
1364 ASSERT_TRUE(WaitForAllMessages(vm1()));
1365 ASSERT_TRUE(WaitForAllMessages(vm2()));
1366
1367 // No messages should have been received.
1368 EXPECT_TRUE(changes1()->empty());
1369 EXPECT_TRUE(changes2()->empty());
1370
1371 // No one should be able to see the cloned tree.
1372 std::vector<TestView> views;
1373 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1374 EXPECT_FALSE(HasClonedView(views));
1375 views.clear();
1376
1377 GetViewTree(vm2(), BuildViewId(1, 1), &views);
1378 EXPECT_FALSE(HasClonedView(views));
1379 }
1380
1327 // TODO(sky): need to better track changes to initial connection. For example, 1381 // 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 1382 // that SetBounsdViews/AddView and the like don't result in messages to the
1329 // originating connection. 1383 // originating connection.
1330 1384
1331 // TODO(sky): make sure coverage of what was 1385 // TODO(sky): make sure coverage of what was
1332 // ViewManagerTest.SecondEmbedRoot_InitService and 1386 // ViewManagerTest.SecondEmbedRoot_InitService and
1333 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager 1387 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager
1334 // tests. 1388 // tests.
1335 1389
1336 } // namespace service 1390 } // namespace service
1337 } // namespace mojo 1391 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698