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