summaryrefslogtreecommitdiffstats
path: root/mojo/services/view_manager/view_manager_connection_unittest.cc
blob: d656a43984ee068817ad686585e40273e4ad2e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>
#include <vector>

#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
#include "mojo/shell/shell_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {
namespace services {
namespace view_manager {

namespace {

base::RunLoop* current_run_loop = NULL;

// TODO(sky): remove and include a common header.
typedef uint32_t ChangeId;

uint16_t FirstIdFromTransportId(uint32_t id) {
  return static_cast<uint16_t>((id >> 16) & 0xFFFF);
}

uint16_t SecondIdFromTransportId(uint32_t id) {
  return static_cast<uint16_t>(id & 0xFFFF);
}

// Sets |current_run_loop| and runs it. It is expected that someone else quits
// the loop.
void DoRunLoop() {
  base::RunLoop run_loop;
  current_run_loop = &run_loop;
  current_run_loop->Run();
  current_run_loop = NULL;
}

// Converts |id| into a string.
std::string NodeIdToString(uint32_t id) {
  return (id == 0) ? "null" :
      base::StringPrintf("%d,%d", FirstIdFromTransportId(id),
                         SecondIdFromTransportId(id));
}

// Boolean callback. Sets |result_cache| to the value of |result| and quits
// the run loop.
void BooleanCallback(bool* result_cache, bool result) {
  *result_cache = result;
  current_run_loop->Quit();
}

struct TestNode {
  std::string ToString() const {
    return base::StringPrintf("node=%s parent=%s view=%s",
                              NodeIdToString(node_id).c_str(),
                              NodeIdToString(parent_id).c_str(),
                              NodeIdToString(view_id).c_str());
  }

  uint32_t parent_id;
  uint32_t node_id;
  uint32_t view_id;
};

// Callback that results in a vector of INodes. The INodes are converted to
// TestNodes.
void INodesCallback(std::vector<TestNode>* test_nodes,
                    const mojo::Array<INode>& data) {
  for (size_t i = 0; i < data.size(); ++i) {
    TestNode node;
    node.parent_id = data[i].parent_id();
    node.node_id = data[i].node_id();
    node.view_id = data[i].view_id();
    test_nodes->push_back(node);
  }
  current_run_loop->Quit();
}

// Creates an id used for transport from the specified parameters.
uint32_t CreateNodeId(uint16_t connection_id, uint16_t node_id) {
  return (connection_id << 16) | node_id;
}

// Creates an id used for transport from the specified parameters.
uint32_t CreateViewId(uint16_t connection_id, uint16_t view_id) {
  return (connection_id << 16) | view_id;
}

// Creates a node with the specified id. Returns true on success. Blocks until
// we get back result from server.
bool CreateNode(IViewManager* view_manager, uint16_t id) {
  bool result = false;
  view_manager->CreateNode(id, base::Bind(&BooleanCallback, &result));
  DoRunLoop();
  return result;
}

// TODO(sky): make a macro for these functions, they are all the same.

// Deletes a node, blocking until done.
bool DeleteNode(IViewManager* view_manager,
                uint32_t node_id,
                ChangeId change_id) {
  bool result = false;
  view_manager->DeleteNode(node_id, change_id,
                           base::Bind(&BooleanCallback, &result));
  DoRunLoop();
  return result;
}

// Adds a node, blocking until done.
bool AddNode(IViewManager* view_manager,
             uint32_t parent,
             uint32_t child,
             ChangeId change_id) {
  bool result = false;
  view_manager->AddNode(parent, child, change_id,
                        base::Bind(&BooleanCallback, &result));
  DoRunLoop();
  return result;
}

// Removes a node, blocking until done.
bool RemoveNodeFromParent(IViewManager* view_manager,
                          uint32_t node_id,
                          ChangeId change_id) {
  bool result = false;
  view_manager->RemoveNodeFromParent(node_id, change_id,
                                     base::Bind(&BooleanCallback, &result));
  DoRunLoop();
  return result;
}

void GetNodeTree(IViewManager* view_manager,
                 uint32_t node_id,
                 std::vector<TestNode>* nodes) {
  view_manager->GetNodeTree(node_id, base::Bind(&INodesCallback, nodes));
  DoRunLoop();
}

// Creates a view with the specified id. Returns true on success. Blocks until
// we get back result from server.
bool CreateView(IViewManager* view_manager, uint16_t id) {
  bool result = false;
  view_manager->CreateView(id, base::Bind(&BooleanCallback, &result));
  DoRunLoop();
  return result;
}

// Sets a view on the specified node. Returns true on success. Blocks until we
// get back result from server.
bool SetView(IViewManager* view_manager,
             uint32_t node_id,
             uint32_t view_id,
             ChangeId change_id) {
  bool result = false;
  view_manager->SetView(node_id, view_id, change_id,
                        base::Bind(&BooleanCallback, &result));
  DoRunLoop();
  return result;
}

}  // namespace

typedef std::vector<std::string> Changes;

class ViewManagerClientImpl : public IViewManagerClient {
 public:
  ViewManagerClientImpl() : id_(0), quit_count_(0) {}

