| // 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. |
| |
| #ifndef MOJO_UI_ASSOCIATES_TEST_HELPERS_H_ |
| #define MOJO_UI_ASSOCIATES_TEST_HELPERS_H_ |
| |
| #include <utility> |
| |
| #include "base/callback.h" |
| #include "mojo/services/ui/views/interfaces/view_associates.mojom.h" |
| |
| namespace test { |
| |
| template <typename T> |
| void Capture(const base::Closure& quit, T* out, T value) { |
| *out = std::move(value); |
| quit.Run(); |
| } |
| |
| inline mojo::PointFPtr MakePointF(float x, float y) { |
| auto result = mojo::PointF::New(); |
| result->x = x; |
| result->y = y; |
| return result.Pass(); |
| } |
| |
| inline mojo::TransformPtr MakeDummyTransform(float x) { |
| auto result = mojo::Transform::New(); |
| result->matrix.resize(16u); |
| result->matrix[0] = x; |
| return result.Pass(); |
| } |
| |
| inline mojo::gfx::composition::SceneTokenPtr MakeDummySceneToken( |
| uint32_t value) { |
| auto result = mojo::gfx::composition::SceneToken::New(); |
| result->value = value; |
| return result.Pass(); |
| } |
| |
| inline mojo::ui::ViewTokenPtr MakeDummyViewToken(uint32_t value) { |
| auto result = mojo::ui::ViewToken::New(); |
| result->value = value; |
| return result.Pass(); |
| } |
| |
| inline mojo::gfx::composition::HitTestResultPtr MakeSimpleHitTestResult( |
| mojo::gfx::composition::SceneTokenPtr scene_token, |
| mojo::TransformPtr transform) { |
| auto result = mojo::gfx::composition::HitTestResult::New(); |
| result->root = mojo::gfx::composition::SceneHit::New(); |
| result->root->scene_token = scene_token.Pass(); |
| result->root->hits.push_back(mojo::gfx::composition::Hit::New()); |
| result->root->hits[0]->set_node(mojo::gfx::composition::NodeHit::New()); |
| result->root->hits[0]->get_node()->transform = transform.Pass(); |
| return result.Pass(); |
| } |
| |
| inline mojo::gfx::composition::HitTestResultPtr MakeSimpleHitTestResult( |
| mojo::gfx::composition::SceneTokenPtr scene_token) { |
| return MakeSimpleHitTestResult(scene_token.Pass(), MakeDummyTransform(0.f)); |
| } |
| |
| } // namespace test |
| |
| #endif // MOJO_UI_ASSOCIATES_TEST_HELPERS_H_ |