Commit a7cb6918 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

window-service: removes EMBED_IN_OWNER

And replaces it with a boolean. This makes more sense as EMBED_IN_OWNER is
really something that changes depending upon whether the Window has an embedding
or not.

BUG=834487
TEST=covered by tests

Change-Id: If5d46331b1c54e329247996f3fc012448435aabf
Reviewed-on: https://chromium-review.googlesource.com/1239371
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595861}
parent 44a4cec2
......@@ -20,6 +20,7 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/property_converter.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/mus/window_tree_client_delegate.h"
#include "ui/aura/mus/window_tree_host_mus.h"
......@@ -124,8 +125,6 @@ TEST_F(AshServiceTest, OpenWindow) {
aura::CreateInitParamsForTopLevel(client.get(), std::move(properties)));
window_tree_host_mus.InitHost();
aura::Window* child_window = new aura::Window(nullptr);
child_window->SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
child_window->Init(ui::LAYER_NOT_DRAWN);
window_tree_host_mus.window()->AddChild(child_window);
......@@ -133,8 +132,8 @@ TEST_F(AshServiceTest, OpenWindow) {
// |child_window|. This blocks until it succeeds.
ws::mojom::WindowTreeClientPtr tree_client;
auto tree_client_request = MakeRequest(&tree_client);
client->Embed(child_window, std::move(tree_client), 0u,
base::BindOnce(&OnEmbed));
aura::WindowPortMus::Get(child_window)
->Embed(std::move(tree_client), 0u, base::BindOnce(&OnEmbed));
std::unique_ptr<aura::WindowTreeClient> child_client =
aura::WindowTreeClient::CreateForEmbedding(
connector(), &window_tree_delegate, std::move(tree_client_request),
......
......@@ -1980,8 +1980,6 @@ void RenderWidgetHostViewAura::CreateAuraWindow(aura::client::WindowType type) {
DCHECK(!is_mus_browser_plugin_guest_);
window_ = new aura::Window(this);
window_->SetName("RenderWidgetHostViewAura");
window_->SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
event_handler_->set_window(window_);
window_observer_.reset(new WindowObserver(this));
......
......@@ -250,6 +250,8 @@ jumbo_static_library("test_support") {
"test/mus/test_window_tree_client_delegate.h",
"test/mus/test_window_tree_client_setup.cc",
"test/mus/test_window_tree_client_setup.h",
"test/mus/window_port_mus_test_helper.cc",
"test/mus/window_port_mus_test_helper.h",
"test/mus/window_tree_client_private.cc",
"test/mus/window_tree_client_private.h",
"test/test_cursor_client.cc",
......
......@@ -24,8 +24,6 @@ DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT, void*)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT, SkColor)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT, int32_t)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT, int64_t)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT,
aura::client::WindowEmbedType)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT, aura::client::FocusClient*)
DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(AURA_EXPORT, aura::Window*)
......@@ -54,9 +52,6 @@ DEFINE_UI_CLASS_PROPERTY_KEY(Window*, kHostWindowKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kImmersiveFullscreenKey, false);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Size, kMinimumSize, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kMirroringEnabledKey, false);
DEFINE_UI_CLASS_PROPERTY_KEY(WindowEmbedType,
kEmbedType,
WindowEmbedType::NONE);
DEFINE_UI_CLASS_PROPERTY_KEY(Window*, kChildModalParentKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(ui::ModalType, kModalKey, ui::MODAL_TYPE_NONE);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kNameKey, nullptr);
......
......@@ -23,11 +23,6 @@ namespace aura {
namespace client {
class FocusClient;
enum class WindowEmbedType {
NONE,
EMBED_IN_OWNER,
};
// Alphabetical sort.
// A property key to store whether accessibility focus falls back to widget or
......@@ -155,9 +150,6 @@ AURA_EXPORT extern const WindowProperty<int>* const kTopViewInset;
// A property key to store the window icon, typically 16x16 for title bars.
AURA_EXPORT extern const WindowProperty<gfx::ImageSkia*>* const kWindowIconKey;
// Indicates the type of embedding within the given window.
AURA_EXPORT extern const WindowProperty<WindowEmbedType>* const kEmbedType;
// The corner radius of a window in DIPs. Currently only used for shadows.
// Default is -1, meaning "unspecified". 0 Ensures corners are square.
AURA_EXPORT extern const WindowProperty<int>* const kWindowCornerRadiusKey;
......
......@@ -113,19 +113,8 @@ std::unique_ptr<WindowPort> Env::CreateWindowPort(Window* window) {
return std::make_unique<WindowPortForShutdown>();
DCHECK(window_tree_client_);
WindowMusType window_mus_type;
switch (window->GetProperty(aura::client::kEmbedType)) {
case aura::client::WindowEmbedType::NONE:
window_mus_type = WindowMusType::LOCAL;
break;
case aura::client::WindowEmbedType::EMBED_IN_OWNER:
window_mus_type = WindowMusType::EMBED_IN_OWNER;
break;
default:
NOTREACHED();
}
// Use LOCAL as all other cases are created by WindowTreeClient explicitly.
return std::make_unique<WindowPortMus>(window_tree_client_, window_mus_type);
return std::make_unique<WindowPortMus>(window_tree_client_,
WindowMusType::LOCAL);
}
void Env::AddObserver(EnvObserver* observer) {
......
......@@ -8,6 +8,7 @@
#include "components/viz/common/hit_test/hit_test_region_list.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/mus/window_port_mus_test_helper.h"
#include "ui/aura/window.h"
#include "ui/aura/window_targeter.h"
#include "ui/gfx/geometry/rect.h"
......@@ -73,23 +74,17 @@ class HitTestDataProviderAuraTest : public test::AuraTestBaseMus {
test::AuraTestBaseMus::SetUp();
root_ = std::make_unique<Window>(nullptr);
root_->SetProperty(client::kEmbedType,
client::WindowEmbedType::EMBED_IN_OWNER);
root_->Init(ui::LAYER_NOT_DRAWN);
root_->SetEventTargeter(std::make_unique<WindowTargeter>());
root_->SetBounds(gfx::Rect(0, 0, 300, 200));
root_->Show();
window2_ = new Window(nullptr);
window2_->SetProperty(client::kEmbedType,
client::WindowEmbedType::EMBED_IN_OWNER);
window2_->Init(ui::LAYER_TEXTURED);
window2_->SetBounds(gfx::Rect(20, 30, 40, 60));
window2_->Show();
window3_ = new Window(nullptr);
window3_->SetProperty(client::kEmbedType,
client::WindowEmbedType::EMBED_IN_OWNER);
window3_->Init(ui::LAYER_TEXTURED);
window3_->SetEventTargeter(std::make_unique<WindowTargeter>());
window3_->SetBounds(gfx::Rect(50, 60, 100, 40));
......
......@@ -20,17 +20,9 @@ enum class WindowMusType {
// The window is an embed root in the embedded client. That is, the client
// received this window by way of another client calling Embed(). In other
// words, this is the embedded side of an embedding.
// NOTE: in the client that called Embed() the window type is LOCAL (or
// EMBED_IN_OWNER).
// TODO(sky): ensure when Embed() is called type is always set to
// EMBED_IN_OWNER, and if the embedding is removed it goes back to LOCAL.
// https://crbug.com/834487
// NOTE: in the client that called Embed() the window type is LOCAL.
EMBED,
// Embed() was called on the window by the local client. In other words, this
// is the embedder side of an embedding.
EMBED_IN_OWNER,
// The window was created by requesting a top level
// (WindowTree::NewTopLevel()).
TOP_LEVEL,
......
......@@ -98,16 +98,28 @@ void WindowPortMus::SetHitTestInsets(const gfx::Insets& mouse,
void WindowPortMus::Embed(ws::mojom::WindowTreeClientPtr client,
uint32_t flags,
ws::mojom::WindowTree::EmbedCallback callback) {
window_tree_client_->Embed(window_, std::move(client), flags,
std::move(callback));
if (!PrepareForEmbed()) {
std::move(callback).Run(false);
return;
}
window_tree_client_->tree_->Embed(
server_id(), std::move(client), flags,
base::BindOnce(&WindowPortMus::OnEmbedAck, weak_ptr_factory_.GetWeakPtr(),
std::move(callback)));
}
void WindowPortMus::EmbedUsingToken(
const base::UnguessableToken& token,
uint32_t flags,
ws::mojom::WindowTree::EmbedCallback callback) {
window_tree_client_->EmbedUsingToken(window_, token, flags,
std::move(callback));
if (!PrepareForEmbed()) {
std::move(callback).Run(false);
return;
}
window_tree_client_->tree_->EmbedUsingToken(
server_id(), token, flags,
base::BindOnce(&WindowPortMus::OnEmbedAck, weak_ptr_factory_.GetWeakPtr(),
std::move(callback)));
}
std::unique_ptr<cc::mojo_embedder::AsyncLayerTreeFrameSink>
......@@ -219,6 +231,43 @@ WindowPortMus::ServerChanges::iterator WindowPortMus::FindChangeByTypeAndData(
return iter;
}
bool WindowPortMus::PrepareForEmbed() {
// Window::Init() must be called before Embed() (otherwise the server hasn't
// been told about the window).
DCHECK(window_->layer());
// The window server removes all children before embedding. In other words,
// it's generally an error to Embed() with existing children. So, fail early.
if (!window_->children().empty())
return false;
// Can only embed in windows created by this client.
if (window_mus_type() != WindowMusType::LOCAL)
return false;
// Don't allow an embed when one exists. This could be handled, if the
// callback was converted to OnChangeCompleted(). To attempt to handle it
// without routing the callback over the WindowTreeClient pipe would result
// in problemcs because of ordering. The ordering problem is because there is
// the Embed() request, the callback, and OnEmbeddedAppDisconnected() (which
// originates from the server side).
if (has_embedding_)
return false;
has_embedding_ = true;
return true;
}
// static
void WindowPortMus::OnEmbedAck(
base::WeakPtr<WindowPortMus> window,
ws::mojom::WindowTree::EmbedCallback real_callback,
bool result) {
if (window && !result)
window->has_embedding_ = false;
std::move(real_callback).Run(window && result);
}
PropertyConverter* WindowPortMus::GetPropertyConverter() {
return window_tree_client_->delegate_->GetPropertyConverter();
}
......@@ -311,7 +360,6 @@ void WindowPortMus::SetPropertyFromServer(
void WindowPortMus::SetFrameSinkIdFromServer(
const viz::FrameSinkId& frame_sink_id) {
DCHECK(window_mus_type() == WindowMusType::EMBED_IN_OWNER);
embed_frame_sink_id_ = frame_sink_id;
window_->SetEmbedFrameSinkId(embed_frame_sink_id_);
UpdatePrimarySurfaceId();
......@@ -449,6 +497,7 @@ void WindowPortMus::PrepareForDestroy() {
}
void WindowPortMus::NotifyEmbeddedAppDisconnected() {
has_embedding_ = false;
for (WindowObserver& observer : *GetObservers(window_))
observer.OnEmbeddedAppDisconnected(window_);
}
......@@ -603,10 +652,8 @@ void WindowPortMus::UnregisterFrameSinkId(
}
void WindowPortMus::UpdatePrimarySurfaceId() {
if (window_mus_type() != WindowMusType::EMBED_IN_OWNER &&
window_mus_type() != WindowMusType::LOCAL) {
if (window_mus_type() != WindowMusType::LOCAL)
return;
}
if (!window_->IsEmbeddingClient() || !local_surface_id_.is_valid())
return;
......@@ -617,10 +664,8 @@ void WindowPortMus::UpdatePrimarySurfaceId() {
}
void WindowPortMus::UpdateClientSurfaceEmbedder() {
if (window_mus_type() != WindowMusType::EMBED_IN_OWNER &&
window_mus_type() != WindowMusType::LOCAL) {
if (!window_->IsEmbeddingClient())
return;
}
if (!client_surface_embedder_) {
client_surface_embedder_ = std::make_unique<ClientSurfaceEmbedder>(
......
......@@ -45,7 +45,6 @@ namespace aura {
class ClientSurfaceEmbedder;
class PropertyConverter;
class Window;
class WindowPortMusTest;
class WindowTreeClient;
class WindowTreeClientPrivate;
class WindowTreeHostMus;
......@@ -106,7 +105,7 @@ class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus {
viz::FrameSinkId GenerateFrameSinkIdFromServerId() const;
private:
friend class WindowPortMusTest;
friend class WindowPortMusTestHelper;
friend class WindowTreeClient;
friend class WindowTreeClientPrivate;
friend class WindowTreeHostMus;
......@@ -221,6 +220,16 @@ class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus {
ServerChanges::iterator FindChangeByTypeAndData(const ServerChangeType type,
const ServerChangeData& data);
// Called to setup state necessary for an embedding. Returns false if an
// embedding is not allowed in this window.
bool PrepareForEmbed();
// Called from OnEmbed() with the result of the embedding. |real_callback| is
// the callback supplied to the embed call.
static void OnEmbedAck(base::WeakPtr<WindowPortMus> window,
ws::mojom::WindowTree::EmbedCallback real_callback,
bool result);
PropertyConverter* GetPropertyConverter();
// WindowMus:
......@@ -317,6 +326,9 @@ class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus {
// See description in single place that changes the value for details.
bool should_restack_transient_children_ = true;
// True if this window has an embedding.
bool has_embedding_ = false;
// When a frame sink is created
// for a local aura::Window, we need keep a weak ptr of it, so we can update
// the local surface id when necessary.
......
......@@ -7,26 +7,15 @@
#include "cc/mojo_embedder/async_layer_tree_frame_sink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/mus/client_surface_embedder.h"
#include "ui/aura/test/aura_mus_test_base.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/mus/window_port_mus_test_helper.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_features.h"
namespace aura {
class WindowPortMusTest : public test::AuraTestBase {
public:
WindowPortMusTest() { EnableMusWithTestWindowTree(); }
~WindowPortMusTest() override = default;
base::WeakPtr<cc::LayerTreeFrameSink> GetFrameSinkFor(Window* window) {
auto* window_mus = WindowPortMus::Get(window);
return window_mus->local_layer_tree_frame_sink_;
}
private:
DISALLOW_COPY_AND_ASSIGN(WindowPortMusTest);
};
using WindowPortMusTest = test::AuraMusClientTestBase;
// TODO(sadrul): https://crbug.com/842361.
TEST_F(WindowPortMusTest,
......@@ -45,7 +34,7 @@ TEST_F(WindowPortMusTest,
window.CreateLayerTreeFrameSink());
EXPECT_TRUE(frame_sink.get());
auto mus_frame_sink = GetFrameSinkFor(&window);
auto mus_frame_sink = WindowPortMusTestHelper(&window).GetFrameSink();
ASSERT_TRUE(mus_frame_sink);
auto frame_sink_local_surface_id =
static_cast<cc::mojo_embedder::AsyncLayerTreeFrameSink*>(
......
......@@ -290,53 +290,12 @@ void WindowTreeClient::UnregisterFrameSinkId(WindowMus* window) {
tree_->UnattachFrameSinkId(window->server_id());
}
void WindowTreeClient::Embed(Window* window,
ws::mojom::WindowTreeClientPtr client,
uint32_t flags,
ws::mojom::WindowTree::EmbedCallback callback) {
DCHECK(tree_);
// Window::Init() must be called before Embed() (otherwise the server hasn't
// been told about the window).
DCHECK(window->layer());
if (!window->children().empty()) {
// The window server removes all children before embedding. In other words,
// it's generally an error to Embed() with existing children. So, fail
// early.
std::move(callback).Run(false);
return;
}
tree_->Embed(WindowMus::Get(window)->server_id(), std::move(client), flags,
std::move(callback));
}
void WindowTreeClient::ScheduleEmbed(
ws::mojom::WindowTreeClientPtr client,
base::OnceCallback<void(const base::UnguessableToken&)> callback) {
tree_->ScheduleEmbed(std::move(client), std::move(callback));
}
void WindowTreeClient::EmbedUsingToken(
Window* window,
const base::UnguessableToken& token,
uint32_t flags,
ws::mojom::WindowTree::EmbedCallback callback) {
DCHECK(tree_);
// Window::Init() must be called before Embed() (otherwise the server hasn't
// been told about the window).
DCHECK(window->layer());
if (!window->children().empty()) {
// The window server removes all children before embedding. In other words,
// it's generally an error to Embed() with existing children. So, fail
// early.
std::move(callback).Run(false);
return;
}
tree_->EmbedUsingToken(WindowMus::Get(window)->server_id(), token, flags,
std::move(callback));
}
void WindowTreeClient::AttachCompositorFrameSink(
ws::Id window_id,
viz::mojom::CompositorFrameSinkRequest compositor_frame_sink,
......@@ -736,16 +695,17 @@ void WindowTreeClient::ScheduleInFlightBoundsChange(
ScheduleInFlightChange(std::make_unique<InFlightBoundsChange>(
this, window, old_bounds, window->GetLocalSurfaceId()));
base::Optional<viz::LocalSurfaceId> local_surface_id;
if (window->window_mus_type() == WindowMusType::EMBED_IN_OWNER ||
if (window->GetWindow()->IsEmbeddingClient() ||
window->HasLocalLayerTreeFrameSink()) {
// Do not use ConvertRectToPixel, enclosing rects cause problems.
const gfx::Size size = gfx::ScaleToCeiledSize(
new_bounds.size(), window->GetDeviceScaleFactor());
local_surface_id = window->GetOrAllocateLocalSurfaceId(size);
// |window_tree_host| may be null if this is called during creation of
// the window associated with the WindowTreeHostMus.
// the window associated with the WindowTreeHostMus, or if there is an
// embedding.
WindowTreeHost* window_tree_host = window->GetWindow()->GetHost();
if (window_tree_host)
if (window_tree_host && window_tree_host->window() == window->GetWindow())
window_tree_host->compositor()->OnChildResizing();
}
tree_->SetWindowBounds(change_id, window->server_id(), new_bounds,
......
......@@ -145,19 +145,6 @@ class AURA_EXPORT WindowTreeClient
const viz::FrameSinkId& child_frame_sink_id);
void UnregisterFrameSinkId(WindowMus* window);
// Embeds a new client in |window|. |flags| is a bitmask of the values defined
// by kEmbedFlag*; 0 gives default behavior. |callback| is called to indicate
// whether the embedding succeeded or failed and may be called immediately if
// the embedding is known to fail.
void Embed(Window* window,
ws::mojom::WindowTreeClientPtr client,
uint32_t flags,
ws::mojom::WindowTree::EmbedCallback callback);
void EmbedUsingToken(Window* window,
const base::UnguessableToken& token,
uint32_t flags,
ws::mojom::WindowTree::EmbedCallback callback);
// Schedules an embed of a client. See
// ws::mojom::WindowTreeClient::ScheduleEmbed() for details.
void ScheduleEmbed(
......
......@@ -39,6 +39,7 @@
#include "ui/aura/mus/window_tree_host_mus_init_params.h"
#include "ui/aura/test/aura_mus_test_base.h"
#include "ui/aura/test/mus/test_window_tree.h"
#include "ui/aura/test/mus/window_port_mus_test_helper.h"
#include "ui/aura/test/mus/window_tree_client_private.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_delegate.h"
......@@ -273,11 +274,8 @@ TEST_F(WindowTreeClientTest, SetBoundsFailed) {
// reverted if the server replied that the change failed.
TEST_F(WindowTreeClientTest, SetBoundsFailedLocalSurfaceId) {
Window window(nullptr);
// TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate viz::LocalSurfaceIds
// when their sizes change.
window.SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
window.Init(ui::LAYER_NOT_DRAWN);
WindowPortMusTestHelper(&window).SimulateEmbedding();
const gfx::Rect original_bounds(window.bounds());
const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
......@@ -299,70 +297,26 @@ INSTANTIATE_TEST_CASE_P(/* no prefix */,
WindowTreeClientTestSurfaceSync,
::testing::Bool());
// Verifies that a ClientSurfaceEmbedder is created for a window once it has
// a bounds, and a valid FrameSinkId.
TEST_P(WindowTreeClientTestSurfaceSync, ClientSurfaceEmbedderOnValidEmbedding) {
// Verifies that windows with an embedding create a ClientSurfaceEmbedder.
TEST_P(WindowTreeClientTestSurfaceSync, ClientSurfaceEmbedderCreated) {
Window window(nullptr);
// EMBED_IN_OWNER windows allocate viz::LocalSurfaceIds when their sizes
// change.
window.SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
window.Init(ui::LAYER_NOT_DRAWN);
WindowPortMusTestHelper(&window).SimulateEmbedding();
// The window will allocate a viz::LocalSurfaceId once it has a bounds.
WindowMus* window_mus = WindowMus::Get(&window);
ASSERT_NE(nullptr, window_mus);
EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid());
gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
ASSERT_NE(new_bounds, window.bounds());
window.SetBounds(new_bounds);
EXPECT_EQ(new_bounds, window.bounds());
EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid());
// An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and
// a valid FrameSinkId.
WindowPortMus* window_port_mus = WindowPortMus::Get(&window);
ASSERT_NE(nullptr, window_port_mus);
EXPECT_FALSE(WindowMus::Get(&window)->GetLocalSurfaceId().is_valid());
// A ClientSurfaceEmbedder is only created once there is bounds and a
// FrameSinkId.
EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder());
// Now that the window has a valid FrameSinkId, it can embed the client in a
// CompositorFrame.
window_tree_client()->OnFrameSinkIdAllocated(server_id(&window),
viz::FrameSinkId(1, 1));
ClientSurfaceEmbedder* client_surface_embedder =
window_port_mus->client_surface_embedder();
ASSERT_NE(nullptr, client_surface_embedder);
}
// Verifies that EMBED_IN_OWNER windows do not gutter.
TEST_P(WindowTreeClientTestSurfaceSync, NoEmbedInOwnerGutter) {
Window window(nullptr);
// TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate viz::LocalSurfaceIds
// when their sizes change.
window.SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
window.Init(ui::LAYER_NOT_DRAWN);
// The window will allocate a viz::LocalSurfaceId once it has a bounds.
WindowMus* window_mus = WindowMus::Get(&window);
ASSERT_NE(nullptr, window_mus);
EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid());
gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
ASSERT_NE(new_bounds, window.bounds());
window.SetBounds(new_bounds);
EXPECT_EQ(new_bounds, window.bounds());
EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid());
// An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and
// a valid FrameSinkId.
WindowPortMus* window_port_mus = WindowPortMus::Get(&window);
ASSERT_NE(nullptr, window_port_mus);
EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder());
EXPECT_TRUE(WindowMus::Get(&window)->GetLocalSurfaceId().is_valid());
// Now that the window has a valid FrameSinkId, it can embed the client in a
// CompositorFrame.
window_tree_client()->OnFrameSinkIdAllocated(server_id(&window),
viz::FrameSinkId(1, 1));
// Once the bounds have been set, the ClientSurfaceEmbedder should be created.
ClientSurfaceEmbedder* client_surface_embedder =
window_port_mus->client_surface_embedder();
ASSERT_NE(nullptr, client_surface_embedder);
......@@ -376,11 +330,8 @@ TEST_P(WindowTreeClientTestSurfaceSync, NoEmbedInOwnerGutter) {
TEST_P(WindowTreeClientTestSurfaceSync, SetBoundsLocalSurfaceIdChanges) {
ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id());
Window window(nullptr);
// TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate viz::LocalSurfaceIds
// when their sizes change.
window.SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
window.Init(ui::LAYER_NOT_DRAWN);
WindowPortMusTestHelper(&window).SimulateEmbedding();
// Resize the window and verify that we've allocated a viz::LocalSurfaceId.
const gfx::Rect new_bounds(0, 0, 100, 100);
......
// Copyright 2017 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 "ui/aura/test/mus/window_port_mus_test_helper.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/window.h"
namespace aura {
// Start with something large that shouldn't conflict with any other values.
// static
uint32_t WindowPortMusTestHelper::next_client_id_ = 10001;
WindowPortMusTestHelper::WindowPortMusTestHelper(Window* window)
: window_port_mus_(WindowPortMus::Get(window)) {
DCHECK(window_port_mus_);
}
WindowPortMusTestHelper::~WindowPortMusTestHelper() = default;
void WindowPortMusTestHelper::SimulateEmbedding() {
window_port_mus_->GetWindow()->SetEmbedFrameSinkId(
viz::FrameSinkId(next_client_id_++, 1));
}
base::WeakPtr<cc::LayerTreeFrameSink> WindowPortMusTestHelper::GetFrameSink() {
return window_port_mus_->local_layer_tree_frame_sink_;
}
} // namespace aura
// Copyright 2018 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.
#ifndef UI_AURA_TEST_MUS_WINDOW_PORT_MUS_TEST_HELPER_H_
#define UI_AURA_TEST_MUS_WINDOW_PORT_MUS_TEST_HELPER_H_
#include <stdint.h>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
namespace cc {
class LayerTreeFrameSink;
}
namespace aura {
class Window;
class WindowPortMus;
class WindowPortMusTestHelper {
public:
explicit WindowPortMusTestHelper(Window* window);
~WindowPortMusTestHelper();
void SimulateEmbedding();
base::WeakPtr<cc::LayerTreeFrameSink> GetFrameSink();
private:
static uint32_t next_client_id_;
WindowPortMus* window_port_mus_;
DISALLOW_COPY_AND_ASSIGN(WindowPortMusTestHelper);
};
} // namespace aura
#endif // UI_AURA_TEST_MUS_WINDOW_PORT_MUS_TEST_HELPER_H_
......@@ -43,8 +43,6 @@ void RemoteViewHost::CreateEmbeddingRoot() {
embedding_root_->set_owned_by_parent(false);
embedding_root_->SetName("RemoteViewHostWindow");
embedding_root_->SetProperty(aura::client::kEmbedType,
aura::client::WindowEmbedType::EMBED_IN_OWNER);
embedding_root_->SetType(aura::client::WINDOW_TYPE_CONTROL);
embedding_root_->Init(ui::LAYER_NOT_DRAWN);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment