Commit 8c23d7c6 authored by Ken Rockot's avatar Ken Rockot Committed by Chromium LUCI CQ

Migrate presentation web tests to WPT+Mojo modules

This moves the presentation web tests into wpt_internal and adapts them
to use the newer Mojo JS modules. Since this already produces quite a
bit of churn in the tests, the tests here are also opportunistically
modernized where feasible, particularly concerning asynchronous logic.

Bug: 1004256
Change-Id: I5515325cfc808cd5f0e7dff51840a94c4078b4b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634278
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846373}
parent fa0f4721
...@@ -1552,9 +1552,6 @@ mojo.internal.InterfaceProxy = function(type) { ...@@ -1552,9 +1552,6 @@ mojo.internal.InterfaceProxy = function(type) {
return { return {
$: { $: {
encode: function(value, encoder, byteOffset, bitOffset, nullable) { encode: function(value, encoder, byteOffset, bitOffset, nullable) {
if (!(value instanceof type))
throw new Error('Invalid proxy type. Expected ' + type.name);
const endpoint = value.proxy.unbind(); const endpoint = value.proxy.unbind();
console.assert(endpoint, `unexpected null ${type.name}`); console.assert(endpoint, `unexpected null ${type.name}`);
...@@ -1582,8 +1579,6 @@ mojo.internal.InterfaceRequest = function(type) { ...@@ -1582,8 +1579,6 @@ mojo.internal.InterfaceRequest = function(type) {
return { return {
$: { $: {
encode: function(value, encoder, byteOffset, bitOffset, nullable) { encode: function(value, encoder, byteOffset, bitOffset, nullable) {
if (!(value instanceof type))
throw new Error('Invalid request type. Expected ' + type.name);
if (!value.handle) if (!value.handle)
throw new Error('Unexpected null ' + type.name); throw new Error('Unexpected null ' + type.name);
...@@ -1610,9 +1605,6 @@ mojo.internal.AssociatedInterfaceProxy = function(type) { ...@@ -1610,9 +1605,6 @@ mojo.internal.AssociatedInterfaceProxy = function(type) {
$: { $: {
type: type, type: type,
encode: function(value, encoder, byteOffset, bitOffset, nullable) { encode: function(value, encoder, byteOffset, bitOffset, nullable) {
console.assert(
value instanceof type,
`unexpected object in place of ${type.name}: `, value);
console.assert( console.assert(
value.proxy.endpoint && value.proxy.endpoint.isPendingAssociation, value.proxy.endpoint && value.proxy.endpoint.isPendingAssociation,
`expected ${type.name} to be associated and unbound`); `expected ${type.name} to be associated and unbound`);
...@@ -1644,9 +1636,6 @@ mojo.internal.AssociatedInterfaceRequest = function(type) { ...@@ -1644,9 +1636,6 @@ mojo.internal.AssociatedInterfaceRequest = function(type) {
$: { $: {
type: type, type: type,
encode: function(value, encoder, byteOffset, bitOffset, nullable) { encode: function(value, encoder, byteOffset, bitOffset, nullable) {
console.assert(
value instanceof type,
`unexpected object in place of ${type.name}: `, value);
console.assert( console.assert(
value.handle && value.handle.isPendingAssociation, value.handle && value.handle.isPendingAssociation,
`expected ${type.name} to be associated and unbound`); `expected ${type.name} to be associated and unbound`);
......
mfoltz@chromium.org mfoltz@chromium.org
mlamouri@chromium.org mlamouri@chromium.org
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
...@@ -847,7 +847,6 @@ plugins/instance-available-before-stylesheets-loaded.html ...@@ -847,7 +847,6 @@ plugins/instance-available-before-stylesheets-loaded.html
pointer-lock/lock-already-locked.html pointer-lock/lock-already-locked.html
pointer-lock/mouse-event-api.html pointer-lock/mouse-event-api.html
pointer-lock/pointerlockelement-null-when-pending.html pointer-lock/pointerlockelement-null-when-pending.html
presentation/presentationconnectionavailableevent-ctor-mock.html
printing/css2.1/page-break-after-000.html printing/css2.1/page-break-after-000.html
printing/css2.1/page-break-before-001.html printing/css2.1/page-break-before-001.html
screen_orientation/screenorientation-api.html screen_orientation/screenorientation-api.html
...@@ -987,4 +986,5 @@ webexposed/internal-properties-should-not-be-exposed.html ...@@ -987,4 +986,5 @@ webexposed/internal-properties-should-not-be-exposed.html
webexposed/permissions-attribute.html webexposed/permissions-attribute.html
webexposed/web-animations-api.html webexposed/web-animations-api.html
wpt_internal/geolocation-api/enabled.html wpt_internal/geolocation-api/enabled.html
wpt_internal/presentation/presentationconnectionavailableevent-ctor-mock.html
wpt_internal/webmidi/permission.html wpt_internal/webmidi/permission.html
...@@ -4334,7 +4334,6 @@ crbug.com/778467 [ Fuchsia ] mhtml/mhtml_in_iframe.html [ Failure ] ...@@ -4334,7 +4334,6 @@ crbug.com/778467 [ Fuchsia ] mhtml/mhtml_in_iframe.html [ Failure ]
# These tests load resources from file:///gen/... . # These tests load resources from file:///gen/... .
crbug.com/919639 [ Fuchsia ] fast/speech/scripted/speechrecognition-re-restart.html [ Failure ] crbug.com/919639 [ Fuchsia ] fast/speech/scripted/speechrecognition-re-restart.html [ Failure ]
crbug.com/919639 [ Fuchsia ] presentation/presentationconnectionavailableevent-ctor-mock.html [ Failure ]
# These tests timeout when using Scenic ozone platform. # These tests timeout when using Scenic ozone platform.
crbug.com/1067477 [ Fuchsia ] fast/media/matchmedium-query-api.html [ Skip ] crbug.com/1067477 [ Fuchsia ] fast/media/matchmedium-query-api.html [ Skip ]
......
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
var button = document.querySelector('button');
var receiverConnectionClosed = false;
var connection = null;
async_test(t => {
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
new PresentationRequest("https://example.com/").start().then(
theConnection => {
connection = theConnection;
connection.onclose = (closeEvent) => {
assert_equals(closeEvent.reason, "closed");
assert_equals(closeEvent.message, "");
assert_equals(connection.state, "closed");
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
w = window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = presentationServiceMock.getControllerConnectionPtr();
w.receiverConnectionRequest = presentationServiceMock.getReceiverConnectionRequest();
w.shouldCallClose = false;
});
}, button);
window.addEventListener("message", t.step_func(e => {
if (e.data == "receiver connection closed") {
receiverConnectionClosed = true;
t.done();
} else if (e.data == "receiver connection ready") {
assert_not_equals(connection, null);
connection.close();
assert_equals(connection.state, "closed");
}
}));
}, "controller connection.close() should fire both controller's and receiver's onclose event handler");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
var button = document.querySelector('button');
var controllerConnectionClosed = false;
async_test(t => {
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
new PresentationRequest("https://example.com/").start().then(
connection => {
connection.onclose = (closeEvent) => {
assert_equals(closeEvent.reason, "closed");
assert_equals(closeEvent.message, "");
assert_equals(connection.state, "closed");
controllerConnectionClosed = true;
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
w = window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = presentationServiceMock.getControllerConnectionPtr();
w.receiverConnectionRequest = presentationServiceMock.getReceiverConnectionRequest();
w.shouldCallClose = true;
});
}, button);
window.addEventListener("message", t.step_func(e => {
if (e.data == "receiver connection closed") {
assert_true(controllerConnectionClosed);
t.done();
}
}));
}, "receiver connection.close() should fire both controller's and receiver's onclose event handler");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
async_test(t => {
const button = document.querySelector('button');
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
new PresentationRequest('https://example.com').start().then(
connection => {
connection.onterminate = t.step_func_done();
connection.onconnect = () => {
connection.terminate();
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
w = window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = presentationServiceMock.getControllerConnectionPtr();
w.receiverConnectionRequest = presentationServiceMock.getReceiverConnectionRequest();
w.shouldCallClose = false;
});
}, button);
}, "Test that controller connection.terminate() fires onterminate event handler.");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<script>
async_test(t => {
internals.settings.setPresentationReceiver(true);
t.add_cleanup(_ => { internals.settings.setPresentationReceiver(false); });
const url = 'https://example.com/a.html';
const id = 'fakePresentationId';
presentationServiceMock.onSetReceiver = () => {
presentationServiceMock.onReceiverConnectionAvailable(url, id);
};
navigator.presentation.receiver.connectionList.then(
t.step_func_done(list => {
assert_equals(list.connections.length, 1);
assert_equals(list.connections[0].url, url);
assert_equals(list.connections[0].id, id);
}));
}, "Test presentation.receiver.connectionList resolves with incoming connection.");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
var button = document.querySelector('button');
var controllerConnectionTerminated = false;
async_test(t => {
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
new PresentationRequest("https://example.com/").start().then(
connection => {
connection.onterminate = () => {
assert_equals(connection.state, "terminated");
controllerConnectionTerminated = true;
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
var w = window.open(
"resources/presentation-receiver-postmessage.html");
w.controllerConnectionPtr = presentationServiceMock.getControllerConnectionPtr();
w.receiverConnectionRequest = presentationServiceMock.getReceiverConnectionRequest();
});
}, button);
window.addEventListener("message", t.step_func(e => {
if (e.data == "passed" || e.data == "failed") {
assert_equals("passed", e.data, "Receiver connection is terminated!");
assert_true(controllerConnectionTerminated);
t.done();
}
}));
}, "receiver connection.terminate() should close receiver frame");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/gc.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
async_test(t => {
var button = document.querySelector('button');
var connection = null;
var request = new PresentationRequest('https://example.com');
waitForClick(_ => {
request.start().then(conn => {
connection = conn;
assert_not_equals(connection, null);
request.reconnect(connection.id).then(
t.step_func_done(conn => {
assert_true(connection === conn);
}));
});
}, button);
}, "Test that Presentation.reconnect() resolves with existing presentation connection.");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
var button = document.querySelector('button');
async_test(t => {
presentationServiceMock.startPresentation = urls => {
return Promise.resolve({
presentation_info: null,
error: {
errorType: blink.mojom.PresentationErrorType.PREVIOUS_START_IN_PROGRESS,
message: 'Previous start in progress'
}
});
};
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
var request = new PresentationRequest("https://example.com");
request.start().catch(t.step_func_done(ex => {
assert_equals(ex.name, 'OperationError');
}));
}, button);
}, "Test that the PresentationRequest.start() rejects with OperationError if PresentationService reports PREVIOUS_START_IN_PROGRESS error");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button>
<script>
var button = document.querySelector('button');
var testPresentationRequestStart = function(t, requestArgument, connectionUrl) {
// This is receiving the user gesture and runs the callback.
waitForClick(() => {
new PresentationRequest(requestArgument).start().then(
t.step_func_done(connection => {
assert_equals(connection.url, connectionUrl);
assert_equals(connection.state, 'connecting');
}));
}, button);
};
async_test(t => {
var presentationUrl = "https://example.com/example.html";
testPresentationRequestStart(t, presentationUrl, presentationUrl);
}, "Test that the PresentationRequest.start() with single URL resolves with correct PresentationConnection object.");
async_test(t => {
var presentationUrls = ["https://example.com/example.html", "cast://google.com/app_id=deadbeef"];
testPresentationRequestStart(t, presentationUrls, presentationUrls[0]);
}, "Test that the PresentationRequest.start() with multiple URLs resolves with correct PresentationConnection object.");
async_test(t => {
var presentationUrl = "https://example.com/\ud801/example.html";
var connectionUrl = "https://example.com/" + encodeURIComponent('\ufffd') + "/example.html"
testPresentationRequestStart(t, presentationUrl, connectionUrl);
}, "Test that the PresentationRequest.start() with single URL containing special symbol resolves with correct PresentationConnection object.");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
promise_test(async _ => {
let receiverConnectionClosed = false;
await waitForClick(button);
const connection =
await new PresentationRequest("https://example.com/").start();
connection.onclose = closeEvent => {
assert_equals(closeEvent.reason, "closed");
assert_equals(closeEvent.message, "");
assert_equals(connection.state, "closed");
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
const w =
window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = mock.getControllerConnectionPtr();
w.receiverConnectionRequest = mock.getReceiverConnectionRequest();
w.shouldCallClose = false;
return new Promise(resolve => {
window.addEventListener("message", e => {
if (e.data == "receiver connection closed") {
receiverConnectionClosed = true;
resolve();
} else if (e.data == "receiver connection ready") {
connection.close();
assert_equals(connection.state, "closed");
}
});
});
}, "controller connection.close() should fire both controller's and receiver's onclose event handler");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
promise_test(async _ => {
let controllerConnectionClosed = false;
await waitForClick(button);
const connection =
await new PresentationRequest("https://example.com/").start();
connection.onclose = closeEvent => {
assert_equals(closeEvent.reason, "closed");
assert_equals(closeEvent.message, "");
assert_equals(connection.state, "closed");
controllerConnectionClosed = true;
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
const w =
window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = mock.getControllerConnectionPtr();
w.receiverConnectionRequest = mock.getReceiverConnectionRequest();
w.shouldCallClose = true;
return new Promise(resolve => {
window.addEventListener("message", e => {
if (e.data == "receiver connection closed") {
assert_true(controllerConnectionClosed);
resolve();
}
});
});
}, "receiver connection.close() should fire both controller's and receiver's onclose event handler");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
promise_test(async _ => {
await waitForClick(button);
return new Promise(async resolve => {
const connection =
await new PresentationRequest('https://example.com').start();
connection.onconnect = () => connection.terminate();
connection.onterminate = resolve;
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
const w = window.open("resources/presentation-receiver-close-connection.html");
w.controllerConnectionPtr = mock.getControllerConnectionPtr();
w.receiverConnectionRequest = mock.getReceiverConnectionRequest();
w.shouldCallClose = false;
});
}, "Test that controller connection.terminate() fires onterminate event handler.");
</script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<iframe></iframe> <iframe></iframe>
<script> <script>
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<iframe></iframe> <iframe></iframe>
<script> <script>
......
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import {PresentationServiceMock} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
promise_test(async t => {
internals.settings.setPresentationReceiver(true);
t.add_cleanup(() => internals.settings.setPresentationReceiver(false));
const url = 'https://example.com/a.html';
const id = 'fakePresentationId';
mock.onSetReceiver = () => mock.onReceiverConnectionAvailable(url, id);
const list = await navigator.presentation.receiver.connectionList;
assert_equals(list.connections.length, 1);
assert_equals(list.connections[0].url, url);
assert_equals(list.connections[0].id, id);
}, "Test presentation.receiver.connectionList resolves with incoming connection.");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
promise_test(async _ => {
let controllerConnectionTerminated = false;
await waitForClick(button);
const connection =
await new PresentationRequest("https://example.com/").start();
connection.onterminate = () => {
assert_equals(connection.state, "terminated");
controllerConnectionTerminated = true;
};
// Open a receiver page and pass controller connection's
// controllerConnectionPtr and receiverConnectionRequest to it.
const w = window.open("resources/presentation-receiver-postmessage.html");
w.controllerConnectionPtr = mock.getControllerConnectionPtr();
w.receiverConnectionRequest = mock.getReceiverConnectionRequest();
return new Promise(resolve => {
window.addEventListener("message", e => {
if (e.data == "passed" || e.data == "failed") {
assert_equals("passed", e.data, "Receiver connection is terminated!");
assert_true(controllerConnectionTerminated);
resolve();
}
});
});
}, "receiver connection.terminate() should close receiver frame");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
promise_test(async _ => {
await waitForClick(button);
const request = new PresentationRequest('https://example.com');
const connection = await request.start();
assert_not_equals(connection, null);
const newConnection = await request.reconnect(connection.id);
assert_equals(connection, newConnection);
}, "Test that Presentation.reconnect() resolves with existing presentation connection.");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationErrorType} from '/gen/third_party/blink/public/mojom/presentation/presentation.mojom.m.js';
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
promise_test(async _ => {
mock.startPresentation = async urls => {
return {
presentationInfo: null,
error: {
errorType: PresentationErrorType.PREVIOUS_START_IN_PROGRESS,
message: 'Previous start in progress'
}
};
};
await waitForClick(button);
const request = new PresentationRequest("https://example.com");
return request.start().catch(e => assert_equals(e.name, 'OperationError'));
}, "Test that the PresentationRequest.start() rejects with OperationError if PresentationService reports PREVIOUS_START_IN_PROGRESS error");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button>click me</button>
<script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
async function testPresentationRequestStart(requestArgument, connectionUrl) {
await waitForClick(button);
const connection =
await new PresentationRequest(requestArgument).start();
assert_equals(connection.url, connectionUrl);
assert_equals(connection.state, 'connecting');
};
promise_test(async _ => {
const presentationUrl = "https://example.com/example.html";
await testPresentationRequestStart(presentationUrl, presentationUrl);
}, "Test that the PresentationRequest.start() with single URL resolves with correct PresentationConnection object.");
promise_test(async _ => {
const presentationUrls = ["https://example.com/example.html", "cast://google.com/app_id=deadbeef"];
await testPresentationRequestStart(presentationUrls, presentationUrls[0]);
}, "Test that the PresentationRequest.start() with multiple URLs resolves with correct PresentationConnection object.");
promise_test(async _ => {
const presentationUrl = "https://example.com/\ud801/example.html";
const connectionUrl = "https://example.com/" + encodeURIComponent('\ufffd') + "/example.html"
await testPresentationRequestStart(presentationUrl, connectionUrl);
}, "Test that the PresentationRequest.start() with single URL containing special symbol resolves with correct PresentationConnection object.");
</script>
</body>
</html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script>
<script src="resources/presentation-service-mock.js"></script>
<button>click me</button> <button>click me</button>
<script> <script type="module">
import {PresentationServiceMock, waitForClick} from './resources/presentation-service-mock.js';
const mock = new PresentationServiceMock();
const button = document.querySelector('button');
test(function() { test(function() {
assert_throws_js(TypeError, () => { assert_throws_js(TypeError, () => {
new PresentationConnectionAvailableEvent('connectionavailable') new PresentationConnectionAvailableEvent('connectionavailable');
}); });
assert_throws_js(TypeError, () => { assert_throws_js(TypeError, () => {
new PresentationConnectionAvailableEvent('connectionavailable', {}) new PresentationConnectionAvailableEvent('connectionavailable', {});
}); });
assert_throws_js(TypeError, () => { assert_throws_js(TypeError, () => {
new PresentationConnectionAvailableEvent('connectionavailable', { connection: null }) new PresentationConnectionAvailableEvent(
'connectionavailable', {connection: null});
}); });
}, "Test that the PresentationConnectionAvailableEvent ctor requires connection parameter.") }, "Test that the PresentationConnectionAvailableEvent ctor requires connection parameter.")
async_test(t => { promise_test(async _ => {
var button = document.querySelector('button'); await waitForClick(button);
// This is receiving the user gesture and runs the callback. const connection =
waitForClick(t.step_func(_ => { await new PresentationRequest('https://example.com').start();
new PresentationRequest('https://example.com').start().then( const e = new PresentationConnectionAvailableEvent(
t.step_func_done(result => { 'connectionavailable', {connection});
var e = new PresentationConnectionAvailableEvent( assert_not_equals(e, null);
'connectionavailable', { connection: result }); assert_equals(e.connection, connection);
assert_not_equals(e, null);
assert_equals(e.connection, result);
}));
}), button);
}, "Test that the PresentationConnectionAvailableEvent ctor can take a valid PresentationConnection.") }, "Test that the PresentationConnectionAvailableEvent ctor can take a valid PresentationConnection.")
</script> </script>
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
const httpsUrl = "https://example.com"; const httpsUrl = "https://example.com";
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
var presentationUrl = "https://example.com"; var presentationUrl = "https://example.com";
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
const httpsUrl = "https://example.com"; const httpsUrl = "https://example.com";
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script> import {PresentationServiceMock} from './presentation-service-mock.js';
<script src="presentation-service-mock.js"></script>
<script> const mock = new PresentationServiceMock();
// Parent window sets parameter for this page. // Parent window sets parameter for this page.
assert_not_equals(shouldCallClose, null); assert_not_equals(shouldCallClose, null);
...@@ -15,8 +15,8 @@ internals.settings.setPresentationReceiver(true); ...@@ -15,8 +15,8 @@ internals.settings.setPresentationReceiver(true);
const pageUrl = 'https://example.com/a.html'; const pageUrl = 'https://example.com/a.html';
const id = 'fakeSessionId'; const id = 'fakeSessionId';
presentationServiceMock.onSetReceiver = () => { mock.onSetReceiver = () => {
presentationServiceMock.onReceiverConnectionAvailable( mock.onReceiverConnectionAvailable(
pageUrl, id, controllerConnectionPtr, receiverConnectionRequest); pageUrl, id, controllerConnectionPtr, receiverConnectionRequest);
}; };
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script src="../../resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script type="module">
<script src="file:///gen/third_party/blink/public/mojom/presentation/presentation.mojom.js"></script> import {PresentationServiceMock} from './presentation-service-mock.js';
<script src="presentation-service-mock.js"></script>
<script> const mock = new PresentationServiceMock();
// Parent window sets parameter for this page. // Parent window sets parameter for this page.
assert_not_equals(controllerConnectionPtr, null); assert_not_equals(controllerConnectionPtr, null);
...@@ -18,8 +18,8 @@ var connection = null; ...@@ -18,8 +18,8 @@ var connection = null;
const pageUrl = 'https://example.com/a.html'; const pageUrl = 'https://example.com/a.html';
const id = 'fakeSessionId'; const id = 'fakeSessionId';
presentationServiceMock.onSetReceiver = () => { mock.onSetReceiver = () => {
presentationServiceMock.onReceiverConnectionAvailable( mock.onReceiverConnectionAvailable(
pageUrl, id, controllerConnectionPtr, receiverConnectionRequest); pageUrl, id, controllerConnectionPtr, receiverConnectionRequest);
}; };
......
...@@ -2,22 +2,19 @@ ...@@ -2,22 +2,19 @@
* Mock implementation of mojo PresentationService. * Mock implementation of mojo PresentationService.
*/ */
"use strict"; import {PresentationConnectionRemote, PresentationConnectionState, PresentationService, PresentationServiceReceiver} from '/gen/third_party/blink/public/mojom/presentation/presentation.mojom.m.js';
class MockPresentationConnection { export class PresentationServiceMock {
};
class PresentationServiceMock {
constructor() { constructor() {
this.pendingResponse_ = null; this.pendingResponse_ = null;
this.bindingSet_ = new mojo.BindingSet(blink.mojom.PresentationService); this.serviceReceiver_ = new PresentationServiceReceiver(this);
this.controllerConnectionPtr_ = null; this.controllerConnectionPtr_ = null;
this.receiverConnectionRequest_ = null; this.receiverConnectionRequest_ = null;
this.interceptor_ = this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.PresentationService.name); new MojoInterfaceInterceptor(PresentationService.$interfaceName);
this.interceptor_.oninterfacerequest = this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle); e => this.serviceReceiver_.$.bindHandle(e.handle);
this.interceptor_.start(); this.interceptor_.start();
this.controller_ = null; this.controller_ = null;
...@@ -28,7 +25,7 @@ class PresentationServiceMock { ...@@ -28,7 +25,7 @@ class PresentationServiceMock {
} }
reset() { reset() {
this.bindingSet_.closeAllBindings(); this.serviceReceiver_.closeBindings();
this.interceptor_.stop(); this.interceptor_.stop();
} }
...@@ -47,59 +44,65 @@ class PresentationServiceMock { ...@@ -47,59 +44,65 @@ class PresentationServiceMock {
this.onSetReceiver(); this.onSetReceiver();
} }
async startPresentation(urls) { setDefaultPresentationUrls(urls) {}
const controller_ptr = new blink.mojom.PresentationConnectionPtr();
const receiver_ptr = new blink.mojom.PresentationConnectionPtr(); listenForScreenAvailability(url) {}
stopListeningForScreenAvailability(url) {}
startPresentation(urls) {
const controller_ptr = new PresentationConnectionRemote();
const receiver_ptr = new PresentationConnectionRemote();
this.controllerConnectionPtr_ = controller_ptr; this.controllerConnectionPtr_ = controller_ptr;
this.receiverConnectionRequest_ = mojo.makeRequest(receiver_ptr); this.receiverConnectionRequest_ =
receiver_ptr.$.bindNewPipeAndPassReceiver();
return { return {
result: { result: {
presentationInfo: {url: urls[0], id: 'fakePresentationId'}, presentationInfo: {url: urls[0], id: 'fakePresentationId'},
connectionRemote: receiver_ptr, connectionRemote: receiver_ptr,
connectionReceiver: mojo.makeRequest(controller_ptr), connectionReceiver: controller_ptr.$.bindNewPipeAndPassReceiver(),
}, },
error: null, error: null,
}; };
} }
async reconnectPresentation(urls) { reconnectPresentation(urls) {
const controller_ptr = new blink.mojom.PresentationConnectionPtr(); const controller_ptr = new PresentationConnectionRemote();
const receiver_ptr = new blink.mojom.PresentationConnectionPtr(); const receiver_ptr = new PresentationConnectionRemote();
this.controllerConnectionPtr_ = controller_ptr; this.controllerConnectionPtr_ = controller_ptr;
this.receiverConnectionRequest_ = mojo.makeRequest(receiver_ptr); this.receiverConnectionRequest_ =
receiver_ptr.$.bindNewPipeAndPassReceiver();
return { return {
result: { result: {
presentationInfo: {url: urls[0], id: 'fakePresentationId'}, presentationInfo: {url: urls[0], id: 'fakePresentationId'},
connectionRemote: receiver_ptr, connectionRemote: receiver_ptr,
connectionReceiver: mojo.makeRequest(controller_ptr), connectionReceiver: controller_ptr.$.bindNewPipeAndPassReceiver(),
}, },
error: null, error: null,
}; };
} }
closeConnection(url, id) {}
terminate(presentationUrl, presentationId) { terminate(presentationUrl, presentationId) {
this.controller_.onConnectionStateChanged( this.controller_.onConnectionStateChanged(
{ url: presentationUrl, id: presentationId }, { url: presentationUrl, id: presentationId },
blink.mojom.PresentationConnectionState.TERMINATED); PresentationConnectionState.TERMINATED);
} }
onReceiverConnectionAvailable( onReceiverConnectionAvailable(
strUrl, id, opt_controllerConnectionPtr, opt_receiverConnectionRequest) { strUrl, id, opt_controllerConnectionPtr, opt_receiverConnectionRequest) {
const mojoUrl = new url.mojom.Url(); const mojoUrl = {url: strUrl}
mojoUrl.url = strUrl;
var controllerConnectionPtr = opt_controllerConnectionPtr; var controllerConnectionPtr = opt_controllerConnectionPtr;
if (!controllerConnectionPtr) { if (!controllerConnectionPtr) {
controllerConnectionPtr = new blink.mojom.PresentationConnectionPtr(); controllerConnectionPtr = new PresentationConnectionRemote();
const connectionBinding = new mojo.Binding( controllerConnectionPtr.$.bindNewPipeAndPassReceiver();
blink.mojom.PresentationConnection,
new MockPresentationConnection(),
mojo.makeRequest(controllerConnectionPtr));
} }
var receiverConnectionRequest = opt_receiverConnectionRequest; var receiverConnectionRequest = opt_receiverConnectionRequest;
if (!receiverConnectionRequest) { if (!receiverConnectionRequest) {
receiverConnectionRequest = mojo.makeRequest( const remote = new PresentationConnectionRemote();
new blink.mojom.PresentationConnectionPtr()); receiverConnectionRequest = remote.$.bindNewPipeAndPassReceiver();
} }
console.log('onReceiverConnectionAvailable: ' + mojoUrl + ',' + id); console.log('onReceiverConnectionAvailable: ' + mojoUrl + ',' + id);
...@@ -118,19 +121,19 @@ class PresentationServiceMock { ...@@ -118,19 +121,19 @@ class PresentationServiceMock {
} }
} }
function waitForClick(callback, button) { export function waitForClick(button) {
button.addEventListener('click', callback, { once: true }); return new Promise(resolve => {
button.addEventListener('click', resolve, {once: true});
if (!('eventSender' in window)) if (!('eventSender' in window))
return; return;
const boundingRect = button.getBoundingClientRect(); const boundingRect = button.getBoundingClientRect();
const x = boundingRect.left + boundingRect.width / 2; const x = boundingRect.left + boundingRect.width / 2;
const y = boundingRect.top + boundingRect.height / 2; const y = boundingRect.top + boundingRect.height / 2;
eventSender.mouseMoveTo(x, y); eventSender.mouseMoveTo(x, y);
eventSender.mouseDown(); eventSender.mouseDown();
eventSender.mouseUp(); eventSender.mouseUp();
});
} }
let presentationServiceMock = new PresentationServiceMock();
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