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

Unified Diff: services/ui/view_manager/tests/view_manager_test.cc

Issue 1949233002: Create a RegisterViewAssociate method in ViewManager (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add tests to mojo tests Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: services/ui/view_manager/tests/view_manager_test.cc
diff --git a/services/ui/view_manager/tests/view_manager_test.cc b/services/ui/view_manager/tests/view_manager_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..13e30c6fc1c5835bee3b9a7386d4c54cc13fa486
--- /dev/null
+++ b/services/ui/view_manager/tests/view_manager_test.cc
@@ -0,0 +1,174 @@
+// 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/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/connect.h"
+#include "mojo/services/ui/views/interfaces/view_manager.mojom.h"
+#include "mojo/services/ui/views/interfaces/views.mojom.h"
+#include "services/ui/view_manager/tests/mock_view_associate.h"
+#include "services/ui/view_manager/tests/view_manager_test_base.h"
+
+namespace view_manager {
+namespace test {
+
+class MockViewListener : public mojo::ui::ViewListener {
+ public:
+ MockViewListener() {}
+ ~MockViewListener() override {}
+
+ void OnPropertiesChanged(
+ uint32_t scene_version,
+ mojo::ui::ViewPropertiesPtr properties,
+ const OnPropertiesChangedCallback& callback) override {}
+};
+
+class ViewManagerTest : public ViewManagerTestBase {
+ public:
+ ViewManagerTest() {}
+ ~ViewManagerTest() override {}
+
+ void SetUp() override {
+ ViewManagerTestBase::SetUp();
+
+ // Connect to view manager
+ mojo::ConnectToService(shell(), "mojo:view_manager_service",
+ mojo::GetProxy(&view_manager_));
+ }
+
+ protected:
+ mojo::ui::ViewManagerPtr view_manager_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
+};
+
+TEST_F(ViewManagerTest, CreateAViewManagerAndView) {
+ // Create and bind a mock view listener
+ mojo::ui::ViewListenerPtr view_listener;
+ MockViewListener mock_view_listener;
+ mojo::Binding<mojo::ui::ViewListener> view_listener_binding(
+ &mock_view_listener, mojo::GetProxy(&view_listener));
+
+ // Create a view
+ mojo::ui::ViewPtr view;
+ mojo::ui::ViewOwnerPtr client_view_owner;
+ view_manager_->CreateView(mojo::GetProxy(&view),
+ mojo::GetProxy(&client_view_owner),
+ view_listener.Pass(), "test_view");
+
+ // Call View::GetToken. Check that you get the callback.
+ int view_token_callback_invokecount = 0;
+ auto view_token_callback = [&view_token_callback_invokecount](
+ mojo::ui::ViewTokenPtr token) { view_token_callback_invokecount++; };
+
+ EXPECT_EQ(0, view_token_callback_invokecount);
+ view->GetToken(view_token_callback);
+
+ KICK_MESSAGE_LOOP_WHILE(view_token_callback_invokecount != 1);
+
+ EXPECT_EQ(1, view_token_callback_invokecount);
+}
+
+TEST_F(ViewManagerTest, ConnectAMockViewAssociate) {
+ // Create and bind a MockViewAssociate
+ mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate;
+ MockViewAssociate mock_view_associate;
+ mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding(
+ &mock_view_associate, mojo::GetProxy(&associate));
+
+ // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect
+ // should be called back
+ EXPECT_EQ(0, mock_view_associate.connect_invokecount);
+ mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
+ view_manager_->RegisterViewAssociate(associate.Pass(),
+ mojo::GetProxy(&view_associate_owner),
+ "test_view_associate");
+
+ KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1);
+
+ EXPECT_EQ(1, mock_view_associate.connect_invokecount);
+}
+
+TEST_F(ViewManagerTest, DisconnectAMockViewAssociate) {
+ mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
+ int owner_connection_error_callback_invokecount = 0;
+
+ {
+ // Create and bind a MockViewAssociate
+ mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate;
+ MockViewAssociate mock_view_associate;
+ mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding(
+ &mock_view_associate, mojo::GetProxy(&associate));
+
+ // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect
+ // should be called back
+ EXPECT_EQ(0, mock_view_associate.connect_invokecount);
+
+ view_manager_->RegisterViewAssociate(associate.Pass(),
+ mojo::GetProxy(&view_associate_owner),
+ "test_view_associate_xyz");
+
+ // set a callback for errors
+ view_associate_owner.set_connection_error_handler(
+ // use lambda function as callback
+ [&owner_connection_error_callback_invokecount]() {
+ owner_connection_error_callback_invokecount++;
+ });
+
+ KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1);
+
+ EXPECT_EQ(1, mock_view_associate.connect_invokecount);
+
+ EXPECT_EQ(0, owner_connection_error_callback_invokecount);
+ }
+
+ // mock_view_associate is out of scope, should be destroyed
+ // we expect to get a connection error from the owner
+ KICK_MESSAGE_LOOP_WHILE(owner_connection_error_callback_invokecount != 1)
+
+ EXPECT_EQ(1, owner_connection_error_callback_invokecount);
+}
+
+TEST_F(ViewManagerTest, DisconnectAViewAssociateOwner) {
+ // Create and bind a MockViewAssociate
+ mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate;
+ MockViewAssociate mock_view_associate;
+ mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding(
+ &mock_view_associate, mojo::GetProxy(&associate));
+
+ // set a callback for errors
+ int connection_error_callback_invokecount = 0;
+ view_associate_binding.set_connection_error_handler(
+ // use lambda function as callback
+ [&connection_error_callback_invokecount]() {
+ connection_error_callback_invokecount++;
+ });
+
+ {
+ mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
+
+ // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect
+ // should be called back
+ EXPECT_EQ(0, mock_view_associate.connect_invokecount);
+
+ view_manager_->RegisterViewAssociate(associate.Pass(),
+ mojo::GetProxy(&view_associate_owner),
+ "test_view_associate_xyz");
+
+ KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1);
+
+ EXPECT_EQ(1, mock_view_associate.connect_invokecount);
+
+ EXPECT_EQ(0, connection_error_callback_invokecount);
+ }
+
+ // view_associate_owner is out of scope, should be destroyed
+ // we expect to get a connection error from the view associate
+ KICK_MESSAGE_LOOP_WHILE(connection_error_callback_invokecount != 1)
+
+ EXPECT_EQ(1, connection_error_callback_invokecount);
+}
+
+} // namespace test
+} // namespace view_manager
« no previous file with comments | « services/ui/view_manager/tests/view_associate_table_test.cc ('k') | services/ui/view_manager/tests/view_manager_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698