Commit b109cb42 authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

Clipboard API Tests: Await set_permission to deflake tests.

await set_permission, which is an async function. Somehow, this was
missed in https://crrev.com/c/2065346 and https://crrev.com/c/2200278,
causing some of these tests to flake (1/10 times).

Bug: 1083268, 1082747
Change-Id: Iedf7e63a02d200c76df0aaa431980493c6a35e61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204838
Auto-Submit: Darwin Huang <huangdarwin@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769578}
parent 6d23f8b3
...@@ -16,8 +16,8 @@ async function loadBlob(fileName) { ...@@ -16,8 +16,8 @@ async function loadBlob(fileName) {
} }
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const blobText = new Blob(['test text'], {type: 'text/plain'}); const blobText = new Blob(['test text'], {type: 'text/plain'});
const blobImage = await loadBlob('resources/greenbox.png'); const blobImage = await loadBlob('resources/greenbox.png');
......
...@@ -40,8 +40,8 @@ async function loadBlob(fileName) { ...@@ -40,8 +40,8 @@ async function loadBlob(fileName) {
} }
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const blobInput = await loadBlob('resources/greenbox.png'); const blobInput = await loadBlob('resources/greenbox.png');
...@@ -67,8 +67,8 @@ promise_test(async t => { ...@@ -67,8 +67,8 @@ promise_test(async t => {
}, 'Verify write and read clipboard [image/png Blob]'); }, 'Verify write and read clipboard [image/png Blob]');
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const invalidPngBlob = new Blob(['this text is not a valid png image'], const invalidPngBlob = new Blob(['this text is not a valid png image'],
{type: 'image/png'}); {type: 'image/png'});
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
'use strict'; 'use strict';
promise_test(async t => { promise_test(async t => {
// Note: This tests proper behavior on a detaching iframe. text/plain is // This tests proper behavior on a detaching iframe. text/plain is chosen for
// chosen for simplicity, and the test should fail the same way no matter what // simplicity, and the test should fail the same way no matter what the input
// the input type is. // type is.
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const iframe = document.getElementById('iframe'); const iframe = document.getElementById('iframe');
const iframeClipboard = iframe.contentWindow.navigator.clipboard; const iframeClipboard = iframe.contentWindow.navigator.clipboard;
...@@ -26,8 +26,8 @@ promise_test(async t => { ...@@ -26,8 +26,8 @@ promise_test(async t => {
iframe.focus(); iframe.focus();
// An iframe detaching while writing to the clipboard should fail, but not // An iframe detaching while writing to the clipboard should fail, but not
// crash. Note the lack of await here, meaning that the iframe will detach // crash. The lack of await here means that the iframe will detach while the
// while the read operation is running. // write operation is running.
iframeClipboard.read([clipboardItemInput]); iframeClipboard.read([clipboardItemInput]);
iframe.parentNode.removeChild(iframe); iframe.parentNode.removeChild(iframe);
}, 'Verify read fails on detaching iframe'); }, 'Verify read fails on detaching iframe');
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
'use strict'; 'use strict';
promise_test(async t => { promise_test(async t => {
// Note: This tests proper behavior on a detaching iframe. text/plain is // This tests proper behavior on a detaching iframe. text/plain is chosen for
// chosen for simplicity, and the test should fail the same way no matter what // simplicity, and the test should fail the same way no matter what the input
// the input type is. // type is.
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const iframe = document.getElementById('iframe'); const iframe = document.getElementById('iframe');
const iframeClipboard = iframe.contentWindow.navigator.clipboard; const iframeClipboard = iframe.contentWindow.navigator.clipboard;
...@@ -26,8 +26,8 @@ promise_test(async t => { ...@@ -26,8 +26,8 @@ promise_test(async t => {
iframe.focus(); iframe.focus();
// An iframe detaching while writing to the clipboard should fail, but not // An iframe detaching while writing to the clipboard should fail, but not
// crash. Note the lack of await here, meaning that the iframe will detach // crash. The lack of await here means that the iframe will detach while the
// while the write operation is running. // write operation is running.
iframeClipboard.write([clipboardItemInput]); iframeClipboard.write([clipboardItemInput]);
iframe.parentNode.removeChild(iframe); iframe.parentNode.removeChild(iframe);
}, 'Verify write fails on detaching iframe'); }, 'Verify write fails on detaching iframe');
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
'use strict'; 'use strict';
promise_test(async t => { promise_test(async t => {
// Note: This tests proper detached iframe behavior. text/plain is chosen for // This tests proper behavior on a detaching iframe. text/plain is chosen for
// simplicity, and the test should fail the same way no matter what the input // simplicity, and the test should fail the same way no matter what the input
// type is. // type is.
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const iframe = document.getElementById('iframe'); const iframe = document.getElementById('iframe');
const iframeClipboard = iframe.contentWindow.navigator.clipboard; const iframeClipboard = iframe.contentWindow.navigator.clipboard;
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
'use strict'; 'use strict';
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const iframe = document.getElementById('iframe'); const iframe = document.getElementById('iframe');
// Clipboard API must only be available in focused documents. // Clipboard API must only be available in focused documents.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
'use strict'; 'use strict';
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'denied'); await test_driver.set_permission({name: 'clipboard-read'}, 'denied');
await promise_rejects_dom(t, await promise_rejects_dom(t,
'NotAllowedError', navigator.clipboard.readText()); 'NotAllowedError', navigator.clipboard.readText());
}, 'navigator.clipboard.readText() fails when permission denied'); }, 'navigator.clipboard.readText() fails when permission denied');
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
'use strict'; 'use strict';
promise_test(async () => { promise_test(async () => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
await navigator.clipboard.readText(); await navigator.clipboard.readText();
}, 'navigator.clipboard.readText() succeeds when permission granted'); }, 'navigator.clipboard.readText() succeeds when permission granted');
</script> </script>
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
'use strict'; 'use strict';
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-write'}, 'denied'); await test_driver.set_permission({name: 'clipboard-write'}, 'denied');
await promise_rejects_dom(t, 'NotAllowedError', await promise_rejects_dom(t, 'NotAllowedError',
navigator.clipboard.writeText('xyz')); navigator.clipboard.writeText('xyz'));
}, 'navigator.clipboard.writeText() fails when permission denied'); }, 'navigator.clipboard.writeText() fails when permission denied');
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
'use strict'; 'use strict';
promise_test(async () => { promise_test(async () => {
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
await navigator.clipboard.writeText('xyz'); await navigator.clipboard.writeText('xyz');
}, 'navigator.clipboard.writeText() succeeds when permission granted'); }, 'navigator.clipboard.writeText() succeeds when permission granted');
</script> </script>
\ No newline at end of file
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
<script> <script>
async function readWriteTest(textInput) { async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const blobInput = new Blob([textInput], {type: 'text/plain'}); const blobInput = new Blob([textInput], {type: 'text/plain'});
const clipboardItemInput = new ClipboardItem({'text/plain': blobInput}); const clipboardItemInput = new ClipboardItem({'text/plain': blobInput});
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
<script> <script>
async function readWriteTest(textInput) { async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
const blobInput = new Blob([textInput], {type: 'text/plain'}); const blobInput = new Blob([textInput], {type: 'text/plain'});
const clipboardItem = new ClipboardItem({'text/plain': blobInput}); const clipboardItem = new ClipboardItem({'text/plain': blobInput});
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
<script> <script>
async function readWriteTest(textInput) { async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
await navigator.clipboard.writeText(textInput); await navigator.clipboard.writeText(textInput);
const clipboardItems = await navigator.clipboard.read(); const clipboardItems = await navigator.clipboard.read();
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<script> <script>
async function readWriteTest(textInput) { async function readWriteTest(textInput) {
promise_test(async t => { promise_test(async t => {
test_driver.set_permission({name: 'clipboard-read'}, 'granted'); await test_driver.set_permission({name: 'clipboard-read'}, 'granted');
test_driver.set_permission({name: 'clipboard-write'}, 'granted'); await test_driver.set_permission({name: 'clipboard-write'}, 'granted');
await navigator.clipboard.writeText(textInput); await navigator.clipboard.writeText(textInput);
const textOutput = await navigator.clipboard.readText(); const textOutput = await navigator.clipboard.readText();
......
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