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:window_manager"; | 40 const char kWindowManagerURL[] = "mojo: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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // Verifies that bounds changes applied to a view hierarchy in one connection | 415 // Verifies that bounds changes applied to a view hierarchy in one connection |
404 // are reflected to another. | 416 // are reflected to another. |
405 TEST_F(ViewManagerTest, DISABLED_SetBounds) { | 417 TEST_F(ViewManagerTest, DISABLED_SetBounds) { |
406 View* view = View::Create(window_manager()); | 418 View* view = View::Create(window_manager()); |
407 window_manager()->GetRoots().front()->AddChild(view); | 419 window_manager()->GetRoots().front()->AddChild(view); |
408 ViewManager* embedded = Embed(window_manager(), view); | 420 ViewManager* embedded = Embed(window_manager(), view); |
409 | 421 |
410 View* view_in_embedded = embedded->GetViewById(view->id()); | 422 View* view_in_embedded = embedded->GetViewById(view->id()); |
411 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 423 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
412 | 424 |
413 view->SetBounds(gfx::Rect(100, 100)); | 425 Rect rect; |
| 426 rect.width = rect.height = 100; |
| 427 view->SetBounds(rect); |
414 EXPECT_NE(view->bounds(), view_in_embedded->bounds()); | 428 EXPECT_NE(view->bounds(), view_in_embedded->bounds()); |
415 WaitForBoundsToChange(view_in_embedded); | 429 WaitForBoundsToChange(view_in_embedded); |
416 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 430 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
417 } | 431 } |
418 | 432 |
419 // Verifies that bounds changes applied to a view owned by a different | 433 // Verifies that bounds changes applied to a view owned by a different |
420 // connection are refused. | 434 // connection are refused. |
421 TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) { | 435 TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) { |
422 View* view = View::Create(window_manager()); | 436 View* view = View::Create(window_manager()); |
423 window_manager()->GetRoots().front()->AddChild(view); | 437 window_manager()->GetRoots().front()->AddChild(view); |
424 ViewManager* embedded = Embed(window_manager(), view); | 438 ViewManager* embedded = Embed(window_manager(), view); |
425 | 439 |
426 View* view_in_embedded = embedded->GetViewById(view->id()); | 440 View* view_in_embedded = embedded->GetViewById(view->id()); |
427 view->SetBounds(gfx::Rect(800, 600)); | 441 Rect rect; |
| 442 rect.width = 800; |
| 443 rect.height = 600; |
| 444 view->SetBounds(rect); |
428 WaitForBoundsToChange(view_in_embedded); | 445 WaitForBoundsToChange(view_in_embedded); |
429 | 446 |
430 view_in_embedded->SetBounds(gfx::Rect(1024, 768)); | 447 rect.width = 1024; |
| 448 rect.height = 768; |
| 449 view_in_embedded->SetBounds(rect); |
431 // Bounds change should have been rejected. | 450 // Bounds change should have been rejected. |
432 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); | 451 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); |
433 } | 452 } |
434 | 453 |
435 // Verifies that a view can only be destroyed by the connection that created it. | 454 // Verifies that a view can only be destroyed by the connection that created it. |
436 TEST_F(ViewManagerTest, DISABLED_DestroySecurity) { | 455 TEST_F(ViewManagerTest, DISABLED_DestroySecurity) { |
437 View* view = View::Create(window_manager()); | 456 View* view = View::Create(window_manager()); |
438 window_manager()->GetRoots().front()->AddChild(view); | 457 window_manager()->GetRoots().front()->AddChild(view); |
439 ViewManager* embedded = Embed(window_manager(), view); | 458 ViewManager* embedded = Embed(window_manager(), view); |
440 | 459 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 | 636 |
618 // TODO(beng): tests for view event dispatcher. | 637 // TODO(beng): tests for view event dispatcher. |
619 // - verify that we see events for all views. | 638 // - verify that we see events for all views. |
620 | 639 |
621 // TODO(beng): tests for focus: | 640 // TODO(beng): tests for focus: |
622 // - focus between two views known to a connection | 641 // - focus between two views known to a connection |
623 // - focus between views unknown to one of the connections. | 642 // - focus between views unknown to one of the connections. |
624 // - focus between views unknown to either connection. | 643 // - focus between views unknown to either connection. |
625 | 644 |
626 } // namespace mojo | 645 } // namespace mojo |
OLD | NEW |