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 "mojo/services/public/cpp/view_manager/view_manager.h" | 5 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/application_manager/application_manager.h" | 10 #include "mojo/application_manager/application_manager.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
13 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
14 #include "mojo/public/cpp/application/service_provider_impl.h" | 14 #include "mojo/public/cpp/application/service_provider_impl.h" |
15 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 15 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
16 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" | 16 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
17 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 17 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
18 #include "mojo/services/public/cpp/view_manager/util.h" | 18 #include "mojo/services/public/cpp/view_manager/util.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
21 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 21 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
22 #include "mojo/shell/shell_test_helper.h" | 22 #include "mojo/shell/shell_test_helper.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace mojo { | 25 namespace mojo { |
| 26 |
| 27 // TODO(jam): move these somewhere else so they can be shared? |
| 28 |
| 29 inline bool operator==(const Rect& lhs, const Rect& rhs) { |
| 30 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && |
| 31 lhs.height == lhs.height; |
| 32 } |
| 33 |
| 34 inline bool operator!=(const Rect& lhs, const Rect& rhs) { |
| 35 return !(lhs == rhs); |
| 36 } |
| 37 |
26 namespace { | 38 namespace { |
27 | 39 |
28 const char kWindowManagerURL[] = "mojo:example_window_manager"; | 40 const char kWindowManagerURL[] = "mojo:example_window_manager"; |
29 const char kEmbeddedApp1URL[] = "mojo:embedded_app_1"; | 41 const char kEmbeddedApp1URL[] = "mojo:embedded_app_1"; |
30 | 42 |
31 base::RunLoop* current_run_loop = NULL; | 43 base::RunLoop* current_run_loop = NULL; |
32 | 44 |
33 void DoRunLoop() { | 45 void DoRunLoop() { |
34 base::RunLoop run_loop; | 46 base::RunLoop run_loop; |
35 current_run_loop = &run_loop; | 47 current_run_loop = &run_loop; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 }; | 107 }; |
96 | 108 |
97 class BoundsChangeObserver : public ViewObserver { | 109 class BoundsChangeObserver : public ViewObserver { |
98 public: | 110 public: |
99 explicit BoundsChangeObserver(View* view) : view_(view) {} | 111 explicit BoundsChangeObserver(View* view) : view_(view) {} |
100 ~BoundsChangeObserver() override {} | 112 ~BoundsChangeObserver() override {} |
101 | 113 |
102 private: | 114 private: |
103 // Overridden from ViewObserver: | 115 // Overridden from ViewObserver: |
104 void OnViewBoundsChanged(View* view, | 116 void OnViewBoundsChanged(View* view, |
105 const gfx::Rect& old_bounds, | 117 const Rect& old_bounds, |
106 const gfx::Rect& new_bounds) override { | 118 const Rect& new_bounds) override { |
107 DCHECK_EQ(view, view_); | 119 DCHECK_EQ(view, view_); |
108 QuitRunLoop(); | 120 QuitRunLoop(); |
109 } | 121 } |
110 | 122 |
111 View* view_; | 123 View* view_; |
112 | 124 |
113 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); | 125 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); |
114 }; | 126 }; |
115 | 127 |
116 // Wait until the bounds of the supplied view change. | 128 // Wait until the bounds of the supplied view change. |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // Verifies that bounds changes applied to a view hierarchy in one connection | 436 // Verifies that bounds changes applied to a view hierarchy in one connection |
425 // are reflected to another. | 437 // are reflected to another. |
426 TEST_F(ViewManagerTest, DISABLED_SetBounds) { | 438 TEST_F(ViewManagerTest, DISABLED_SetBounds) { |
427 View* view = View::Create(window_manager()); | 439 View* view = View::Create(window_manager()); |
428 window_manager()->GetRoots().front()->AddChild(view); | 440 window_manager()->GetRoots().front()->AddChild(view); |
429 ViewManager* embedded = Embed(window_manager(), view); | 441 ViewManager* embedded = Embed(window_manager(), view); |
430 | 442 |
431 View* view_in_embedded = embedded->GetViewById(view->id()); | 443 View* view_in_embedded = embedded->GetViewById(view->id()); |
432 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 444 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
433 | 445 |
434 view->SetBounds(gfx::Rect(100, 100)); | 446 Rect rect; |
| 447 rect.width = rect.height = 100; |
| 448 view->SetBounds(rect); |
435 EXPECT_NE(view->bounds(), view_in_embedded->bounds()); | 449 EXPECT_NE(view->bounds(), view_in_embedded->bounds()); |
436 WaitForBoundsToChange(view_in_embedded); | 450 WaitForBoundsToChange(view_in_embedded); |
437 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 451 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
438 } | 452 } |
439 | 453 |
440 // Verifies that bounds changes applied to a view owned by a different | 454 // Verifies that bounds changes applied to a view owned by a different |
441 // connection are refused. | 455 // connection are refused. |
442 TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) { | 456 TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) { |
443 View* view = View::Create(window_manager()); | 457 View* view = View::Create(window_manager()); |
444 window_manager()->GetRoots().front()->AddChild(view); | 458 window_manager()->GetRoots().front()->AddChild(view); |
445 ViewManager* embedded = Embed(window_manager(), view); | 459 ViewManager* embedded = Embed(window_manager(), view); |
446 | 460 |
447 View* view_in_embedded = embedded->GetViewById(view->id()); | 461 View* view_in_embedded = embedded->GetViewById(view->id()); |
448 view->SetBounds(gfx::Rect(800, 600)); | 462 Rect rect; |
| 463 rect.width = 800; |
| 464 rect.height = 600; |
| 465 view->SetBounds(rect); |
449 WaitForBoundsToChange(view_in_embedded); | 466 WaitForBoundsToChange(view_in_embedded); |
450 | 467 |
451 view_in_embedded->SetBounds(gfx::Rect(1024, 768)); | 468 rect.width = 1024; |
| 469 rect.height = 768; |
| 470 view_in_embedded->SetBounds(rect); |
452 // Bounds change should have been rejected. | 471 // Bounds change should have been rejected. |
453 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 472 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
454 } | 473 } |
455 | 474 |
456 // Verifies that a view can only be destroyed by the connection that created it. | 475 // Verifies that a view can only be destroyed by the connection that created it. |
457 TEST_F(ViewManagerTest, DISABLED_DestroySecurity) { | 476 TEST_F(ViewManagerTest, DISABLED_DestroySecurity) { |
458 View* view = View::Create(window_manager()); | 477 View* view = View::Create(window_manager()); |
459 window_manager()->GetRoots().front()->AddChild(view); | 478 window_manager()->GetRoots().front()->AddChild(view); |
460 ViewManager* embedded = Embed(window_manager(), view); | 479 ViewManager* embedded = Embed(window_manager(), view); |
461 | 480 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 657 |
639 // TODO(beng): tests for view event dispatcher. | 658 // TODO(beng): tests for view event dispatcher. |
640 // - verify that we see events for all views. | 659 // - verify that we see events for all views. |
641 | 660 |
642 // TODO(beng): tests for focus: | 661 // TODO(beng): tests for focus: |
643 // - focus between two views known to a connection | 662 // - focus between two views known to a connection |
644 // - focus between views unknown to one of the connections. | 663 // - focus between views unknown to one of the connections. |
645 // - focus between views unknown to either connection. | 664 // - focus between views unknown to either connection. |
646 | 665 |
647 } // namespace mojo | 666 } // namespace mojo |
OLD | NEW |