Commit 8d12d2f9 authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

[OT-PW] Fix PaintWorkletProxyClientTest::Paint

The test was failing to actually add any global scopes, which we didn't
notice as it iterated over
PaintWorkletProxyClient::GetGlobalScopesForTesting - which was empty.
Properly add the global scopes and make sure the test validates that the
set is the right size.

Bug: None
Change-Id: I7d782106d19f2268a2191dceaabce1b68c7d852a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1576116Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652806}
parent d02fea3c
......@@ -66,6 +66,20 @@ class PaintWorkletProxyClientTest : public RenderingTest {
PaintWorkletProxyClient*,
base::WaitableEvent*);
void AddGlobalScopeOnWorkletThread(WorkerThread* worker_thread,
PaintWorkletProxyClient* proxy_client,
base::WaitableEvent* waitable_event) {
// The natural flow for PaintWorkletGlobalScope is to be registered with the
// proxy client during its first registerPaint call. Rather than circumvent
// this with a specialised AddGlobalScopeForTesting method, we just use the
// standard flow.
worker_thread->GlobalScope()->ScriptController()->Evaluate(
ScriptSourceCode(
"registerPaint('add_global_scope', class { paint() { } });"),
SanitizeScriptErrors::kDoNotSanitize);
waitable_event->Signal();
}
void RunMultipleGlobalScopeTestsOnWorklet(TestCallback callback) {
// PaintWorklet is stateless, and this is enforced via having multiple
// global scopes (which are switched between). To mimic the real world,
......@@ -77,6 +91,21 @@ class PaintWorkletProxyClientTest : public RenderingTest {
&GetDocument(), reporting_proxy_.get(), proxy_client_));
}
// Add the global scopes. This must happen on the worklet thread.
for (size_t i = 0; i < PaintWorklet::kNumGlobalScopes; i++) {
base::WaitableEvent waitable_event;
PostCrossThreadTask(
*worklet_threads[i]->GetTaskRunner(TaskType::kInternalTest),
FROM_HERE,
CrossThreadBind(
&PaintWorkletProxyClientTest::AddGlobalScopeOnWorkletThread,
CrossThreadUnretained(this),
CrossThreadUnretained(worklet_threads[i].get()),
CrossThreadPersistent<PaintWorkletProxyClient>(proxy_client_),
CrossThreadUnretained(&waitable_event)));
waitable_event.Wait();
}
// Now let the test actually run. We only run the test on the first worklet
// thread currently; this suffices since they share the proxy.
base::WaitableEvent waitable_event;
......@@ -88,7 +117,6 @@ class PaintWorkletProxyClientTest : public RenderingTest {
CrossThreadPersistent<PaintWorkletProxyClient>(proxy_client_),
CrossThreadUnretained(&waitable_event)));
waitable_event.Wait();
waitable_event.Reset();
// And finally clean up.
for (size_t i = 0; i < PaintWorklet::kNumGlobalScopes; i++) {
......@@ -100,7 +128,13 @@ class PaintWorkletProxyClientTest : public RenderingTest {
void RunPaintOnWorklet(WorkerThread* thread,
PaintWorkletProxyClient* proxy_client,
base::WaitableEvent* waitable_event) {
// Make sure to register the painter on all global scopes.
// Assert that all global scopes have been registered. Note that we don't
// use ASSERT_EQ here as that would crash the worklet thread and the test
// would timeout rather than fail.
EXPECT_EQ(proxy_client->GetGlobalScopesForTesting().size(),
PaintWorklet::kNumGlobalScopes);
// Register the painter on all global scopes.
for (const auto& global_scope : proxy_client->GetGlobalScopesForTesting()) {
global_scope->ScriptController()->Evaluate(
ScriptSourceCode("registerPaint('foo', class { paint() { } });"),
......
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