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 "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "components/mus/ids.h" | 9 #include "components/mus/ids.h" |
| 10 #include "components/mus/public/interfaces/view_tree.mojom.h" | 10 #include "components/mus/public/interfaces/view_tree.mojom.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool DeleteView(ViewTree* vm, Id view_id) { | 157 bool DeleteView(ViewTree* vm, Id view_id) { |
| 158 base::RunLoop run_loop; | 158 base::RunLoop run_loop; |
| 159 bool result = false; | 159 bool result = false; |
| 160 vm->DeleteView(view_id, base::Bind(&BoolResultCallback, &run_loop, &result)); | 160 vm->DeleteView(view_id, base::Bind(&BoolResultCallback, &run_loop, &result)); |
| 161 run_loop.Run(); | 161 run_loop.Run(); |
| 162 return result; | 162 return result; |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool SetViewCapture(ViewTree* vm, Id view_id) { | |
| 166 base::RunLoop run_loop; | |
| 167 bool result = false; | |
| 168 vm->SetCapture(view_id, base::Bind(&BoolResultCallback, &run_loop, &result)); | |
| 169 run_loop.Run(); | |
| 170 return result; | |
| 171 } | |
| 172 | |
| 165 bool SetViewBounds(ViewTree* vm, Id view_id, int x, int y, int w, int h) { | 173 bool SetViewBounds(ViewTree* vm, Id view_id, int x, int y, int w, int h) { |
| 166 base::RunLoop run_loop; | 174 base::RunLoop run_loop; |
| 167 bool result = false; | 175 bool result = false; |
| 168 RectPtr rect(mojo::Rect::New()); | 176 RectPtr rect(mojo::Rect::New()); |
| 169 rect->x = x; | 177 rect->x = x; |
| 170 rect->y = y; | 178 rect->y = y; |
| 171 rect->width = w; | 179 rect->width = w; |
| 172 rect->height = h; | 180 rect->height = h; |
| 173 vm->SetViewBounds(view_id, rect.Pass(), | 181 vm->SetViewBounds(view_id, rect.Pass(), |
| 174 base::Bind(&BoolResultCallback, &run_loop, &result)); | 182 base::Bind(&BoolResultCallback, &run_loop, &result)); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 tree_ = tree.Pass(); | 317 tree_ = tree.Pass(); |
| 310 connection_id_ = connection_id; | 318 connection_id_ = connection_id; |
| 311 tracker()->OnEmbed(connection_id, root.Pass()); | 319 tracker()->OnEmbed(connection_id, root.Pass()); |
| 312 if (embed_run_loop_) | 320 if (embed_run_loop_) |
| 313 embed_run_loop_->Quit(); | 321 embed_run_loop_->Quit(); |
| 314 } | 322 } |
| 315 void OnEmbeddedAppDisconnected(Id view_id) override { | 323 void OnEmbeddedAppDisconnected(Id view_id) override { |
| 316 tracker()->OnEmbeddedAppDisconnected(view_id); | 324 tracker()->OnEmbeddedAppDisconnected(view_id); |
| 317 } | 325 } |
| 318 void OnUnembed() override { tracker()->OnUnembed(); } | 326 void OnUnembed() override { tracker()->OnUnembed(); } |
| 327 void OnLostCapture(Id view_id) override { tracker()->OnLostCapture(view_id); } | |
| 319 void OnViewBoundsChanged(Id view_id, | 328 void OnViewBoundsChanged(Id view_id, |
| 320 RectPtr old_bounds, | 329 RectPtr old_bounds, |
| 321 RectPtr new_bounds) override { | 330 RectPtr new_bounds) override { |
| 322 // The bounds of the root may change during startup on Android at random | 331 // The bounds of the root may change during startup on Android at random |
| 323 // times. As this doesn't matter, and shouldn't impact test exepctations, | 332 // times. As this doesn't matter, and shouldn't impact test exepctations, |
| 324 // it is ignored. | 333 // it is ignored. |
| 325 if (view_id == root_view_id_) | 334 if (view_id == root_view_id_) |
| 326 return; | 335 return; |
| 327 tracker()->OnViewBoundsChanged(view_id, old_bounds.Pass(), | 336 tracker()->OnViewBoundsChanged(view_id, old_bounds.Pass(), |
| 328 new_bounds.Pass()); | 337 new_bounds.Pass()); |
| (...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 vm1(), view_1_2, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT, nullptr); | 1669 vm1(), view_1_2, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT, nullptr); |
| 1661 ASSERT_TRUE(vm_client3_.get() != nullptr); | 1670 ASSERT_TRUE(vm_client3_.get() != nullptr); |
| 1662 vm_client3_->set_root_view(root_view_id()); | 1671 vm_client3_->set_root_view(root_view_id()); |
| 1663 | 1672 |
| 1664 // view_1_2 is vm3's root, so even though v3 is an embed root it should not | 1673 // view_1_2 is vm3's root, so even though v3 is an embed root it should not |
| 1665 // be able to Embed into itself. | 1674 // be able to Embed into itself. |
| 1666 ASSERT_FALSE( | 1675 ASSERT_FALSE( |
| 1667 EmbedUrl(application_impl(), vm3(), application_impl()->url(), view_1_2)); | 1676 EmbedUrl(application_impl(), vm3(), application_impl()->url(), view_1_2)); |
| 1668 } | 1677 } |
| 1669 | 1678 |
| 1679 TEST_F(ViewTreeAppTest, CapturePropagation) { | |
| 1680 Id view_1_1 = vm_client1()->CreateView(1); | |
| 1681 Id view_1_2 = vm_client1()->CreateView(2); | |
| 1682 changes1()->clear(); | |
| 1683 // View 1 takes capture then View 2 takes capture. | |
| 1684 // Verify that view 1 has lost capture. | |
| 1685 SetViewCapture(vm1(), view_1_1); | |
| 1686 SetViewCapture(vm1(), view_1_2); | |
|
sadrul
2015/09/18 01:30:50
What if the two setcapture calls come from two sep
Fady Samuel
2015/09/18 02:44:43
So two separate windows? If one tries to capture,
sadrul
2015/09/18 11:47:28
Yep. (in most cases anyway. The second capture can
| |
| 1687 vm_client1_->WaitForChangeCount(1); | |
| 1688 | |
| 1689 EXPECT_EQ("OnLostCapture view=" + IdToString(view_1_1), | |
| 1690 SingleChangeToDescription(*changes1())); | |
| 1691 // std::vector<TestView> views; | |
| 1692 // GetViewTree(vm1(), view_1_1, &views); | |
| 1693 // EXPECT_FALSE(views.empty()); | |
| 1694 } | |
|
sadrul
2015/09/18 01:30:50
?
Fady Samuel
2015/09/18 02:44:43
Removed.
| |
| 1670 // TODO(sky): need to better track changes to initial connection. For example, | 1695 // TODO(sky): need to better track changes to initial connection. For example, |
| 1671 // that SetBounsdViews/AddView and the like don't result in messages to the | 1696 // that SetBounsdViews/AddView and the like don't result in messages to the |
| 1672 // originating connection. | 1697 // originating connection. |
| 1673 | 1698 |
| 1674 // TODO(sky): make sure coverage of what was | 1699 // TODO(sky): make sure coverage of what was |
| 1675 // ViewManagerTest.SecondEmbedRoot_InitService and | 1700 // ViewManagerTest.SecondEmbedRoot_InitService and |
| 1676 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1701 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
| 1677 // tests. | 1702 // tests. |
| 1678 | 1703 |
| 1679 } // namespace mus | 1704 } // namespace mus |
| OLD | NEW |