  uint16_t id() const { return id_; }

  Changes GetAndClearChanges() {
    Changes changes;
    changes.swap(changes_);
    return changes;
  }

  void WaitForId() {
    if (id_ == 0)
      DoRunLoop();
  }

  void DoRunLoopUntilChangesCount(size_t count) {
    if (changes_.size() >= count)
      return;
    quit_count_ = count - changes_.size();
    DoRunLoop();
  }

 private:
  // IViewManagerClient overrides:
  virtual void OnConnectionEstablished(uint16_t connection_id) OVERRIDE {
    id_ = connection_id;
    if (current_run_loop)
      current_run_loop->Quit();
  }
  virtual void OnNodeHierarchyChanged(uint32_t node,
                                      uint32_t new_parent,
                                      uint32_t old_parent,
                                      ChangeId change_id) OVERRIDE {
    changes_.push_back(
        base::StringPrintf(
            "change_id=%d node=%s new_parent=%s old_parent=%s",
            static_cast<int>(change_id), NodeIdToString(node).c_str(),
            NodeIdToString(new_parent).c_str(),
            NodeIdToString(old_parent).c_str()));
    QuitIfNecessary();
  }
  virtual void OnNodeViewReplaced(uint32_t node,
                                  uint32_t new_view_id,
                                  uint32_t old_view_id,
                                  ChangeId change_id) OVERRIDE {
    changes_.push_back(
        base::StringPrintf(
            "change_id=%d node=%s new_view=%s old_view=%s",
            static_cast<int>(change_id), NodeIdToString(node).c_str(),
            NodeIdToString(new_view_id).c_str(),
            NodeIdToString(old_view_id).c_str()));
    QuitIfNecessary();
  }

  void QuitIfNecessary() {
    if (quit_count_ > 0 && --quit_count_ == 0)
      current_run_loop->Quit();
  }

  uint16_t id_;

  // Used to determine when/if to quit the run loop.
  size_t quit_count_;

  Changes changes_;

  DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl);
};

class ViewManagerConnectionTest : public testing::Test {
 public:
  ViewManagerConnectionTest() {}

  virtual void SetUp() OVERRIDE {
    AllocationScope allocation_scope;

    test_helper_.Init();

    InterfacePipe<IViewManager, AnyInterface> pipe;
    test_helper_.shell()->Connect("mojo:mojo_view_manager",
                                  pipe.handle_to_peer.Pass());
    view_manager_.reset(pipe.handle_to_self.Pass(), &client_);

    client_.WaitForId();
  }

 protected:
  // Creates a second connection to the viewmanager.
  void EstablishSecondConnection() {
    AllocationScope allocation_scope;
    InterfacePipe<IViewManager, AnyInterface> pipe;
    test_helper_.shell()->Connect("mojo:mojo_view_manager",
                                  pipe.handle_to_peer.Pass());
    view_manager2_.reset(pipe.handle_to_self.Pass(), &client2_);

    client2_.WaitForId();
  }

  void DestroySecondConnection() {
    view_manager2_.reset();
  }

  base::MessageLoop loop_;
  shell::ShellTestHelper test_helper_;

  ViewManagerClientImpl client_;
  RemotePtr<IViewManager> view_manager_;

  ViewManagerClientImpl client2_;
  RemotePtr<IViewManager> view_manager2_;

  DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest);
};

// Verifies client gets a valid id.
TEST_F(ViewManagerConnectionTest, ValidId) {
  // All these tests assume 1 for the client id. The only real assertion here is
  // the client id is not zero, but adding this as rest of code here assumes 1.
  EXPECT_EQ(1, client_.id());
}

// Verifies two clients/connections get different ids.
TEST_F(ViewManagerConnectionTest, TwoClientsGetDifferentConnectionIds) {
  EstablishSecondConnection();
  EXPECT_NE(0, client2_.id());
  EXPECT_NE(client_.id(), client2_.id());
}

// Verifies client gets a valid id.
TEST_F(ViewManagerConnectionTest, CreateNode) {
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));

  // Can't create a node with the same id.
  ASSERT_FALSE(CreateNode(view_manager_.get(), 1));
}

