Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for remote playback API #35827

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 56 additions & 37 deletions remote-playback/cancel-watch-availability.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
<!DOCTYPE html>
<html>
<title>Tests various ways to call cancelWatchAvailability()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
async_test(t => {
var v = document.createElement('video');
v.src = getVideoURI('/media/movie_5');
<title>Tests various ways to call cancelWatchAvailability()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
async_test((t) => {
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");

v.remote.watchAvailability(function() {})
.then(t.step_func(id => {
v.remote.cancelWatchAvailability(id).then(t.step_func(function() {
v.remote.cancelWatchAvailability(id).then(
t.unreached_func(), t.step_func_done(e => {
assert_equals(e.name, 'NotFoundError');
})
v.remote
.watchAvailability(() => {})
.then(
t.step_func((id) => {
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
v.remote.cancelWatchAvailability(id).then(
t.step_func(() => {
v.remote.cancelWatchAvailability(id).then(
t.unreached_func(),
t.step_func_done((e) => {
assert_equals(e.name, "NotFoundError");
})
);
}),
t.unreached_func()
);
}),
t.unreached_func()
);
}), t.unreached_func());
}), t.unreached_func());
}, 'Test that calling cancelWatchAvailability() with an id does remove the callback.');
}, "Test that calling cancelWatchAvailability() with an id does remove the callback.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved

async_test(t => {
var v = document.createElement('video');
v.src = getVideoURI('/media/movie_5');
async_test((t) => {
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");

Promise.all([
v.remote.watchAvailability(function() {}),
v.remote.watchAvailability(function() {})
]).then(t.step_func(ids => {
v.remote.cancelWatchAvailability().then(t.step_func(function() {
v.remote.cancelWatchAvailability(ids[0]).then(t.unreached_func(), t.step_func(function(e) {
assert_equals(e.name, 'NotFoundError');
v.remote.cancelWatchAvailability(ids[1])
.then(t.unreached_func(), t.step_func_done(function(e) {
assert_equals(e.name, 'NotFoundError');
}));
}));
}), t.unreached_func());
}), t.unreached_func());
}, 'Test that calling cancelWatchAvailability() without an id removes all the callbacks.');
</script>
Promise.all([
v.remote.watchAvailability(() => {}),
v.remote.watchAvailability(() => {}),
]).then(
t.step_func((ids) =>
v.remote.cancelWatchAvailability().then(
t.step_func(() =>
v.remote.cancelWatchAvailability(ids[0]).then(
t.unreached_func(),
t.step_func((e) => {
assert_equals(e.name, "NotFoundError");
v.remote.cancelWatchAvailability(ids[1]).then(
t.unreached_func(),
t.step_func_done((e) =>
assert_equals(e.name, "NotFoundError")
)
);
})
)
),
t.unreached_func()
)
),
t.unreached_func()
);
}, "Test that calling cancelWatchAvailability() without an id removes all the callbacks.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
<!DOCTYPE html>
<html>
<title>Test that calling cancelWatchAvailability() when disableRemotePlayback attribute is set throws an exception</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
async_test(t => {
var v = document.createElement('video');
v.src = getVideoURI('/media/movie_5');
<title>
Test that calling cancelWatchAvailability() when disableRemotePlayback
attribute is set throws an exception
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
async_test((t) => {
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");

v.remote.watchAvailability(function() {})
.then(id => {
v.disableRemotePlayback = true;
v.remote.cancelWatchAvailability(id).then(
t.unreached_func(),
t.step_func(e => {
assert_equals(e.name, 'InvalidStateError');
v.remote.cancelWatchAvailability().then(
v.remote
.watchAvailability(() => {})
.then((id) => {
v.disableRemotePlayback = true;
v.remote.cancelWatchAvailability(id).then(
t.unreached_func(),
t.step_func_done(e => {
assert_equals(e.name, 'InvalidStateError');
t.step_func((e) => {
assert_equals(e.name, "InvalidStateError");
v.remote.cancelWatchAvailability().then(
t.unreached_func(),
t.step_func_done((e) => {
assert_equals(e.name, "InvalidStateError");
})
);
})
);
}));
}, t.unreached_func());
}, 'Test that calling cancelWatchAvailability() when disableRemotePlayback attribute is set throws an exception.');
</script>
}, t.unreached_func());
}, "Test that calling cancelWatchAvailability() when disableRemotePlayback attribute is set throws an exception.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
27 changes: 15 additions & 12 deletions remote-playback/disable-remote-playback-prompt-throws.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<!DOCTYPE html>
<html>
<title>Test that calling prompt() when disableRemotePlayback attribute is set throws an exception</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
promise_test(t => {
var v = document.createElement('video');
v.src = getVideoURI('/media/movie_5');
v.disableRemotePlayback = true;
<title>
Test that calling prompt() when disableRemotePlayback attribute is set
throws an exception
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
promise_test((t) => {
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");
v.disableRemotePlayback = true;

return promise_rejects_dom(t, 'InvalidStateError', v.remote.prompt());
}, 'Test that calling prompt() when disableRemotePlayback attribute is set throws an exception.');
</script>
return promise_rejects_dom(t, "InvalidStateError", v.remote.prompt());
}, "Test that calling prompt() when disableRemotePlayback attribute is set throws an exception.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<!DOCTYPE html>
<html>
<title>Test that calling watchAvailability() when disableRemotePlayback attribute is set throws an exception</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
promise_test(t => {
var v = document.createElement('video');
v.src = getVideoURI('/media/movie_5');
v.disableRemotePlayback = true;
<title>
Test that calling watchAvailability() when disableRemotePlayback attribute
is set throws an exception
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
promise_test((t) => {
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");
v.disableRemotePlayback = true;

return promise_rejects_dom(t, 'InvalidStateError',
v.remote.watchAvailability(function() {}));
}, 'Test that calling watchAvailability() when disableRemotePlayback attribute is set throws an exception.');
</script>
return promise_rejects_dom(
t,
"InvalidStateError",
v.remote.watchAvailability(() => {})
);
}, "Test that calling watchAvailability() when disableRemotePlayback attribute is set throws an exception.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
60 changes: 60 additions & 0 deletions remote-playback/event-handlers-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<title>Test that all event handlers are called.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
setup({ explicit_timeout: true });
</script>
<body>
<div id="prep">
<p>Please make sure a device for remote playback is <b>available.</b></p>
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
<button id="prompt-button-prep">Show devices</button>
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
<button id="start-button">Start test</button>
</div>
<div id="pick-device" style="display: none">
<p>
Click the button below to prompt for a remote playback device and select
one! After connecting to the device, please click again and disconnect
from device.
</p>
<button id="prompt-button">Pick device</button>
<button id="disconnect-button" style="display: none">
Disconnect device
</button>
</div>
</body>
<script src="./prepare-device.js"></script>
<script>
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");

async_test((t) => {
let onConnectingCalled = false;
let onConnectCalled = false;
let onDisconnectCalled = false;
v.remote.onconnecting = () => (onConnectingCalled = true);
v.remote.onconnect = () => (onConnectCalled = true);
v.remote.ondisconnect = () => (onDisconnectCalled = true);
let button = document.getElementById("prompt-button");
let disconnectButton = document.getElementById("disconnect-button");
button.onclick = promise_test(
() =>
v.remote.prompt().then(() => {
button.style.display = "none";
disconnectButton.style.display = "inline";
}),
"Prompt to connect device"
);
disconnectButton.onclick = () =>
v.remote.prompt().then(
t.step_func_done(() => {
assert_true(onConnectingCalled, "onconnecting was called");
assert_true(onConnectCalled, "onconnect was called");
assert_true(onDisconnectCalled, "ondisconnect was called");
})
);
}, "Test that all event handlers are called.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
12 changes: 12 additions & 0 deletions remote-playback/prepare-device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var startButton = document.getElementById("start-button");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
startButton.onclick = function () {
document.getElementById("prep").style.display = "none";
document.getElementById("pick-device").style.display = "block";
};
var promptPrepButton = document.getElementById("prompt-button-prep");
promptPrepButton.onclick = function () {
v.remote
.prompt()
.then(() => {})
.catch(() => {});
};
37 changes: 37 additions & 0 deletions remote-playback/prompt-and-cancel-selection-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<title>
Test that promise is rejected when user cancels device selection.
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
<script>
setup({ explicit_timeout: true });
</script>
<body>
<p>
Click the button below to prompt for a remote playback device and
<b>cancel the selection</b> of a device!
</p>
<button id="prompt-button">Pick device</button>
</body>
<script>
async_test((t) => {
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");

let button = document.getElementById("prompt-button");
button.onclick = t.step_func(() =>
v.remote
.prompt()
.then(t.unreached_func())
.catch(
t.step_func_done((error) =>
assert_equals(error.name, "NotAllowedError")
)
)
);
}, "Test that promise is rejected when user cancels device selection.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
38 changes: 38 additions & 0 deletions remote-playback/prompt-and-select-device-manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<title>Test that promise is resolved when user selects a device.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
setup({ explicit_timeout: true });
</script>
<body>
<div id="prep">
<p>Please make sure a device for remote playback is <b>available.</b></p>
<button id="prompt-button-prep">Show devices</button>
<button id="start-button">Start test</button>
</div>
<div id="pick-device" style="display: none">
<p>
Click the button below to prompt for a remote playback device and select
one!
</p>
<button id="prompt-button">Pick device</button>
</div>
</body>
<script src="./prepare-device.js"></script>
<script>
let v = document.createElement("video");
v.src = getVideoURI("/media/movie_5");

async_test((t) => {
let button = document.getElementById("prompt-button");
button.onclick = t.step_func_done(() => {
promise_test(() => {
return v.remote.prompt();
}, "Prompt resolves");
});
}, "Test that promise is resolved when user selects a device.");
markafoltz marked this conversation as resolved.
Show resolved Hide resolved
</script>
</html>
Loading