Index: mojo/services/view_manager/view_manager_service_apptest.cc |
diff --git a/mojo/services/view_manager/view_manager_service_apptest.cc b/mojo/services/view_manager/view_manager_service_apptest.cc |
index b49221bc41b722d5af87652f71e4b8d94933a8d0..7270903f07747fa47655eb12c2c1e38d7650b972 100644 |
--- a/mojo/services/view_manager/view_manager_service_apptest.cc |
+++ b/mojo/services/view_manager/view_manager_service_apptest.cc |
@@ -171,6 +171,31 @@ bool SetViewProperty(ViewManagerService* vm, |
return result; |
} |
+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.
|
+ wm->CloneAndAnimate(view_id); |
+} |
+ |
+// Utility functions ----------------------------------------------------------- |
+ |
+// Waits for all messages to be received by |vm|. This is done by attempting to |
+// create a bogus view. When we get the response we know all messages have been |
+// processed. |
+bool WaitForAllMessages(ViewManagerService* vm) { |
+ ErrorCode result = ERROR_CODE_NONE; |
+ base::RunLoop run_loop; |
+ vm->CreateView(ViewIdToTransportId(InvalidViewId()), |
+ base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
+ run_loop.Run(); |
+ return result != ERROR_CODE_NONE; |
+} |
+ |
+bool HasClonedView(const std::vector<TestView>& views) { |
+ for (size_t i = 0; i < views.size(); ++i) |
+ if (views[i].view_id == ViewIdToTransportId(ClonedViewId())) |
+ return true; |
+ return false; |
+} |
+ |
// ----------------------------------------------------------------------------- |
// A ViewManagerClient implementation that logs all changes to a tracker. |
@@ -1324,6 +1349,39 @@ TEST_F(ViewManagerServiceAppTest, DontCleanMapOnDestroy) { |
EXPECT_FALSE(views.empty()); |
} |
+TEST_F(ViewManagerServiceAppTest, CloneAndAnimate) { |
+ // Create connection 2 and 3. |
+ ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
+ ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); |
+ ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); |
+ ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 3))); |
+ ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); |
+ ASSERT_TRUE(AddView(vm2(), BuildViewId(2, 2), BuildViewId(2, 3))); |
+ changes2()->clear(); |
+ |
+ ASSERT_TRUE(WaitForAllMessages(vm1())); |
+ changes1()->clear(); |
+ |
+ CloneAndAnimate(wm_internal_.get(), BuildViewId(2, 3)); |
+ ASSERT_TRUE(WaitForAllMessages(vm1())); |
+ |
+ ASSERT_TRUE(WaitForAllMessages(vm1())); |
+ ASSERT_TRUE(WaitForAllMessages(vm2())); |
+ |
+ // No messages should have been received. |
+ EXPECT_TRUE(changes1()->empty()); |
+ EXPECT_TRUE(changes2()->empty()); |
+ |
+ // No one should be able to see the cloned tree. |
+ std::vector<TestView> views; |
+ GetViewTree(vm1(), BuildViewId(1, 1), &views); |
+ EXPECT_FALSE(HasClonedView(views)); |
+ views.clear(); |
+ |
+ GetViewTree(vm2(), BuildViewId(1, 1), &views); |
+ EXPECT_FALSE(HasClonedView(views)); |
+} |
+ |
// TODO(sky): need to better track changes to initial connection. For example, |
// that SetBounsdViews/AddView and the like don't result in messages to the |
// originating connection. |