// Verifies hierarchy changes.
TEST_F(ViewManagerConnectionTest, AddRemoveNotify) {
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 2));

  EXPECT_TRUE(client_.GetAndClearChanges().empty());

  // Make 2 a child of 1.
  {
    AllocationScope scope;
    ASSERT_TRUE(AddNode(view_manager_.get(),
                        CreateNodeId(client_.id(), 1),
                        CreateNodeId(client_.id(), 2),
                        11));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null",
              changes[0]);
  }

  // Remove 2 from its parent.
  {
    AllocationScope scope;
    ASSERT_TRUE(RemoveNodeFromParent(view_manager_.get(),
                                     CreateNodeId(client_.id(), 2),
                                     101));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=101 node=1,2 new_parent=null old_parent=1,1",
              changes[0]);
  }
}

// Verifies hierarchy changes are sent to multiple clients.
TEST_F(ViewManagerConnectionTest, AddRemoveNotifyMultipleConnections) {
  EstablishSecondConnection();

  // Create two nodes in first connection.
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 2));

  EXPECT_TRUE(client_.GetAndClearChanges().empty());
  EXPECT_TRUE(client2_.GetAndClearChanges().empty());

  // Make 2 a child of 1.
  {
    AllocationScope scope;
    ASSERT_TRUE(AddNode(view_manager_.get(),
                        CreateNodeId(client_.id(), 1),
                        CreateNodeId(client_.id(), 2),
                        11));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null",
              changes[0]);
  }

  // Second client should also have received the change.
  {
    client2_.DoRunLoopUntilChangesCount(1);
    Changes changes(client2_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=0 node=1,2 new_parent=1,1 old_parent=null",
              changes[0]);
  }
}

// Verifies adding to root sends right notifications.
TEST_F(ViewManagerConnectionTest, AddToRoot) {
  ASSERT_TRUE(CreateNode(view_manager_.get(), 21));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 3));
  EXPECT_TRUE(client_.GetAndClearChanges().empty());

  // Make 3 a child of 21.
  {
    AllocationScope scope;
    ASSERT_TRUE(AddNode(view_manager_.get(),
                        CreateNodeId(client_.id(), 21),
                        CreateNodeId(client_.id(), 3),
                        11));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=11 node=1,3 new_parent=1,21 old_parent=null",
              changes[0]);
  }

  // Make 21 a child of the root.
  {
    AllocationScope scope;
    ASSERT_TRUE(AddNode(view_manager_.get(),
                        CreateNodeId(0, 1),
                        CreateNodeId(client_.id(), 21),
                        44));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=44 node=1,21 new_parent=0,1 old_parent=null",
              changes[0]);
  }
}

// Verifies DeleteNode works.
TEST_F(ViewManagerConnectionTest, DeleteNode) {
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
  EXPECT_TRUE(client_.GetAndClearChanges().empty());

  // Make 2 a child of 1.
  {
    AllocationScope scope;
    ASSERT_TRUE(AddNode(view_manager_.get(),
                        CreateNodeId(client_.id(), 1),
                        CreateNodeId(client_.id(), 2),
                        11));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null",
              changes[0]);
  }

  // Add 1 to the root
  {
    AllocationScope scope;
    ASSERT_TRUE(AddNode(view_manager_.get(),
                        CreateNodeId(0, 1),
                        CreateNodeId(client_.id(), 1),
                        101));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=101 node=1,1 new_parent=0,1 old_parent=null",
              changes[0]);
  }

  // Delete 1.
  {
    AllocationScope scope;
    ASSERT_TRUE(DeleteNode(view_manager_.get(),
                           CreateNodeId(client_.id(), 1),
                           121));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(2u, changes.size());
    EXPECT_EQ("change_id=121 node=1,1 new_parent=null old_parent=0,1",
              changes[0]);
    EXPECT_EQ("change_id=121 node=1,2 new_parent=null old_parent=1,1",
              changes[1]);
  }
}

// Assertions around setting a view.
TEST_F(ViewManagerConnectionTest, SetView) {
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
  ASSERT_TRUE(CreateView(view_manager_.get(), 11));
  EXPECT_TRUE(client_.GetAndClearChanges().empty());

  // Set view 11 on node 1.
  {
    ASSERT_TRUE(SetView(view_manager_.get(),
                        CreateNodeId(client_.id(), 1),
                        CreateViewId(client_.id(), 11),
                        21));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=21 node=1,1 new_view=1,11 old_view=null",
              changes[0]);
  }

  // Set view 11 on node 2.
  {
    ASSERT_TRUE(SetView(view_manager_.get(),
                        CreateNodeId(client_.id(), 2),
                        CreateViewId(client_.id(), 11),
                        22));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(2u, changes.size());
    EXPECT_EQ("change_id=22 node=1,1 new_view=null old_view=1,11",
              changes[0]);
    EXPECT_EQ("change_id=22 node=1,2 new_view=1,11 old_view=null",
              changes[1]);
  }
}

