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

Unified Diff: components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc

Issue 1568263003: Changes top level window creation to include window state in callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn Created 4 years, 11 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
« no previous file with comments | « components/mus/public/cpp/tests/BUILD.gn ('k') | components/mus/public/interfaces/window_tree.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
diff --git a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
index e46f2cdfbc8130ddf2a341f443941d5870037533..51c88c925cc7ba3ded9defcb2dafe786b907215c 100644
--- a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
+++ b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
@@ -18,6 +18,7 @@
#include "components/mus/public/cpp/window_observer.h"
#include "components/mus/public/cpp/window_property.h"
#include "components/mus/public/cpp/window_tree_delegate.h"
+#include "mojo/common/common_type_converters.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "mojo/converters/input_events/input_events_type_converters.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -508,7 +509,11 @@ TEST_F(WindowTreeClientImplTest, NewTopLevelWindow) {
uint32_t change_id;
ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
EXPECT_EQ(setup.window_tree()->window_id(), root2->id());
- setup.window_tree_client()->OnChangeCompleted(change_id, true);
+
+ mojom::WindowDataPtr data = mojom::WindowData::New();
+ data->window_id = root2->id();
+ data->viewport_metrics = mojom::ViewportMetrics::New();
+ setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data));
// Should not be able to add a top level as a child of another window.
root1->AddChild(root2);
@@ -521,4 +526,123 @@ TEST_F(WindowTreeClientImplTest, NewTopLevelWindow) {
EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u);
}
+TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsPropertiesFromData) {
+ WindowTreeSetup setup;
+ Window* root1 = setup.GetFirstRoot();
+ ASSERT_TRUE(root1);
+ Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr);
+ ASSERT_TRUE(root2);
+
+ EXPECT_FALSE(root2->IsDrawn());
+ EXPECT_FALSE(root2->visible());
+
+ // Ack the request to the windowtree to create the new window.
+ uint32_t change_id;
+ ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
+ EXPECT_EQ(setup.window_tree()->window_id(), root2->id());
+
+ mojom::WindowDataPtr data = mojom::WindowData::New();
+ data->window_id = root2->id();
+ data->viewport_metrics = mojom::ViewportMetrics::New();
+ data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2));
+ data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4));
+ data->visible = true;
+ data->drawn = true;
+ setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data));
+
+ // Make sure all the properties took.
+ EXPECT_TRUE(root2->IsDrawn());
+ EXPECT_TRUE(root2->visible());
+ EXPECT_EQ(gfx::Size(1, 2),
+ root2->viewport_metrics().size_in_pixels.To<gfx::Size>());
+ EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds());
+}
+
+TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) {
+ WindowTreeSetup setup;
+ Window* root1 = setup.GetFirstRoot();
+ ASSERT_TRUE(root1);
+ Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr);
+ ASSERT_TRUE(root2);
+
+ EXPECT_FALSE(root2->IsDrawn());
+ EXPECT_FALSE(root2->visible());
+
+ // Get the id of the in flight change for creating the new window.
+ uint32_t new_window_in_flight_change_id;
+ ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(
+ &new_window_in_flight_change_id));
+ EXPECT_EQ(setup.window_tree()->window_id(), root2->id());
+
+ // Make visibility go from false->true->false. Don't ack immediately.
+ root2->SetVisible(true);
+ uint32_t vis_in_flight_change_id1;
+ ASSERT_TRUE(
+ setup.window_tree()->GetAndClearChangeId(&vis_in_flight_change_id1));
+ EXPECT_NE(new_window_in_flight_change_id, vis_in_flight_change_id1);
+ root2->SetVisible(false);
+ uint32_t vis_in_flight_change_id2;
+ ASSERT_TRUE(
+ setup.window_tree()->GetAndClearChangeId(&vis_in_flight_change_id2));
+ EXPECT_NE(vis_in_flight_change_id1, vis_in_flight_change_id2);
+
+ // Change bounds to 5, 6, 7, 8.
+ root2->SetBounds(gfx::Rect(5, 6, 7, 8));
+ uint32_t bounds_in_flight_change_id;
+ ASSERT_TRUE(
+ setup.window_tree()->GetAndClearChangeId(&bounds_in_flight_change_id));
+ EXPECT_NE(vis_in_flight_change_id2, bounds_in_flight_change_id);
+
+ root2->SetSharedProperty<std::string>("xx", "client_xx");
+ uint32_t property_in_flight_change_id;
+ ASSERT_TRUE(
+ setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id));
+ EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id);
+
+ // Ack the new window top level window. Vis and bounds shouldn't change.
+ mojom::WindowDataPtr data = mojom::WindowData::New();
+ data->window_id = root2->id();
+ data->viewport_metrics = mojom::ViewportMetrics::New();
+ data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2));
+ data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4));
+ data->visible = true;
+ data->drawn = true;
+ data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx"));
+ data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy"));
+ setup.window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
+ std::move(data));
+
+ // The only value that should take effect is the property for 'yy' as it was
+ // not in flight.
+ EXPECT_TRUE(WindowPrivate(root2).drawn());
+ EXPECT_FALSE(root2->visible());
+ EXPECT_EQ(gfx::Size(1, 2),
+ root2->viewport_metrics().size_in_pixels.To<gfx::Size>());
+ EXPECT_EQ(gfx::Rect(5, 6, 7, 8), root2->bounds());
+ EXPECT_EQ(2u, root2->shared_properties().size());
+ ASSERT_TRUE(root2->HasSharedProperty("yy"));
+ EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy"));
+ ASSERT_TRUE(root2->HasSharedProperty("xx"));
+ EXPECT_EQ("client_xx", root2->GetSharedProperty<std::string>("xx"));
+
+ // Tell the client the changes failed. This should cause the values to change
+ // to that of the server.
+ setup.window_tree_client()->OnChangeCompleted(vis_in_flight_change_id1,
+ false);
+ EXPECT_FALSE(root2->visible());
+ setup.window_tree_client()->OnChangeCompleted(vis_in_flight_change_id2,
+ false);
+ EXPECT_TRUE(root2->visible());
+ setup.window_tree_client()->OnChangeCompleted(bounds_in_flight_change_id,
+ false);
+ EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds());
+ setup.window_tree_client()->OnChangeCompleted(property_in_flight_change_id,
+ false);
+ EXPECT_EQ(2u, root2->shared_properties().size());
+ ASSERT_TRUE(root2->HasSharedProperty("yy"));
+ EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy"));
+ ASSERT_TRUE(root2->HasSharedProperty("xx"));
+ EXPECT_EQ("server_xx", root2->GetSharedProperty<std::string>("xx"));
+}
+
} // namespace mus
« no previous file with comments | « components/mus/public/cpp/tests/BUILD.gn ('k') | components/mus/public/interfaces/window_tree.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698