Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<title>Sub Apps: Error cases for remove()</title>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/subapps-helpers.js"></script>
<body></body>
<script>
promise_test(async t => {
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
const iframeDOMException = iframe.contentWindow.DOMException;
const subApps = iframe.contentWindow.subApps;
iframe.remove();
// At this point the iframe is detached and unloaded, and its execution
// context is gone.
await promise_rejects_dom(t, 'OperationError', iframeDOMException, subApps.remove(['/sub-app-id']));
}, "The object is no longer associated to a document.");
promise_test(async t => {
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
const iframeDOMException = iframe.contentWindow.DOMException;
t.add_cleanup(() => iframe.remove());
await promise_rejects_dom(t, 'NotSupportedError', iframeDOMException, iframe.contentWindow.subApps.remove(['/sub-app-id']));
}, "API is only supported in top-level browsing contexts.");
promise_test(async t => {
t.add_cleanup(async () => {
await mockSubAppsService.reset();
mockSubAppsService = null;
});
const cross_origin_url = 'https://example.com/sub-app-id';
await createMockSubAppsService(Status.SUCCESS, [], [], []);
await promise_rejects_js(t, TypeError, window.subApps.remove([cross_origin_url]));
}, 'API supports only same-origin URLs.');
promise_test(async t => {
const url_1 = '/sub-app-1';
const url_2 = '/sub-app-2';
const url_3 = '/sub-app-3';
let remove_call_params = [url_1, url_2, url_3];
let mocked_response = () => [
{ "manifestId": url_1, "resultType": SubAppsServiceRemoveResultType.kGenericError },
{ "manifestId": url_2, "resultType": SubAppsServiceRemoveResultType.kGenericError },
{ "manifestId": url_3, "resultType": SubAppsServiceRemoveResultType.kGenericError }
];
let expected_results = () => ({
failedApps: {
[url_1]: "OperationError",
[url_2]: "OperationError",
[url_3]: "OperationError"
}
});
await test_driver.bless("removing subapps", async function () {
await subapps_remove_expect_success_with_result(t, remove_call_params, mocked_response, expected_results);
});
}, 'Remove call fails.');
promise_test(async t => {
const url_1 = '/sub-app-1';
const url_2 = '/sub-app-2';
const url_3 = '/sub-app-3';
let remove_call_params = [url_1, url_2, url_3];
let mocked_response = () => [
{ "manifestId": url_1, "resultType": SubAppsServiceRemoveResultType.kSuccess },
{ "manifestId": url_2, "resultType": SubAppsServiceRemoveResultType.kSuccess },
{ "manifestId": url_3, "resultType": SubAppsServiceRemoveResultType.kGenericError }
];
let expected_results = () => ({
removedApps: [url_1, url_2],
failedApps: {
[url_3]: "OperationError"
}
});
await test_driver.bless("removing subapps", async function () {
await subapps_remove_expect_success_with_result(t, remove_call_params, mocked_response, expected_results);
});
}, 'Remove call fails with mixed results.');
</script>