// Verifies deleting a node with a view sends correct notifications.
TEST_F(ViewManagerConnectionTest, DeleteNodeWithView) {
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
  ASSERT_TRUE(CreateView(view_manager_.get(), 11));
  EXPECT_TRUE(client_.GetAndClearChanges().empty());

  // Set view 11 on node 1.
  ASSERT_TRUE(SetView(view_manager_.get(),
                      CreateNodeId(client_.id(), 1),
                      CreateViewId(client_.id(), 11),
                      21));
  client_.GetAndClearChanges();

  // Delete node 1.
  {
    ASSERT_TRUE(DeleteNode(view_manager_.get(),
                           CreateNodeId(client_.id(), 1),
                           121));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=121 node=1,1 new_view=null old_view=1,11",
              changes[0]);
  }

  // Set view 11 on node 2.
  {
    ASSERT_TRUE(SetView(view_manager_.get(),
                        CreateNodeId(client_.id(), 2),
                        CreateViewId(client_.id(), 11),
                        22));
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=22 node=1,2 new_view=1,11 old_view=null", changes[0]);
  }
}

// Sets view from one connection on another.
TEST_F(ViewManagerConnectionTest, SetViewFromSecondConnection) {
  EstablishSecondConnection();

  // Create two nodes in first connection.
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 2));

  EXPECT_TRUE(client_.GetAndClearChanges().empty());
  EXPECT_TRUE(client2_.GetAndClearChanges().empty());

  // Create a view in the second connection.
  ASSERT_TRUE(CreateView(view_manager2_.get(), 51));

  // Attach view to node 1 in the first connection.
  {
    ASSERT_TRUE(SetView(view_manager2_.get(),
                        CreateNodeId(client_.id(), 1),
                        CreateViewId(client2_.id(), 51),
                        22));
    client_.DoRunLoopUntilChangesCount(1);
    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=0 node=1,1 new_view=2,51 old_view=null", changes[0]);

    client2_.DoRunLoopUntilChangesCount(1);
    changes = client2_.GetAndClearChanges();
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=22 node=1,1 new_view=2,51 old_view=null", changes[0]);
  }

  // Shutdown the second connection and verify view is removed.
  {
    DestroySecondConnection();
    client_.DoRunLoopUntilChangesCount(1);

    Changes changes(client_.GetAndClearChanges());
    ASSERT_EQ(1u, changes.size());
    EXPECT_EQ("change_id=0 node=1,1 new_view=null old_view=2,51", changes[0]);
  }
}

// Assertions for GetNodeTree.
TEST_F(ViewManagerConnectionTest, GetNodeTree) {
  EstablishSecondConnection();

  // Create two nodes in first connection, 1 and 11 (11 is a child of 1).
  ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
  ASSERT_TRUE(CreateNode(view_manager_.get(), 11));
  ASSERT_TRUE(AddNode(view_manager_.get(),
                      CreateNodeId(0, 1),
                      CreateNodeId(client_.id(), 1),
                      101));
  ASSERT_TRUE(AddNode(view_manager_.get(),
                      CreateNodeId(client_.id(), 1),
                      CreateNodeId(client_.id(), 11),
                      102));

  // Create two nodes in second connection, 2 and 3, both children of the root.
  ASSERT_TRUE(CreateNode(view_manager2_.get(), 2));
  ASSERT_TRUE(CreateNode(view_manager2_.get(), 3));
  ASSERT_TRUE(AddNode(view_manager2_.get(),
                      CreateNodeId(0, 1),
                      CreateNodeId(client2_.id(), 2),
                      99));
  ASSERT_TRUE(AddNode(view_manager2_.get(),
                      CreateNodeId(0, 1),
                      CreateNodeId(client2_.id(), 3),
                      99));

  // Attach view to node 11 in the first connection.
  ASSERT_TRUE(CreateView(view_manager_.get(), 51));
  ASSERT_TRUE(SetView(view_manager_.get(),
                      CreateNodeId(client_.id(), 11),
                      CreateViewId(client_.id(), 51),
                      22));

  // Verifies GetNodeTree() on the root.
  {
    AllocationScope scope;
    std::vector<TestNode> nodes;
    GetNodeTree(view_manager2_.get(), CreateNodeId(0, 1), &nodes);
    ASSERT_EQ(5u, nodes.size());
    EXPECT_EQ("node=0,1 parent=null view=null", nodes[0].ToString());
    EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[1].ToString());
    EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[2].ToString());
    EXPECT_EQ("node=2,2 parent=0,1 view=null", nodes[3].ToString());
    EXPECT_EQ("node=2,3 parent=0,1 view=null", nodes[4].ToString());
  }

  // Verifies GetNodeTree() on the node 1,1.
  {
    AllocationScope scope;
    std::vector<TestNode> nodes;
    GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes);
    ASSERT_EQ(2u, nodes.size());
    EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString());
    EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString());
  }
}

}  // namespace view_manager
}  // namespace services
}  // namespace mojo