Commit e4f4e191 authored by kylechar's avatar kylechar Committed by Commit bot

Add unit test for mus_demo.

The unit test starts mus demo and checks that it successfully draws
compositor frames. Test is not setup to run on bots yet.

There is a problem where the WindowTree name isn't set to the client
name when the WindowTree is created for a WindowManager. Once this is
fixed EnsureClientHasDrawnWindow() should be using "mojo:mus_demo" as
the name it's looking for.

Also use this chance to fix some namespace stuff for MusDemo.

BUG=611473

Review-Url: https://codereview.chromium.org/2138433002
Cr-Commit-Position: refs/heads/master@{#405493}
parent 12caff1b
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import("//mojo/public/mojo_application.gni") import("//mojo/public/mojo_application.gni")
import("//mojo/public/mojo_application_manifest.gni") import("//mojo/public/mojo_application_manifest.gni")
import("//testing/test.gni")
mojo_native_application("mus_demo") { mojo_native_application("mus_demo") {
sources = [ sources = [
...@@ -35,6 +36,34 @@ mojo_application_manifest("manifest") { ...@@ -35,6 +36,34 @@ mojo_application_manifest("manifest") {
source = "manifest.json" source = "manifest.json"
} }
mojo_application_manifest("test_manifest") {
type = "exe"
application_name = "mus_demo_unittests"
source = "test_manifest.json"
}
test("mus_demo_unittests") {
testonly = true
sources = [
"mus_demo_unittests.cc",
]
deps = [
":demo",
"//base",
"//services/shell/public/cpp",
"//services/shell/public/cpp:service_test_support",
"//services/ui/common:run_all_shelltests",
"//services/ui/public/interfaces",
"//testing/gtest",
]
data_deps = [
":test_manifest",
]
}
group("demo") { group("demo") {
deps = [ deps = [
":mus_demo", ":mus_demo",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "services/ui/demo/mus_demo.h" #include "services/ui/demo/mus_demo.h"
MojoResult MojoMain(MojoHandle shell_handle) { MojoResult MojoMain(MojoHandle shell_handle) {
shell::ApplicationRunner runner(new mus_demo::MusDemo); shell::ApplicationRunner runner(new ui::demo::MusDemo);
runner.set_message_loop_type(base::MessageLoop::TYPE_UI); runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
return runner.Run(shell_handle); return runner.Run(shell_handle);
} }
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
#include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace mus_demo { namespace ui {
namespace demo {
namespace { namespace {
...@@ -67,8 +68,8 @@ void MusDemo::OnStart(shell::Connector* connector, ...@@ -67,8 +68,8 @@ void MusDemo::OnStart(shell::Connector* connector,
const shell::Identity& identity, const shell::Identity& identity,
uint32_t id) { uint32_t id) {
connector_ = connector; connector_ = connector;
ui::GpuService::Initialize(connector_); GpuService::Initialize(connector_);
window_tree_client_ = new ui::WindowTreeClient(this, this, nullptr); window_tree_client_ = new WindowTreeClient(this, this, nullptr);
window_tree_client_->ConnectAsWindowManager(connector); window_tree_client_->ConnectAsWindowManager(connector);
} }
...@@ -76,43 +77,42 @@ bool MusDemo::OnConnect(shell::Connection* connection) { ...@@ -76,43 +77,42 @@ bool MusDemo::OnConnect(shell::Connection* connection) {
return true; return true;
} }
void MusDemo::OnEmbed(ui::Window* window) { void MusDemo::OnEmbed(Window* window) {
// Not called for the WindowManager. // Not called for the WindowManager.
NOTREACHED(); NOTREACHED();
} }
void MusDemo::OnDidDestroyClient(ui::WindowTreeClient* client) { void MusDemo::OnDidDestroyClient(WindowTreeClient* client) {
window_tree_client_ = nullptr; window_tree_client_ = nullptr;
timer_.Stop(); timer_.Stop();
} }
void MusDemo::OnEventObserved(const ui::Event& event, ui::Window* target) {} void MusDemo::OnEventObserved(const Event& event, Window* target) {}
void MusDemo::SetWindowManagerClient(ui::WindowManagerClient* client) {} void MusDemo::SetWindowManagerClient(WindowManagerClient* client) {}
bool MusDemo::OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) { bool MusDemo::OnWmSetBounds(Window* window, gfx::Rect* bounds) {
return true; return true;
} }
bool MusDemo::OnWmSetProperty(ui::Window* window, bool MusDemo::OnWmSetProperty(Window* window,
const std::string& name, const std::string& name,
std::unique_ptr<std::vector<uint8_t>>* new_data) { std::unique_ptr<std::vector<uint8_t>>* new_data) {
return true; return true;
} }
ui::Window* MusDemo::OnWmCreateTopLevelWindow( Window* MusDemo::OnWmCreateTopLevelWindow(
std::map<std::string, std::vector<uint8_t>>* properties) { std::map<std::string, std::vector<uint8_t>>* properties) {
return nullptr; return nullptr;
} }
void MusDemo::OnWmClientJankinessChanged( void MusDemo::OnWmClientJankinessChanged(
const std::set<ui::Window*>& client_windows, const std::set<Window*>& client_windows,
bool janky) { bool janky) {
// Don't care // Don't care
} }
void MusDemo::OnWmNewDisplay(ui::Window* window, void MusDemo::OnWmNewDisplay(Window* window, const display::Display& display) {
const display::Display& display) {
DCHECK(!window_); // Only support one display. DCHECK(!window_); // Only support one display.
window_ = window; window_ = window;
...@@ -126,14 +126,14 @@ void MusDemo::OnWmNewDisplay(ui::Window* window, ...@@ -126,14 +126,14 @@ void MusDemo::OnWmNewDisplay(ui::Window* window,
base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); base::Bind(&MusDemo::DrawFrame, base::Unretained(this)));
} }
void MusDemo::OnWmPerformMoveLoop(ui::Window* window, void MusDemo::OnWmPerformMoveLoop(Window* window,
ui::mojom::MoveLoopSource source, mojom::MoveLoopSource source,
const gfx::Point& cursor_location, const gfx::Point& cursor_location,
const base::Callback<void(bool)>& on_done) { const base::Callback<void(bool)>& on_done) {
// Don't care // Don't care
} }
void MusDemo::OnWmCancelMoveLoop(ui::Window* window) {} void MusDemo::OnWmCancelMoveLoop(Window* window) {}
void MusDemo::AllocBitmap() { void MusDemo::AllocBitmap() {
const gfx::Rect bounds = window_->GetBoundsInRoot(); const gfx::Rect bounds = window_->GetBoundsInRoot();
...@@ -181,4 +181,5 @@ void MusDemo::DrawFrame() { ...@@ -181,4 +181,5 @@ void MusDemo::DrawFrame() {
bitmap_uploader::BitmapUploader::BGRA); bitmap_uploader::BitmapUploader::BGRA);
} }
} // namespace ui_demo } // namespace demo
} // namespace ui
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -22,14 +23,15 @@ namespace bitmap_uploader { ...@@ -22,14 +23,15 @@ namespace bitmap_uploader {
class BitmapUploader; class BitmapUploader;
} }
namespace mus_demo { namespace ui {
namespace demo {
// A simple MUS Demo mojo app. This app connects to the mojo:ui, creates a new // A simple MUS Demo mojo app. This app connects to the mojo:ui, creates a new
// window and draws a spinning square in the center of the window. Provides a // window and draws a spinning square in the center of the window. Provides a
// simple way to demonstrate that the graphic stack works as intended. // simple way to demonstrate that the graphic stack works as intended.
class MusDemo : public shell::Service, class MusDemo : public shell::Service,
public ui::WindowTreeClientDelegate, public WindowTreeClientDelegate,
public ui::WindowManagerDelegate { public WindowManagerDelegate {
public: public:
MusDemo(); MusDemo();
~MusDemo() override; ~MusDemo() override;
...@@ -42,28 +44,27 @@ class MusDemo : public shell::Service, ...@@ -42,28 +44,27 @@ class MusDemo : public shell::Service,
bool OnConnect(shell::Connection* connection) override; bool OnConnect(shell::Connection* connection) override;
// WindowTreeClientDelegate: // WindowTreeClientDelegate:
void OnEmbed(ui::Window* root) override; void OnEmbed(Window* root) override;
void OnDidDestroyClient(ui::WindowTreeClient* client) override; void OnDidDestroyClient(WindowTreeClient* client) override;
void OnEventObserved(const ui::Event& event, ui::Window* target) override; void OnEventObserved(const Event& event, Window* target) override;
// WindowManagerDelegate: // WindowManagerDelegate:
void SetWindowManagerClient(ui::WindowManagerClient* client) override; void SetWindowManagerClient(WindowManagerClient* client) override;
bool OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) override; bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override;
bool OnWmSetProperty( bool OnWmSetProperty(
ui::Window* window, Window* window,
const std::string& name, const std::string& name,
std::unique_ptr<std::vector<uint8_t>>* new_data) override; std::unique_ptr<std::vector<uint8_t>>* new_data) override;
ui::Window* OnWmCreateTopLevelWindow( Window* OnWmCreateTopLevelWindow(
std::map<std::string, std::vector<uint8_t>>* properties) override; std::map<std::string, std::vector<uint8_t>>* properties) override;
void OnWmClientJankinessChanged(const std::set<ui::Window*>& client_windows, void OnWmClientJankinessChanged(const std::set<Window*>& client_windows,
bool janky) override; bool janky) override;
void OnWmNewDisplay(ui::Window* window, void OnWmNewDisplay(Window* window, const display::Display& display) override;
const display::Display& display) override; void OnWmPerformMoveLoop(Window* window,
void OnWmPerformMoveLoop(ui::Window* window, mojom::MoveLoopSource source,
ui::mojom::MoveLoopSource source,
const gfx::Point& cursor_location, const gfx::Point& cursor_location,
const base::Callback<void(bool)>& on_done) override; const base::Callback<void(bool)>& on_done) override;
void OnWmCancelMoveLoop(ui::Window* window) override; void OnWmCancelMoveLoop(Window* window) override;
// Allocate a bitmap the same size as the window to draw into. // Allocate a bitmap the same size as the window to draw into.
void AllocBitmap(); void AllocBitmap();
...@@ -73,8 +74,8 @@ class MusDemo : public shell::Service, ...@@ -73,8 +74,8 @@ class MusDemo : public shell::Service,
shell::Connector* connector_ = nullptr; shell::Connector* connector_ = nullptr;
ui::Window* window_ = nullptr; Window* window_ = nullptr;
ui::WindowTreeClient* window_tree_client_ = nullptr; WindowTreeClient* window_tree_client_ = nullptr;
// Used to send frames to mus. // Used to send frames to mus.
std::unique_ptr<bitmap_uploader::BitmapUploader> uploader_; std::unique_ptr<bitmap_uploader::BitmapUploader> uploader_;
...@@ -91,6 +92,7 @@ class MusDemo : public shell::Service, ...@@ -91,6 +92,7 @@ class MusDemo : public shell::Service,
DISALLOW_COPY_AND_ASSIGN(MusDemo); DISALLOW_COPY_AND_ASSIGN(MusDemo);
}; };
} // namespace ui_demo } // namespace demo
} // namespace ui
#endif // SERVICES_UI_DEMO_MUS_DEMO_H_ #endif // SERVICES_UI_DEMO_MUS_DEMO_H_
// 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 "base/bind.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "services/shell/public/cpp/service_test.h"
#include "services/ui/public/interfaces/window_server_test.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ui {
namespace demo {
namespace {
const char kTestAppName[] = "exe:mus_demo_unittests";
void RunCallback(bool* success, const base::Closure& callback, bool result) {
*success = result;
callback.Run();
}
class MusDemoTest : public shell::test::ServiceTest {
public:
MusDemoTest() : shell::test::ServiceTest(kTestAppName) {}
~MusDemoTest() override {}
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch("use-test-config");
ServiceTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(MusDemoTest);
};
} // namespace
TEST_F(MusDemoTest, CheckMusDemoDraws) {
connector()->Connect("mojo:mus_demo");
::ui::mojom::WindowServerTestPtr test_interface;
connector()->ConnectToInterface("mojo:ui", &test_interface);
base::RunLoop run_loop;
bool success = false;
// TODO(kylechar): Fix WindowServer::CreateTreeForWindowManager so that the
// WindowTree has the correct name instead of an empty name.
test_interface->EnsureClientHasDrawnWindow(
"", // WindowTree name is empty.
base::Bind(&RunCallback, &success, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_TRUE(success);
}
} // namespace demo
} // namespace ui
{
"manifest_version": 1,
"name": "exe:mus_demo_unittests",
"display_name": "MUS Demo Unittests",
"capabilities": {
"required": {
"*": { "classes": [ "app", "test" ] },
"mojo:ui": { "interfaces": [ "ui::mojom::WindowServerTest" ] }
}
}
}
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