| Index: mojo/services/view_manager/view_manager_service_unittest.cc
|
| diff --git a/mojo/services/view_manager/view_manager_service_unittest.cc b/mojo/services/view_manager/view_manager_service_unittest.cc
|
| index 1079c933283020dc58a990dab04c3db91731a698..a08007a2e611069a2027f06ac659462b52370dd7 100644
|
| --- a/mojo/services/view_manager/view_manager_service_unittest.cc
|
| +++ b/mojo/services/view_manager/view_manager_service_unittest.cc
|
| @@ -5,7 +5,7 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| -#include "mojo/common/common_type_converters.h"
|
| +#include "base/message_loop/message_loop.h"
|
| #include "mojo/converters/geometry/geometry_type_converters.h"
|
| #include "mojo/public/interfaces/application/service_provider.mojom.h"
|
| #include "mojo/services/public/cpp/view_manager/types.h"
|
| @@ -18,6 +18,7 @@
|
| #include "mojo/services/view_manager/connection_manager_delegate.h"
|
| #include "mojo/services/view_manager/display_manager.h"
|
| #include "mojo/services/view_manager/ids.h"
|
| +#include "mojo/services/view_manager/server_view.h"
|
| #include "mojo/services/view_manager/test_change_tracker.h"
|
| #include "mojo/services/view_manager/view_manager_service_impl.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -113,12 +114,14 @@ class TestClientConnection : public ClientConnection {
|
| // Empty implementation of ConnectionManagerDelegate.
|
| class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
|
| public:
|
| - TestConnectionManagerDelegate() : last_client_(nullptr) {}
|
| + TestConnectionManagerDelegate() : last_connection_(nullptr) {}
|
| ~TestConnectionManagerDelegate() override {}
|
|
|
| - // TestViewManagerClient that was created by the last
|
| - // CreateClientConnectionForEmbedAtView() call.
|
| - TestViewManagerClient* last_client() { return last_client_; }
|
| + TestViewManagerClient* last_client() {
|
| + return last_connection_ ? last_connection_->client() : nullptr;
|
| + }
|
| +
|
| + TestClientConnection* last_connection() { return last_connection_; }
|
|
|
| private:
|
| // ConnectionManagerDelegate:
|
| @@ -132,12 +135,11 @@ class TestConnectionManagerDelegate : public ConnectionManagerDelegate {
|
| const ViewId& root_id) override {
|
| scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl(
|
| connection_manager, creator_id, creator_url, url, root_id));
|
| - TestClientConnection* connection = new TestClientConnection(service.Pass());
|
| - last_client_ = connection->client();
|
| - return connection;
|
| + last_connection_ = new TestClientConnection(service.Pass());
|
| + return last_connection_;
|
| }
|
|
|
| - TestViewManagerClient* last_client_;
|
| + TestClientConnection* last_connection_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
|
| };
|
| @@ -186,42 +188,238 @@ class ViewManagerServiceTest : public testing::Test {
|
| ViewManagerServiceTest() : wm_client_(nullptr) {}
|
| ~ViewManagerServiceTest() override {}
|
|
|
| + // ViewManagerServiceImpl for the window manager.
|
| + ViewManagerServiceImpl* wm_connection() {
|
| + return connection_manager_->GetConnection(1);
|
| + }
|
| +
|
| + TestViewManagerClient* last_view_manager_client() {
|
| + return delegate_.last_client();
|
| + }
|
| +
|
| + TestClientConnection* last_client_connection() {
|
| + return delegate_.last_connection();
|
| + }
|
| +
|
| + ConnectionManager* connection_manager() { return connection_manager_.get(); }
|
| +
|
| + TestViewManagerClient* wm_client() { return wm_client_; }
|
| +
|
| protected:
|
| // testing::Test:
|
| void SetUp() override {
|
| connection_manager_.reset(new ConnectionManager(
|
| &delegate_, scoped_ptr<DisplayManager>(new TestDisplayManager),
|
| &wm_internal_));
|
| -
|
| scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl(
|
| connection_manager_.get(), kInvalidConnectionId, std::string(),
|
| std::string("mojo:window_manager"), RootViewId()));
|
| scoped_ptr<TestClientConnection> client_connection(
|
| new TestClientConnection(service.Pass()));
|
| wm_client_ = client_connection->client();
|
| + ASSERT_TRUE(wm_client_ != nullptr);
|
| connection_manager_->SetWindowManagerClientConnection(
|
| client_connection.Pass());
|
| + ASSERT_TRUE(wm_connection() != nullptr);
|
| + ASSERT_TRUE(wm_connection()->root() != nullptr);
|
| }
|
|
|
| - // ViewManagerServiceImpl for the window manager.
|
| - ViewManagerServiceImpl* wm_connection() {
|
| - return connection_manager_->GetConnection(1);
|
| - }
|
| -
|
| + private:
|
| // TestViewManagerClient that is used for the WM connection.
|
| TestViewManagerClient* wm_client_;
|
|
|
| - private:
|
| TestWindowManagerInternal wm_internal_;
|
| TestConnectionManagerDelegate delegate_;
|
| scoped_ptr<ConnectionManager> connection_manager_;
|
| + base::MessageLoop message_loop_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceTest);
|
| };
|
|
|
| -TEST_F(ViewManagerServiceTest, Basic) {
|
| - wm_connection()->CreateView(ViewId(wm_connection()->id(), 1));
|
| - ASSERT_EQ(1u, wm_client_->tracker()->changes()->size());
|
| +namespace {
|
| +
|
| +const ServerView* GetFirstCloned(const ServerView* view) {
|
| + for (const ServerView* child : view->GetChildren()) {
|
| + if (child->id() == ClonedViewId())
|
| + return child;
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +// Provides common setup for animation tests. Creates the following views:
|
| +// 0,1 (the root, provided by view manager)
|
| +// 1,1 the second connection is embedded here (view owned by wm_connection()).
|
| +// 2,1 bounds=1,2 11x22
|
| +// 2,2 bounds=2,3 6x7
|
| +// 2,3 bounds=3,4 6x7
|
| +// CloneAndAnimate() is invoked for 2,2.
|
| +void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) {
|
| + *embed_view_id = ViewId(test->wm_connection()->id(), 1);
|
| + EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id));
|
| + EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()),
|
| + *embed_view_id));
|
| + EXPECT_TRUE(test->wm_connection()->Embed(
|
| + std::string(), *embed_view_id, InterfaceRequest<ServiceProvider>()));
|
| + ViewManagerServiceImpl* connection1 =
|
| + test->connection_manager()->GetConnectionWithRoot(*embed_view_id);
|
| + ASSERT_TRUE(connection1 != nullptr);
|
| + ASSERT_NE(connection1, test->wm_connection());
|
| +
|
| + const ViewId child1(connection1->id(), 1);
|
| + EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
|
| + const ViewId child2(connection1->id(), 2);
|
| + EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
|
| + const ViewId child3(connection1->id(), 3);
|
| + EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
|
| +
|
| + ServerView* v1 = connection1->GetView(child1);
|
| + v1->SetBounds(gfx::Rect(1, 2, 11, 22));
|
| + ServerView* v2 = connection1->GetView(child2);
|
| + v2->SetBounds(gfx::Rect(2, 3, 6, 7));
|
| + ServerView* v3 = connection1->GetView(child3);
|
| + v3->SetBounds(gfx::Rect(3, 4, 6, 7));
|
| +
|
| + EXPECT_TRUE(connection1->AddView(*embed_view_id, child1));
|
| + EXPECT_TRUE(connection1->AddView(child1, child2));
|
| + EXPECT_TRUE(connection1->AddView(child2, child3));
|
| +
|
| + TestViewManagerClient* connection1_client = test->last_view_manager_client();
|
| + connection1_client->tracker()->changes()->clear();
|
| + test->wm_client()->tracker()->changes()->clear();
|
| + EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2));
|
| + EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
|
| + EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty());
|
| +
|
| + // We cloned v2. The cloned view ends up as a sibling of it.
|
| + const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1));
|
| + ASSERT_TRUE(cloned_view);
|
| + // |cloned_view| should have one and only one cloned child (corresponds to
|
| + // |child3|).
|
| + ASSERT_EQ(1u, cloned_view->GetChildren().size());
|
| + EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
|
| +
|
| + // Cloned views should match the bounds of the view they were cloned from.
|
| + EXPECT_EQ(v2->bounds(), cloned_view->bounds());
|
| + EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds());
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(ViewManagerServiceTest, ConnectionsCantSeeClonedViews) {
|
| + ViewId embed_view_id;
|
| + EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
|
| +
|
| + ViewManagerServiceImpl* connection1 =
|
| + connection_manager()->GetConnectionWithRoot(embed_view_id);
|
| +
|
| + const ViewId child1(connection1->id(), 1);
|
| + const ViewId child2(connection1->id(), 2);
|
| + const ViewId child3(connection1->id(), 3);
|
| +
|
| + // Verify the root doesn't see any cloned views.
|
| + std::vector<const ServerView*> views(
|
| + wm_connection()->GetViewTree(*wm_connection()->root()));
|
| + ASSERT_EQ(5u, views.size());
|
| + ASSERT_TRUE(views[0]->id() == *wm_connection()->root());
|
| + ASSERT_TRUE(views[1]->id() == embed_view_id);
|
| + ASSERT_TRUE(views[2]->id() == child1);
|
| + ASSERT_TRUE(views[3]->id() == child2);
|
| + ASSERT_TRUE(views[4]->id() == child3);
|
| +
|
| + // Verify connection1 doesn't see any cloned views.
|
| + std::vector<const ServerView*> v1_views(
|
| + connection1->GetViewTree(embed_view_id));
|
| + ASSERT_EQ(4u, v1_views.size());
|
| + ASSERT_TRUE(v1_views[0]->id() == embed_view_id);
|
| + ASSERT_TRUE(v1_views[1]->id() == child1);
|
| + ASSERT_TRUE(v1_views[2]->id() == child2);
|
| + ASSERT_TRUE(v1_views[3]->id() == child3);
|
| +}
|
| +
|
| +TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnConnectionClose) {
|
| + ViewId embed_view_id;
|
| + EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
|
| +
|
| + // Destroy connection1, which should force the cloned view to become a child
|
| + // of where it was embedded (the embedded view still exists).
|
| + connection_manager()->OnConnectionError(last_client_connection());
|
| +
|
| + ServerView* embed_view = wm_connection()->GetView(embed_view_id);
|
| + ASSERT_TRUE(embed_view != nullptr);
|
| + const ServerView* cloned_view = GetFirstCloned(embed_view);
|
| + ASSERT_TRUE(cloned_view);
|
| + ASSERT_EQ(1u, cloned_view->GetChildren().size());
|
| + EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
|
| +
|
| + // Because the cloned view changed parents its bounds should have changed.
|
| + EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds());
|
| + // The bounds of the cloned child should not have changed though.
|
| + EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds());
|
| +}
|
| +
|
| +TEST_F(ViewManagerServiceTest, ClonedViewsPromotedOnHide) {
|
| + ViewId embed_view_id;
|
| + EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
|
| +
|
| + ViewManagerServiceImpl* connection1 =
|
| + connection_manager()->GetConnectionWithRoot(embed_view_id);
|
| +
|
| + // Hide the parent of the cloned view, which should force the cloned view to
|
| + // become a sibling of the parent.
|
| + const ServerView* view_to_hide =
|
| + connection1->GetView(ViewId(connection1->id(), 1));
|
| + ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false));
|
| +
|
| + const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent());
|
| + ASSERT_TRUE(cloned_view);
|
| + ASSERT_EQ(1u, cloned_view->GetChildren().size());
|
| + EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
|
| + EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size());
|
| + EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view);
|
| +}
|
| +
|
| +// Clone and animate on a tree with more depth. Basically that of
|
| +// SetUpAnimate1() but cloning 2,1.
|
| +TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) {
|
| + const ViewId embed_view_id(wm_connection()->id(), 1);
|
| + EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
|
| + EXPECT_TRUE(
|
| + wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
|
| + EXPECT_TRUE(wm_connection()->Embed(std::string(), embed_view_id,
|
| + InterfaceRequest<ServiceProvider>()));
|
| + ViewManagerServiceImpl* connection1 =
|
| + connection_manager()->GetConnectionWithRoot(embed_view_id);
|
| + ASSERT_TRUE(connection1 != nullptr);
|
| + ASSERT_NE(connection1, wm_connection());
|
| +
|
| + const ViewId child1(connection1->id(), 1);
|
| + EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
|
| + const ViewId child2(connection1->id(), 2);
|
| + EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
|
| + const ViewId child3(connection1->id(), 3);
|
| + EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
|
| +
|
| + ServerView* v1 = connection1->GetView(child1);
|
| +
|
| + EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
|
| + EXPECT_TRUE(connection1->AddView(child1, child2));
|
| + EXPECT_TRUE(connection1->AddView(child2, child3));
|
| +
|
| + TestViewManagerClient* connection1_client = last_view_manager_client();
|
| + connection1_client->tracker()->changes()->clear();
|
| + wm_client()->tracker()->changes()->clear();
|
| + EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1));
|
| + EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
|
| + EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
|
| +
|
| + // We cloned v1. The cloned view ends up as a sibling of it.
|
| + const ServerView* cloned_view = GetFirstCloned(v1->parent());
|
| + ASSERT_TRUE(cloned_view);
|
| + // |cloned_view| should have a child and its child should have a child.
|
| + ASSERT_EQ(1u, cloned_view->GetChildren().size());
|
| + const ServerView* cloned_view_child = cloned_view->GetChildren()[0];
|
| + EXPECT_EQ(1u, cloned_view_child->GetChildren().size());
|
| + EXPECT_TRUE(cloned_view_child->id() == ClonedViewId());
|
| }
|
|
|
| } // namespace service
|
|
|