Implement event sender service for testing
This service lets us send Mojo events during testing. R=eseidel@chromium.org, esprehn@chromium.org Review URL: https://codereview.chromium.org/716043002
This commit is contained in:
parent
50de29f59d
commit
41448b9de9
@ -0,0 +1,6 @@
|
|||||||
|
#BEGIN
|
||||||
|
Running 1 tests
|
||||||
|
ok 1 Sky event sender should be able to send events
|
||||||
|
1 tests
|
||||||
|
1 pass
|
||||||
|
0 fail
|
35
engine/src/flutter/tests/services/event-sender.sky
Normal file
35
engine/src/flutter/tests/services/event-sender.sky
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<sky>
|
||||||
|
<import src="../resources/chai.sky" />
|
||||||
|
<import src="../resources/mocha.sky" />
|
||||||
|
<import src="/mojo/services/public/interfaces/input_events/input_event_constants.mojom.sky" as="constants" />
|
||||||
|
<import src="/mojo/services/public/interfaces/input_events/input_events.mojom.sky" as="events" />
|
||||||
|
<import src="/sky/framework/shell.sky" as="shell" />
|
||||||
|
<import src="/sky/services/testing/test_harness.mojom.sky" as="harness" />
|
||||||
|
|
||||||
|
<script>
|
||||||
|
describe('Sky event sender', function() {
|
||||||
|
it('should be able to send events', function(done) {
|
||||||
|
var sky = document.querySelector('sky')
|
||||||
|
sky.focus();
|
||||||
|
sky.addEventListener('keypress', function(event) {
|
||||||
|
assert.equal(event.type, 'keypress');
|
||||||
|
assert.equal(event.keyCode, 0x41);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
var testHarness = shell.connectToService(
|
||||||
|
"mojo:sky_tester", harness.TestHarness);
|
||||||
|
testHarness.dispatchInputEvent(new events.Event({
|
||||||
|
action: constants.EventType.KEY_PRESSED,
|
||||||
|
key_data: new events.KeyData({
|
||||||
|
native_key_code: 0x41,
|
||||||
|
text: 0x41,
|
||||||
|
unmodified_text: 0x41,
|
||||||
|
is_char: true,
|
||||||
|
character: 0x41,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</sky>
|
@ -25,6 +25,7 @@ shared_library("tester") {
|
|||||||
"//mojo/services/public/cpp/view_manager",
|
"//mojo/services/public/cpp/view_manager",
|
||||||
"//mojo/services/public/interfaces/input_events",
|
"//mojo/services/public/interfaces/input_events",
|
||||||
"//mojo/services/window_manager:lib",
|
"//mojo/services/window_manager:lib",
|
||||||
|
"//sky/services/testing:bindings",
|
||||||
"//sky/viewer:bindings",
|
"//sky/viewer:bindings",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,10 @@ void TestHarnessImpl::OnTestComplete(const mojo::String& test_result) {
|
|||||||
test_runner_->OnTestComplete(test_result);
|
test_runner_->OnTestComplete(test_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestHarnessImpl::DispatchInputEvent(mojo::EventPtr event) {
|
||||||
|
if (test_runner_)
|
||||||
|
test_runner_->client()->DispatchInputEvent(event.Pass());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tester
|
} // namespace tester
|
||||||
} // namespace sky
|
} // namespace sky
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "mojo/public/cpp/application/interface_factory_impl.h"
|
#include "mojo/public/cpp/application/interface_factory_impl.h"
|
||||||
#include "mojo/public/cpp/system/core.h"
|
#include "mojo/public/cpp/system/core.h"
|
||||||
#include "sky/viewer/services/test_harness.mojom.h"
|
#include "sky/services/testing/test_harness.mojom.h"
|
||||||
|
|
||||||
namespace sky {
|
namespace sky {
|
||||||
namespace tester {
|
namespace tester {
|
||||||
@ -22,6 +22,7 @@ class TestHarnessImpl : public mojo::InterfaceImpl<TestHarness> {
|
|||||||
private:
|
private:
|
||||||
// TestHarness implementation.
|
// TestHarness implementation.
|
||||||
void OnTestComplete(const mojo::String& test_result) override;
|
void OnTestComplete(const mojo::String& test_result) override;
|
||||||
|
void DispatchInputEvent(mojo::EventPtr event) override;
|
||||||
|
|
||||||
base::WeakPtr<TestRunner> test_runner_;
|
base::WeakPtr<TestRunner> test_runner_;
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
namespace sky {
|
namespace sky {
|
||||||
namespace tester {
|
namespace tester {
|
||||||
|
|
||||||
|
TestRunnerClient::~TestRunnerClient() {
|
||||||
|
}
|
||||||
|
|
||||||
TestRunner::TestRunner(TestRunnerClient* client, mojo::View* container,
|
TestRunner::TestRunner(TestRunnerClient* client, mojo::View* container,
|
||||||
const std::string& url)
|
const std::string& url)
|
||||||
: test_harness_factory_(this),
|
: test_harness_factory_(this),
|
||||||
|
@ -18,6 +18,10 @@ namespace tester {
|
|||||||
class TestRunnerClient {
|
class TestRunnerClient {
|
||||||
public:
|
public:
|
||||||
virtual void OnTestComplete() = 0;
|
virtual void OnTestComplete() = 0;
|
||||||
|
virtual void DispatchInputEvent(mojo::EventPtr event) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual ~TestRunnerClient();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestRunner {
|
class TestRunner {
|
||||||
@ -26,6 +30,9 @@ class TestRunner {
|
|||||||
const std::string& url);
|
const std::string& url);
|
||||||
virtual ~TestRunner();
|
virtual ~TestRunner();
|
||||||
|
|
||||||
|
TestRunnerClient* client() const { return client_; }
|
||||||
|
TestHarnessFactory* test_harness_factory() { return &test_harness_factory_; }
|
||||||
|
|
||||||
base::WeakPtr<TestRunner> GetWeakPtr();
|
base::WeakPtr<TestRunner> GetWeakPtr();
|
||||||
void OnTestStart();
|
void OnTestStart();
|
||||||
void OnTestComplete(const std::string& test_result);
|
void OnTestComplete(const std::string& test_result);
|
||||||
|
@ -56,6 +56,8 @@ class SkyTester : public mojo::ApplicationDelegate,
|
|||||||
virtual bool ConfigureIncomingConnection(
|
virtual bool ConfigureIncomingConnection(
|
||||||
mojo::ApplicationConnection* connection) override {
|
mojo::ApplicationConnection* connection) override {
|
||||||
window_manager_app_->ConfigureIncomingConnection(connection);
|
window_manager_app_->ConfigureIncomingConnection(connection);
|
||||||
|
if (test_runner_)
|
||||||
|
connection->AddService(test_runner_->test_harness_factory());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +120,10 @@ class SkyTester : public mojo::ApplicationDelegate,
|
|||||||
ScheduleRun();
|
ScheduleRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DispatchInputEvent(mojo::EventPtr event) override {
|
||||||
|
window_manager_app_->DispatchInputEventToView(content_, event.Pass());
|
||||||
|
}
|
||||||
|
|
||||||
scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
|
scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
|
||||||
|
|
||||||
std::string url_from_args_;
|
std::string url_from_args_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user