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

chromeos: delete WindowTreeFactory before asserting no WindowTrees

WindowTreeFactory owns any WindowTrees that were created by way of
ui::mojom::WindowTreeFactory. So, WindowTreeFactory needs to be deleted before
the DCHECK that there are no more WindowTrees.

BUG=854336
TEST=covered by test

Change-Id: Idba2928244721579e694b434415b95cbbdf4b360
Reviewed-on: https://chromium-review.googlesource.com/1107136
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568859}
parent f014e5bb
......@@ -163,6 +163,7 @@ source_set("tests") {
"embedding_unittest.cc",
"focus_handler_unittest.cc",
"screen_provider_unittest.cc",
"window_service_unittest.cc",
"window_tree_client_unittest.cc",
"window_tree_unittest.cc",
]
......@@ -174,6 +175,7 @@ source_set("tests") {
"//components/viz/common",
"//mojo/public/cpp/bindings",
"//services/service_manager/public/cpp:service_test_support",
"//services/service_manager/public/cpp/test:test_support",
"//services/service_manager/public/mojom",
"//services/ui/common:task_runner_test_base",
"//services/ui/public/cpp",
......
......@@ -36,6 +36,9 @@ WindowService::WindowService(
}
WindowService::~WindowService() {
// WindowTreeFactory owns WindowTrees created by way of WindowTreeFactory.
// Deleting it should ensure there are no WindowTrees left.
window_tree_factory_.reset();
DCHECK(window_trees_.empty());
}
......
// 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.
#include "services/ui/ws2/window_service.h"
#include <memory>
#include "base/run_loop.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/test/test_connector_factory.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
#include "services/ui/ws2/gpu_interface_provider.h"
#include "services/ui/ws2/window_service_test_setup.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ui {
namespace ws2 {
TEST(WindowServiceTest, DeleteWithClients) {
// Use |test_setup| to configure aura and other state.
WindowServiceTestSetup test_setup;
// Create another WindowService.
TestWindowServiceDelegate test_window_service_delegate;
std::unique_ptr<WindowService> window_service_ptr =
std::make_unique<WindowService>(&test_window_service_delegate, nullptr,
test_setup.focus_controller());
WindowService* window_service = window_service_ptr.get();
std::unique_ptr<service_manager::TestConnectorFactory> factory =
service_manager::TestConnectorFactory::CreateForUniqueService(
std::move(window_service_ptr));
std::unique_ptr<service_manager::Connector> connector =
factory->CreateConnector();
// Connect to |window_service| and ask for a new WindowTree.
ui::mojom::WindowTreeFactoryPtr window_tree_factory;
connector->BindInterface(ui::mojom::kServiceName, &window_tree_factory);
ui::mojom::WindowTreePtr window_tree;
ui::mojom::WindowTreeClientPtr client;
mojom::WindowTreeClientRequest client_request = MakeRequest(&client);
window_tree_factory->CreateWindowTree(MakeRequest(&window_tree),
std::move(client));
// Use FlushForTesting() to ensure WindowService processes the request.
window_tree_factory.FlushForTesting();
// There should be at least one WindowTree.
EXPECT_FALSE(window_service->window_trees().empty());
// Destroying the |window_service| should remove all the WindowTrees and
// ensure a DCHECK isn't hit in ~WindowTree.
}
} // namespace ws2
} // namespace ui
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