Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: components/mus/mus_client_apptest.cc

Issue 1340983002: Mandoline UI Process: Update namespaces and file names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated all the namespaces in mus Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/logging.h" 6 #include "base/logging.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "components/mus/public/cpp/tests/view_manager_test_base.h" 8 #include "components/mus/public/cpp/tests/mandoline_ui_services_test_base.h"
9 #include "components/mus/public/cpp/util.h" 9 #include "components/mus/public/cpp/util.h"
10 #include "components/mus/public/cpp/view_observer.h" 10 #include "components/mus/public/cpp/view_observer.h"
11 #include "components/mus/public/cpp/view_tree_connection.h" 11 #include "components/mus/public/cpp/view_tree_connection.h"
12 #include "components/mus/public/cpp/view_tree_delegate.h" 12 #include "components/mus/public/cpp/view_tree_delegate.h"
13 #include "mojo/application/public/cpp/application_connection.h" 13 #include "mojo/application/public/cpp/application_connection.h"
14 #include "mojo/application/public/cpp/application_impl.h" 14 #include "mojo/application/public/cpp/application_impl.h"
15 #include "mojo/application/public/cpp/application_test_base.h" 15 #include "mojo/application/public/cpp/application_test_base.h"
16 #include "ui/mojo/geometry/geometry_util.h" 16 #include "ui/mojo/geometry/geometry_util.h"
17 17
18 namespace mojo { 18 namespace mus {
19 19
20 namespace { 20 namespace {
21 21
22 class BoundsChangeObserver : public ViewObserver { 22 class BoundsChangeObserver : public ViewObserver {
23 public: 23 public:
24 explicit BoundsChangeObserver(View* view) : view_(view) { 24 explicit BoundsChangeObserver(View* view) : view_(view) {
25 view_->AddObserver(this); 25 view_->AddObserver(this);
26 } 26 }
27 ~BoundsChangeObserver() override { view_->RemoveObserver(this); } 27 ~BoundsChangeObserver() override { view_->RemoveObserver(this); }
28 28
29 private: 29 private:
30 // Overridden from ViewObserver: 30 // Overridden from ViewObserver:
31 void OnViewBoundsChanged(View* view, 31 void OnViewBoundsChanged(View* view,
32 const Rect& old_bounds, 32 const mojo::Rect& old_bounds,
33 const Rect& new_bounds) override { 33 const mojo::Rect& new_bounds) override {
34 DCHECK_EQ(view, view_); 34 DCHECK_EQ(view, view_);
35 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 35 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
36 } 36 }
37 37
38 View* view_; 38 View* view_;
39 39
40 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); 40 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
41 }; 41 };
42 42
43 // Wait until the bounds of the supplied view change; returns false on timeout. 43 // Wait until the bounds of the supplied view change; returns false on timeout.
44 bool WaitForBoundsToChange(View* view) { 44 bool WaitForBoundsToChange(View* view) {
45 BoundsChangeObserver observer(view); 45 BoundsChangeObserver observer(view);
46 return ViewManagerTestBase::DoRunLoopWithTimeout(); 46 return MandolineUIServicesTestBase::DoRunLoopWithTimeout();
47 } 47 }
48 48
49 // Spins a run loop until the tree beginning at |root| has |tree_size| views 49 // Spins a run loop until the tree beginning at |root| has |tree_size| views
50 // (including |root|). 50 // (including |root|).
51 class TreeSizeMatchesObserver : public ViewObserver { 51 class TreeSizeMatchesObserver : public ViewObserver {
52 public: 52 public:
53 TreeSizeMatchesObserver(View* tree, size_t tree_size) 53 TreeSizeMatchesObserver(View* tree, size_t tree_size)
54 : tree_(tree), tree_size_(tree_size) { 54 : tree_(tree), tree_size_(tree_size) {
55 tree_->AddObserver(this); 55 tree_->AddObserver(this);
56 } 56 }
57 ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); } 57 ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); }
58 58
59 bool IsTreeCorrectSize() { return CountViews(tree_) == tree_size_; } 59 bool IsTreeCorrectSize() { return CountViews(tree_) == tree_size_; }
60 60
61 private: 61 private:
62 // Overridden from ViewObserver: 62 // Overridden from ViewObserver:
63 void OnTreeChanged(const TreeChangeParams& params) override { 63 void OnTreeChanged(const TreeChangeParams& params) override {
64 if (IsTreeCorrectSize()) 64 if (IsTreeCorrectSize())
65 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 65 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
66 } 66 }
67 67
68 size_t CountViews(const View* view) const { 68 size_t CountViews(const View* view) const {
69 size_t count = 1; 69 size_t count = 1;
70 View::Children::const_iterator it = view->children().begin(); 70 View::Children::const_iterator it = view->children().begin();
71 for (; it != view->children().end(); ++it) 71 for (; it != view->children().end(); ++it)
72 count += CountViews(*it); 72 count += CountViews(*it);
73 return count; 73 return count;
74 } 74 }
75 75
76 View* tree_; 76 View* tree_;
77 size_t tree_size_; 77 size_t tree_size_;
78 78
79 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); 79 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver);
80 }; 80 };
81 81
82 // Wait until |view| has |tree_size| descendants; returns false on timeout. The 82 // Wait until |view| has |tree_size| descendants; returns false on timeout. The
83 // count includes |view|. For example, if you want to wait for |view| to have 83 // count includes |view|. For example, if you want to wait for |view| to have
84 // a single child, use a |tree_size| of 2. 84 // a single child, use a |tree_size| of 2.
85 bool WaitForTreeSizeToMatch(View* view, size_t tree_size) { 85 bool WaitForTreeSizeToMatch(View* view, size_t tree_size) {
86 TreeSizeMatchesObserver observer(view, tree_size); 86 TreeSizeMatchesObserver observer(view, tree_size);
87 return observer.IsTreeCorrectSize() || 87 return observer.IsTreeCorrectSize() ||
88 ViewManagerTestBase::DoRunLoopWithTimeout(); 88 MandolineUIServicesTestBase::DoRunLoopWithTimeout();
89 } 89 }
90 90
91 class OrderChangeObserver : public ViewObserver { 91 class OrderChangeObserver : public ViewObserver {
92 public: 92 public:
93 OrderChangeObserver(View* view) : view_(view) { view_->AddObserver(this); } 93 OrderChangeObserver(View* view) : view_(view) { view_->AddObserver(this); }
94 ~OrderChangeObserver() override { view_->RemoveObserver(this); } 94 ~OrderChangeObserver() override { view_->RemoveObserver(this); }
95 95
96 private: 96 private:
97 // Overridden from ViewObserver: 97 // Overridden from ViewObserver:
98 void OnViewReordered(View* view, 98 void OnViewReordered(View* view,
99 View* relative_view, 99 View* relative_view,
100 OrderDirection direction) override { 100 mojo::OrderDirection direction) override {
101 DCHECK_EQ(view, view_); 101 DCHECK_EQ(view, view_);
102 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 102 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
103 } 103 }
104 104
105 View* view_; 105 View* view_;
106 106
107 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); 107 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver);
108 }; 108 };
109 109
110 // Wait until |view|'s tree size matches |tree_size|; returns false on timeout. 110 // Wait until |view|'s tree size matches |tree_size|; returns false on timeout.
111 bool WaitForOrderChange(ViewTreeConnection* connection, View* view) { 111 bool WaitForOrderChange(ViewTreeConnection* connection, View* view) {
112 OrderChangeObserver observer(view); 112 OrderChangeObserver observer(view);
113 return ViewManagerTestBase::DoRunLoopWithTimeout(); 113 return MandolineUIServicesTestBase::DoRunLoopWithTimeout();
114 } 114 }
115 115
116 // Tracks a view's destruction. Query is_valid() for current state. 116 // Tracks a view's destruction. Query is_valid() for current state.
117 class ViewTracker : public ViewObserver { 117 class ViewTracker : public ViewObserver {
118 public: 118 public:
119 explicit ViewTracker(View* view) : view_(view) { view_->AddObserver(this); } 119 explicit ViewTracker(View* view) : view_(view) { view_->AddObserver(this); }
120 ~ViewTracker() override { 120 ~ViewTracker() override {
121 if (view_) 121 if (view_)
122 view_->RemoveObserver(this); 122 view_->RemoveObserver(this);
123 } 123 }
(...skipping 25 matching lines...) Expand all
149 149
150 // The id supplied to the callback from OnEmbed(). Depending upon the 150 // The id supplied to the callback from OnEmbed(). Depending upon the
151 // access policy this may or may not match the connection id of 151 // access policy this may or may not match the connection id of
152 // |connection|. 152 // |connection|.
153 ConnectionSpecificId connection_id; 153 ConnectionSpecificId connection_id;
154 }; 154 };
155 155
156 // These tests model synchronization of two peer connections to the view manager 156 // These tests model synchronization of two peer connections to the view manager
157 // service, that are given access to some root view. 157 // service, that are given access to some root view.
158 158
159 class ViewManagerTest : public ViewManagerTestBase { 159 class ViewManagerTest : public MandolineUIServicesTestBase {
160 public: 160 public:
161 ViewManagerTest() {} 161 ViewManagerTest() {}
162 162
163 // Embeds another version of the test app @ view. This runs a run loop until 163 // Embeds another version of the test app @ view. This runs a run loop until
164 // a response is received, or a timeout. On success the new ViewManager is 164 // a response is received, or a timeout. On success the new ViewManager is
165 // returned. 165 // returned.
166 EmbedResult Embed(View* view) { 166 EmbedResult Embed(View* view) {
167 DCHECK(!embed_details_); 167 DCHECK(!embed_details_);
168 embed_details_.reset(new EmbedDetails); 168 embed_details_.reset(new EmbedDetails);
169 view->Embed(ConnectToApplicationAndGetViewManagerClient(), 169 view->Embed(ConnectToApplicationAndGetViewManagerClient(),
170 base::Bind(&ViewManagerTest::EmbedCallbackImpl, 170 base::Bind(&ViewManagerTest::EmbedCallbackImpl,
171 base::Unretained(this))); 171 base::Unretained(this)));
172 embed_details_->waiting = true; 172 embed_details_->waiting = true;
173 if (!ViewManagerTestBase::DoRunLoopWithTimeout()) 173 if (!MandolineUIServicesTestBase::DoRunLoopWithTimeout())
174 return EmbedResult(); 174 return EmbedResult();
175 const EmbedResult result(embed_details_->connection, 175 const EmbedResult result(embed_details_->connection,
176 embed_details_->connection_id); 176 embed_details_->connection_id);
177 embed_details_.reset(); 177 embed_details_.reset();
178 return result; 178 return result;
179 } 179 }
180 180
181 // Establishes a connection to this application and asks for a 181 // Establishes a connection to this application and asks for a
182 // ViewTreeClient. 182 // ViewTreeClient.
183 mojo::ViewTreeClientPtr ConnectToApplicationAndGetViewManagerClient() { 183 mojo::ViewTreeClientPtr ConnectToApplicationAndGetViewManagerClient() {
184 mojo::URLRequestPtr request(mojo::URLRequest::New()); 184 mojo::URLRequestPtr request(mojo::URLRequest::New());
185 request->url = mojo::String::From(application_impl()->url()); 185 request->url = mojo::String::From(application_impl()->url());
186 scoped_ptr<ApplicationConnection> connection = 186 scoped_ptr<mojo::ApplicationConnection> connection =
187 application_impl()->ConnectToApplication(request.Pass()); 187 application_impl()->ConnectToApplication(request.Pass());
188 mojo::ViewTreeClientPtr client; 188 mojo::ViewTreeClientPtr client;
189 connection->ConnectToService(&client); 189 connection->ConnectToService(&client);
190 return client.Pass(); 190 return client.Pass();
191 } 191 }
192 192
193 // ViewManagerTestBase: 193 // MandolineUIServicesTestBase:
194 void OnEmbed(View* root) override { 194 void OnEmbed(View* root) override {
195 if (!embed_details_) { 195 if (!embed_details_) {
196 ViewManagerTestBase::OnEmbed(root); 196 MandolineUIServicesTestBase::OnEmbed(root);
197 return; 197 return;
198 } 198 }
199 199
200 embed_details_->connection = root->connection(); 200 embed_details_->connection = root->connection();
201 if (embed_details_->callback_run) 201 if (embed_details_->callback_run)
202 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 202 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
203 } 203 }
204 204
205 private: 205 private:
206 // Used to track the state of a call to view->Embed(). 206 // Used to track the state of a call to view->Embed().
207 struct EmbedDetails { 207 struct EmbedDetails {
208 EmbedDetails() 208 EmbedDetails()
209 : callback_run(false), 209 : callback_run(false),
210 result(false), 210 result(false),
211 waiting(false), 211 waiting(false),
212 connection_id(0), 212 connection_id(0),
(...skipping 14 matching lines...) Expand all
227 // The ViewTreeConnection that resulted from the Embed(). null if |result| 227 // The ViewTreeConnection that resulted from the Embed(). null if |result|
228 // is false. 228 // is false.
229 ViewTreeConnection* connection; 229 ViewTreeConnection* connection;
230 }; 230 };
231 231
232 void EmbedCallbackImpl(bool result, ConnectionSpecificId connection_id) { 232 void EmbedCallbackImpl(bool result, ConnectionSpecificId connection_id) {
233 embed_details_->callback_run = true; 233 embed_details_->callback_run = true;
234 embed_details_->result = result; 234 embed_details_->result = result;
235 embed_details_->connection_id = connection_id; 235 embed_details_->connection_id = connection_id;
236 if (embed_details_->waiting && (!result || embed_details_->connection)) 236 if (embed_details_->waiting && (!result || embed_details_->connection))
237 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 237 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
238 } 238 }
239 239
240 scoped_ptr<EmbedDetails> embed_details_; 240 scoped_ptr<EmbedDetails> embed_details_;
241 241
242 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); 242 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
243 }; 243 };
244 244
245 TEST_F(ViewManagerTest, RootView) { 245 TEST_F(ViewManagerTest, RootView) {
246 ASSERT_NE(nullptr, window_manager()); 246 ASSERT_NE(nullptr, window_manager());
247 EXPECT_NE(nullptr, window_manager()->GetRoot()); 247 EXPECT_NE(nullptr, window_manager()->GetRoot());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 TEST_F(ViewManagerTest, SetBounds) { 299 TEST_F(ViewManagerTest, SetBounds) {
300 View* view = window_manager()->CreateView(); 300 View* view = window_manager()->CreateView();
301 view->SetVisible(true); 301 view->SetVisible(true);
302 window_manager()->GetRoot()->AddChild(view); 302 window_manager()->GetRoot()->AddChild(view);
303 ViewTreeConnection* embedded = Embed(view).connection; 303 ViewTreeConnection* embedded = Embed(view).connection;
304 ASSERT_NE(nullptr, embedded); 304 ASSERT_NE(nullptr, embedded);
305 305
306 View* view_in_embedded = embedded->GetViewById(view->id()); 306 View* view_in_embedded = embedded->GetViewById(view->id());
307 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); 307 EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
308 308
309 Rect rect; 309 mojo::Rect rect;
310 rect.width = rect.height = 100; 310 rect.width = rect.height = 100;
311 view->SetBounds(rect); 311 view->SetBounds(rect);
312 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded)); 312 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded));
313 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); 313 EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
314 } 314 }
315 315
316 // Verifies that bounds changes applied to a view owned by a different 316 // Verifies that bounds changes applied to a view owned by a different
317 // connection are refused. 317 // connection are refused.
318 TEST_F(ViewManagerTest, SetBoundsSecurity) { 318 TEST_F(ViewManagerTest, SetBoundsSecurity) {
319 View* view = window_manager()->CreateView(); 319 View* view = window_manager()->CreateView();
320 view->SetVisible(true); 320 view->SetVisible(true);
321 window_manager()->GetRoot()->AddChild(view); 321 window_manager()->GetRoot()->AddChild(view);
322 ViewTreeConnection* embedded = Embed(view).connection; 322 ViewTreeConnection* embedded = Embed(view).connection;
323 ASSERT_NE(nullptr, embedded); 323 ASSERT_NE(nullptr, embedded);
324 324
325 View* view_in_embedded = embedded->GetViewById(view->id()); 325 View* view_in_embedded = embedded->GetViewById(view->id());
326 Rect rect; 326 mojo::Rect rect;
327 rect.width = 800; 327 rect.width = 800;
328 rect.height = 600; 328 rect.height = 600;
329 view->SetBounds(rect); 329 view->SetBounds(rect);
330 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded)); 330 ASSERT_TRUE(WaitForBoundsToChange(view_in_embedded));
331 331
332 rect.width = 1024; 332 rect.width = 1024;
333 rect.height = 768; 333 rect.height = 768;
334 view_in_embedded->SetBounds(rect); 334 view_in_embedded->SetBounds(rect);
335 // Bounds change should have been rejected. 335 // Bounds change should have been rejected.
336 EXPECT_EQ(view->bounds(), view_in_embedded->bounds()); 336 EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 public: 418 public:
419 explicit VisibilityChangeObserver(View* view) : view_(view) { 419 explicit VisibilityChangeObserver(View* view) : view_(view) {
420 view_->AddObserver(this); 420 view_->AddObserver(this);
421 } 421 }
422 ~VisibilityChangeObserver() override { view_->RemoveObserver(this); } 422 ~VisibilityChangeObserver() override { view_->RemoveObserver(this); }
423 423
424 private: 424 private:
425 // Overridden from ViewObserver: 425 // Overridden from ViewObserver:
426 void OnViewVisibilityChanged(View* view) override { 426 void OnViewVisibilityChanged(View* view) override {
427 EXPECT_EQ(view, view_); 427 EXPECT_EQ(view, view_);
428 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 428 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
429 } 429 }
430 430
431 View* view_; 431 View* view_;
432 432
433 MOJO_DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); 433 MOJO_DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
434 }; 434 };
435 435
436 } // namespace 436 } // namespace
437 437
438 TEST_F(ViewManagerTest, Visible) { 438 TEST_F(ViewManagerTest, Visible) {
439 View* view1 = window_manager()->CreateView(); 439 View* view1 = window_manager()->CreateView();
440 view1->SetVisible(true); 440 view1->SetVisible(true);
441 window_manager()->GetRoot()->AddChild(view1); 441 window_manager()->GetRoot()->AddChild(view1);
442 442
443 // Embed another app and verify initial state. 443 // Embed another app and verify initial state.
444 ViewTreeConnection* embedded = Embed(view1).connection; 444 ViewTreeConnection* embedded = Embed(view1).connection;
445 ASSERT_NE(nullptr, embedded); 445 ASSERT_NE(nullptr, embedded);
446 ASSERT_NE(nullptr, embedded->GetRoot()); 446 ASSERT_NE(nullptr, embedded->GetRoot());
447 View* embedded_root = embedded->GetRoot(); 447 View* embedded_root = embedded->GetRoot();
448 EXPECT_TRUE(embedded_root->visible()); 448 EXPECT_TRUE(embedded_root->visible());
449 EXPECT_TRUE(embedded_root->IsDrawn()); 449 EXPECT_TRUE(embedded_root->IsDrawn());
450 450
451 // Change the visible state from the first connection and verify its mirrored 451 // Change the visible state from the first connection and verify its mirrored
452 // correctly to the embedded app. 452 // correctly to the embedded app.
453 { 453 {
454 VisibilityChangeObserver observer(embedded_root); 454 VisibilityChangeObserver observer(embedded_root);
455 view1->SetVisible(false); 455 view1->SetVisible(false);
456 ASSERT_TRUE(ViewManagerTestBase::DoRunLoopWithTimeout()); 456 ASSERT_TRUE(MandolineUIServicesTestBase::DoRunLoopWithTimeout());
457 } 457 }
458 458
459 EXPECT_FALSE(view1->visible()); 459 EXPECT_FALSE(view1->visible());
460 EXPECT_FALSE(view1->IsDrawn()); 460 EXPECT_FALSE(view1->IsDrawn());
461 461
462 EXPECT_FALSE(embedded_root->visible()); 462 EXPECT_FALSE(embedded_root->visible());
463 EXPECT_FALSE(embedded_root->IsDrawn()); 463 EXPECT_FALSE(embedded_root->IsDrawn());
464 464
465 // Make the node visible again. 465 // Make the node visible again.
466 { 466 {
467 VisibilityChangeObserver observer(embedded_root); 467 VisibilityChangeObserver observer(embedded_root);
468 view1->SetVisible(true); 468 view1->SetVisible(true);
469 ASSERT_TRUE(ViewManagerTestBase::DoRunLoopWithTimeout()); 469 ASSERT_TRUE(MandolineUIServicesTestBase::DoRunLoopWithTimeout());
470 } 470 }
471 471
472 EXPECT_TRUE(view1->visible()); 472 EXPECT_TRUE(view1->visible());
473 EXPECT_TRUE(view1->IsDrawn()); 473 EXPECT_TRUE(view1->IsDrawn());
474 474
475 EXPECT_TRUE(embedded_root->visible()); 475 EXPECT_TRUE(embedded_root->visible());
476 EXPECT_TRUE(embedded_root->IsDrawn()); 476 EXPECT_TRUE(embedded_root->IsDrawn());
477 } 477 }
478 478
479 namespace { 479 namespace {
480 480
481 class DrawnChangeObserver : public ViewObserver { 481 class DrawnChangeObserver : public ViewObserver {
482 public: 482 public:
483 explicit DrawnChangeObserver(View* view) : view_(view) { 483 explicit DrawnChangeObserver(View* view) : view_(view) {
484 view_->AddObserver(this); 484 view_->AddObserver(this);
485 } 485 }
486 ~DrawnChangeObserver() override { view_->RemoveObserver(this); } 486 ~DrawnChangeObserver() override { view_->RemoveObserver(this); }
487 487
488 private: 488 private:
489 // Overridden from ViewObserver: 489 // Overridden from ViewObserver:
490 void OnViewDrawnChanged(View* view) override { 490 void OnViewDrawnChanged(View* view) override {
491 EXPECT_EQ(view, view_); 491 EXPECT_EQ(view, view_);
492 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 492 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
493 } 493 }
494 494
495 View* view_; 495 View* view_;
496 496
497 MOJO_DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver); 497 MOJO_DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver);
498 }; 498 };
499 499
500 } // namespace 500 } // namespace
501 501
502 TEST_F(ViewManagerTest, Drawn) { 502 TEST_F(ViewManagerTest, Drawn) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 544
545 View* last_lost_focus() { return last_lost_focus_; } 545 View* last_lost_focus() { return last_lost_focus_; }
546 546
547 private: 547 private:
548 // Overridden from ViewObserver. 548 // Overridden from ViewObserver.
549 void OnViewFocusChanged(View* gained_focus, View* lost_focus) override { 549 void OnViewFocusChanged(View* gained_focus, View* lost_focus) override {
550 EXPECT_TRUE(!gained_focus || gained_focus->HasFocus()); 550 EXPECT_TRUE(!gained_focus || gained_focus->HasFocus());
551 EXPECT_FALSE(lost_focus && lost_focus->HasFocus()); 551 EXPECT_FALSE(lost_focus && lost_focus->HasFocus());
552 last_gained_focus_ = gained_focus; 552 last_gained_focus_ = gained_focus;
553 last_lost_focus_ = lost_focus; 553 last_lost_focus_ = lost_focus;
554 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 554 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
555 } 555 }
556 556
557 View* view_; 557 View* view_;
558 View* last_gained_focus_; 558 View* last_gained_focus_;
559 View* last_lost_focus_; 559 View* last_lost_focus_;
560 560
561 MOJO_DISALLOW_COPY_AND_ASSIGN(FocusChangeObserver); 561 MOJO_DISALLOW_COPY_AND_ASSIGN(FocusChangeObserver);
562 }; 562 };
563 563
564 } // namespace 564 } // namespace
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 ASSERT_NE(nullptr, observer.last_lost_focus()); 603 ASSERT_NE(nullptr, observer.last_lost_focus());
604 EXPECT_EQ(view11->id(), observer.last_lost_focus()->id()); 604 EXPECT_EQ(view11->id(), observer.last_lost_focus()->id());
605 EXPECT_EQ(embedded->GetRoot()->id(), observer.last_gained_focus()->id()); 605 EXPECT_EQ(embedded->GetRoot()->id(), observer.last_gained_focus()->id());
606 } 606 }
607 } 607 }
608 608
609 namespace { 609 namespace {
610 610
611 class DestroyedChangedObserver : public ViewObserver { 611 class DestroyedChangedObserver : public ViewObserver {
612 public: 612 public:
613 DestroyedChangedObserver(ViewManagerTestBase* test, 613 DestroyedChangedObserver(MandolineUIServicesTestBase* test,
614 View* view, 614 View* view,
615 bool* got_destroy) 615 bool* got_destroy)
616 : test_(test), view_(view), got_destroy_(got_destroy) { 616 : test_(test), view_(view), got_destroy_(got_destroy) {
617 view_->AddObserver(this); 617 view_->AddObserver(this);
618 } 618 }
619 ~DestroyedChangedObserver() override { 619 ~DestroyedChangedObserver() override {
620 if (view_) 620 if (view_)
621 view_->RemoveObserver(this); 621 view_->RemoveObserver(this);
622 } 622 }
623 623
624 private: 624 private:
625 // Overridden from ViewObserver: 625 // Overridden from ViewObserver:
626 void OnViewDestroyed(View* view) override { 626 void OnViewDestroyed(View* view) override {
627 EXPECT_EQ(view, view_); 627 EXPECT_EQ(view, view_);
628 view_->RemoveObserver(this); 628 view_->RemoveObserver(this);
629 *got_destroy_ = true; 629 *got_destroy_ = true;
630 view_ = nullptr; 630 view_ = nullptr;
631 631
632 // We should always get OnViewDestroyed() before OnConnectionLost(). 632 // We should always get OnViewDestroyed() before OnConnectionLost().
633 EXPECT_FALSE(test_->view_tree_connection_destroyed()); 633 EXPECT_FALSE(test_->view_tree_connection_destroyed());
634 } 634 }
635 635
636 ViewManagerTestBase* test_; 636 MandolineUIServicesTestBase* test_;
637 View* view_; 637 View* view_;
638 bool* got_destroy_; 638 bool* got_destroy_;
639 639
640 MOJO_DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver); 640 MOJO_DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver);
641 }; 641 };
642 642
643 } // namespace 643 } // namespace
644 644
645 // Verifies deleting a ViewManager sends the right notifications. 645 // Verifies deleting a ViewManager sends the right notifications.
646 TEST_F(ViewManagerTest, DeleteViewManager) { 646 TEST_F(ViewManagerTest, DeleteViewManager) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // Run the message loop so the Embed() call above completes. Without this 713 // Run the message loop so the Embed() call above completes. Without this
714 // we may end up reconnecting to the test and rerunning the test, which is 714 // we may end up reconnecting to the test and rerunning the test, which is
715 // problematic since the other services don't shut down. 715 // problematic since the other services don't shut down.
716 ASSERT_TRUE(DoRunLoopWithTimeout()); 716 ASSERT_TRUE(DoRunLoopWithTimeout());
717 } 717 }
718 718
719 namespace { 719 namespace {
720 720
721 class DestroyObserver : public ViewObserver { 721 class DestroyObserver : public ViewObserver {
722 public: 722 public:
723 DestroyObserver(ViewManagerTestBase* test, 723 DestroyObserver(MandolineUIServicesTestBase* test,
724 ViewTreeConnection* connection, 724 ViewTreeConnection* connection,
725 bool* got_destroy) 725 bool* got_destroy)
726 : test_(test), got_destroy_(got_destroy) { 726 : test_(test), got_destroy_(got_destroy) {
727 connection->GetRoot()->AddObserver(this); 727 connection->GetRoot()->AddObserver(this);
728 } 728 }
729 ~DestroyObserver() override {} 729 ~DestroyObserver() override {}
730 730
731 private: 731 private:
732 // Overridden from ViewObserver: 732 // Overridden from ViewObserver:
733 void OnViewDestroyed(View* view) override { 733 void OnViewDestroyed(View* view) override {
734 *got_destroy_ = true; 734 *got_destroy_ = true;
735 view->RemoveObserver(this); 735 view->RemoveObserver(this);
736 736
737 // We should always get OnViewDestroyed() before OnViewManagerDestroyed(). 737 // We should always get OnViewDestroyed() before OnViewManagerDestroyed().
738 EXPECT_FALSE(test_->view_tree_connection_destroyed()); 738 EXPECT_FALSE(test_->view_tree_connection_destroyed());
739 739
740 EXPECT_TRUE(ViewManagerTestBase::QuitRunLoop()); 740 EXPECT_TRUE(MandolineUIServicesTestBase::QuitRunLoop());
741 } 741 }
742 742
743 ViewManagerTestBase* test_; 743 MandolineUIServicesTestBase* test_;
744 bool* got_destroy_; 744 bool* got_destroy_;
745 745
746 MOJO_DISALLOW_COPY_AND_ASSIGN(DestroyObserver); 746 MOJO_DISALLOW_COPY_AND_ASSIGN(DestroyObserver);
747 }; 747 };
748 748
749 } // namespace 749 } // namespace
750 750
751 // Verifies deleting a View that is the root of another connection notifies 751 // Verifies deleting a View that is the root of another connection notifies
752 // observers in the right order (OnViewDestroyed() before 752 // observers in the right order (OnViewDestroyed() before
753 // OnViewManagerDestroyed()). 753 // OnViewManagerDestroyed()).
(...skipping 11 matching lines...) Expand all
765 EXPECT_TRUE(DoRunLoopWithTimeout()); 765 EXPECT_TRUE(DoRunLoopWithTimeout());
766 EXPECT_TRUE(got_destroy); 766 EXPECT_TRUE(got_destroy);
767 } 767 }
768 768
769 // Verifies an embed root sees views created beneath it from another 769 // Verifies an embed root sees views created beneath it from another
770 // connection. 770 // connection.
771 TEST_F(ViewManagerTest, EmbedRootSeesHierarchyChanged) { 771 TEST_F(ViewManagerTest, EmbedRootSeesHierarchyChanged) {
772 View* embed_view = window_manager()->CreateView(); 772 View* embed_view = window_manager()->CreateView();
773 window_manager()->GetRoot()->AddChild(embed_view); 773 window_manager()->GetRoot()->AddChild(embed_view);
774 774
775 embed_view->SetAccessPolicy(ViewTree::ACCESS_POLICY_EMBED_ROOT); 775 embed_view->SetAccessPolicy(mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT);
776 ViewTreeConnection* vm2 = Embed(embed_view).connection; 776 ViewTreeConnection* vm2 = Embed(embed_view).connection;
777 View* vm2_v1 = vm2->CreateView(); 777 View* vm2_v1 = vm2->CreateView();
778 vm2->GetRoot()->AddChild(vm2_v1); 778 vm2->GetRoot()->AddChild(vm2_v1);
779 779
780 ViewTreeConnection* vm3 = Embed(vm2_v1).connection; 780 ViewTreeConnection* vm3 = Embed(vm2_v1).connection;
781 View* vm3_v1 = vm3->CreateView(); 781 View* vm3_v1 = vm3->CreateView();
782 vm3->GetRoot()->AddChild(vm3_v1); 782 vm3->GetRoot()->AddChild(vm3_v1);
783 783
784 // As |vm2| is an embed root it should get notified about |vm3_v1|. 784 // As |vm2| is an embed root it should get notified about |vm3_v1|.
785 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); 785 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2));
786 } 786 }
787 787
788 TEST_F(ViewManagerTest, EmbedFromEmbedRoot) { 788 TEST_F(ViewManagerTest, EmbedFromEmbedRoot) {
789 View* embed_view = window_manager()->CreateView(); 789 View* embed_view = window_manager()->CreateView();
790 window_manager()->GetRoot()->AddChild(embed_view); 790 window_manager()->GetRoot()->AddChild(embed_view);
791 791
792 // Give the connection embedded at |embed_view| embed root powers. 792 // Give the connection embedded at |embed_view| embed root powers.
793 embed_view->SetAccessPolicy(ViewTree::ACCESS_POLICY_EMBED_ROOT); 793 embed_view->SetAccessPolicy(mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT);
794 const EmbedResult result1 = Embed(embed_view); 794 const EmbedResult result1 = Embed(embed_view);
795 ViewTreeConnection* vm2 = result1.connection; 795 ViewTreeConnection* vm2 = result1.connection;
796 EXPECT_EQ(result1.connection_id, vm2->GetConnectionId()); 796 EXPECT_EQ(result1.connection_id, vm2->GetConnectionId());
797 View* vm2_v1 = vm2->CreateView(); 797 View* vm2_v1 = vm2->CreateView();
798 vm2->GetRoot()->AddChild(vm2_v1); 798 vm2->GetRoot()->AddChild(vm2_v1);
799 799
800 const EmbedResult result2 = Embed(vm2_v1); 800 const EmbedResult result2 = Embed(vm2_v1);
801 ViewTreeConnection* vm3 = result2.connection; 801 ViewTreeConnection* vm3 = result2.connection;
802 EXPECT_EQ(result2.connection_id, vm3->GetConnectionId()); 802 EXPECT_EQ(result2.connection_id, vm3->GetConnectionId());
803 View* vm3_v1 = vm3->CreateView(); 803 View* vm3_v1 = vm3->CreateView();
(...skipping 10 matching lines...) Expand all
814 814
815 // Embed() from vm2 in vm3_v1. This is allowed as vm2 is an embed root, and 815 // Embed() from vm2 in vm3_v1. This is allowed as vm2 is an embed root, and
816 // further the callback should see the connection id. 816 // further the callback should see the connection id.
817 ASSERT_EQ(1u, vm2_v1->children().size()); 817 ASSERT_EQ(1u, vm2_v1->children().size());
818 View* vm3_v1_in_vm2 = vm2_v1->children()[0]; 818 View* vm3_v1_in_vm2 = vm2_v1->children()[0];
819 const EmbedResult result4 = Embed(vm3_v1_in_vm2); 819 const EmbedResult result4 = Embed(vm3_v1_in_vm2);
820 ASSERT_TRUE(result4.connection); 820 ASSERT_TRUE(result4.connection);
821 EXPECT_EQ(result4.connection_id, result4.connection->GetConnectionId()); 821 EXPECT_EQ(result4.connection_id, result4.connection->GetConnectionId());
822 } 822 }
823 823
824 } // namespace mojo 824 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698