Chromium Code Reviews| 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..d3f388015006fa82427483ba7b9781b2e863f86c 100644 |
| --- a/mojo/services/view_manager/view_manager_service_apptest.cc |
| +++ b/mojo/services/view_manager/view_manager_service_apptest.cc |
| @@ -171,6 +171,36 @@ bool SetViewProperty(ViewManagerService* vm, |
| return result; |
| } |
| +bool CloneAndAnimate(WindowManagerInternalClient* wm, Id view_id) { |
| + bool result = false; |
| + base::RunLoop run_loop; |
| + wm->CloneAndAnimate(view_id, |
| + base::Bind(&BoolResultCallback, &run_loop, &result)); |
| + run_loop.Run(); |
| + return result; |
| +} |
| + |
| +// 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(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.
|
| + 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 == BuildViewId(kInvalidConnectionId, 1)) |
|
msw
2014/11/18 23:37:42
nit: use ClonedViewId().
sky
2014/11/19 00:49:39
Done.
|
| + return true; |
| + return false; |
| +} |
| + |
| // ----------------------------------------------------------------------------- |
| // A ViewManagerClient implementation that logs all changes to a tracker. |
| @@ -1324,6 +1354,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(); |
| + |
| + // 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.
|
| + ASSERT_TRUE(WaitForAllMessages(vm1())); |
| + changes1()->clear(); |
| + |
| + ASSERT_TRUE(CloneAndAnimate(wm_internal_.get(), BuildViewId(2, 3))); |
| + |
| + 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. |
|
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.
|
| + 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. |