Index: services/ui/view_manager/tests/view_associate_table_test.cc |
diff --git a/services/ui/view_manager/tests/view_associate_table_test.cc b/services/ui/view_manager/tests/view_associate_table_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..19d25ef65079fd372aa0dc7d45ff62cf0bf1aedc |
--- /dev/null |
+++ b/services/ui/view_manager/tests/view_associate_table_test.cc |
@@ -0,0 +1,65 @@ |
+// Copyright 2016 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 "mojo/services/ui/views/interfaces/view_manager.mojom.h" |
+#include "mojo/services/ui/views/interfaces/views.mojom.h" |
+#include "mojo/ui/associates/mock_view_inspector.h" |
+#include "services/ui/view_manager/tests/mock_view_associate.h" |
+#include "services/ui/view_manager/tests/view_manager_test_base.h" |
+#include "services/ui/view_manager/view_associate_table.h" |
+ |
+namespace view_manager { |
+namespace test { |
+ |
+class ViewAssociateTableTest : public ViewManagerTestBase { |
+ public: |
+ ViewAssociateTableTest() {} |
+ ~ViewAssociateTableTest() override {} |
+ |
+ void SetUp() override { ViewManagerTestBase::SetUp(); } |
+ |
+ // 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
|
+ // we are a friend class |
+ int GetViewAssociateTableSize( |
+ const ViewAssociateTable& view_associate_table) { |
+ return view_associate_table.associates_.size(); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ViewAssociateTableTest); |
+}; |
+ |
+TEST_F(ViewAssociateTableTest, RegisterViewAssociateThenCloseIt) { |
+ // Create a mock view registry |
+ mojo::ui::MockViewInspector mock_view_inspector; |
+ |
+ // Create a view associate table |
+ ViewAssociateTable view_associate_table; |
+ |
+ { |
+ // Create and bind a MockViewAssociate |
+ mojo::ui::ViewAssociatePtr associate; |
+ MockViewAssociate mock_view_associate; |
+ mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding( |
+ &mock_view_associate, mojo::GetProxy(&associate)); |
+ |
+ // call ViewAssociateTable::RegisterViewAssociate |
+ EXPECT_EQ(0, GetViewAssociateTableSize(view_associate_table)); |
+ |
+ ViewAssociateTable::AssociateConnectionErrorCallback null_callback; |
+ view_associate_table.RegisterViewAssociate(&mock_view_inspector, |
+ associate.Pass(), null_callback); |
+ KICK_MESSAGE_LOOP_WHILE(GetViewAssociateTableSize(view_associate_table) != |
+ 1); |
+ EXPECT_EQ(1, GetViewAssociateTableSize(view_associate_table)); |
+ } |
+ |
+ // ViewAssociate has been destroyed (since it's out of scope now) |
+ // Make sure it's been removed |
+ KICK_MESSAGE_LOOP_WHILE(GetViewAssociateTableSize(view_associate_table) != 0); |
+ EXPECT_EQ(0, GetViewAssociateTableSize(view_associate_table)); |
+} |
+ |
+} // namespace test |
+} // namespace view_manager |