OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h" | |
6 #include "mojo/services/ui/views/interfaces/views.mojom.h" | |
7 #include "mojo/ui/associates/mock_view_inspector.h" | |
8 #include "services/ui/view_manager/tests/mock_view_associate.h" | |
9 #include "services/ui/view_manager/tests/view_manager_test_base.h" | |
10 #include "services/ui/view_manager/view_associate_table.h" | |
11 | |
12 namespace view_manager { | |
13 namespace test { | |
14 | |
15 class ViewAssociateTableTest : public ViewManagerTestBase { | |
16 public: | |
17 ViewAssociateTableTest() {} | |
18 ~ViewAssociateTableTest() override {} | |
19 | |
20 void SetUp() override { ViewManagerTestBase::SetUp(); } | |
21 | |
22 // we have special permission to access ViewAssociateTable::associates_ since | |
jeffbrown
2016/05/11 23:44:16
Slightly cleaner way to do this is to add an "asso
| |
23 // we are a friend class | |
24 int GetViewAssociateTableSize( | |
25 const ViewAssociateTable& view_associate_table) { | |
26 return view_associate_table.associates_.size(); | |
27 } | |
28 | |
29 private: | |
30 DISALLOW_COPY_AND_ASSIGN(ViewAssociateTableTest); | |
31 }; | |
32 | |
33 TEST_F(ViewAssociateTableTest, RegisterViewAssociateThenCloseIt) { | |
34 // Create a mock view registry | |
35 mojo::ui::MockViewInspector mock_view_inspector; | |
36 | |
37 // Create a view associate table | |
38 ViewAssociateTable view_associate_table; | |
39 | |
40 { | |
41 // Create and bind a MockViewAssociate | |
42 mojo::ui::ViewAssociatePtr associate; | |
43 MockViewAssociate mock_view_associate; | |
44 mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding( | |
45 &mock_view_associate, mojo::GetProxy(&associate)); | |
46 | |
47 // call ViewAssociateTable::RegisterViewAssociate | |
48 EXPECT_EQ(0, GetViewAssociateTableSize(view_associate_table)); | |
49 | |
50 ViewAssociateTable::AssociateConnectionErrorCallback null_callback; | |
51 view_associate_table.RegisterViewAssociate(&mock_view_inspector, | |
52 associate.Pass(), null_callback); | |
53 KICK_MESSAGE_LOOP_WHILE(GetViewAssociateTableSize(view_associate_table) != | |
54 1); | |
55 EXPECT_EQ(1, GetViewAssociateTableSize(view_associate_table)); | |
56 } | |
57 | |
58 // ViewAssociate has been destroyed (since it's out of scope now) | |
59 // Make sure it's been removed | |
60 KICK_MESSAGE_LOOP_WHILE(GetViewAssociateTableSize(view_associate_table) != 0); | |
61 EXPECT_EQ(0, GetViewAssociateTableSize(view_associate_table)); | |
62 } | |
63 | |
64 } // namespace test | |
65 } // namespace view_manager | |
OLD | NEW |