Commit 85106229 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebShare: Test that large file share attempts fail

When we have more than 10 files, or more than
50 megabytes in total file size, the share request in rejected.

BUG=903010

Change-Id: Ib7a50e7fbfdd00fecb4eaa6a73f0dec00f6ea8e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626913
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662814}
parent fa790f69
...@@ -883,6 +883,8 @@ android_library("chrome_test_java") { ...@@ -883,6 +883,8 @@ android_library("chrome_test_java") {
"//content/test/data/android/webshare-csv.html", "//content/test/data/android/webshare-csv.html",
"//content/test/data/android/webshare-dex.html", "//content/test/data/android/webshare-dex.html",
"//content/test/data/android/webshare-ogg.html", "//content/test/data/android/webshare-ogg.html",
"//content/test/data/android/webshare-many.html",
"//content/test/data/android/webshare-large.html",
"//content/test/data/media/bear.webm", "//content/test/data/media/bear.webm",
"//content/test/data/media/getusermedia.html", "//content/test/data/media/getusermedia.html",
"//content/test/data/media/session/", "//content/test/data/media/session/",
......
...@@ -52,6 +52,8 @@ public class WebShareTest { ...@@ -52,6 +52,8 @@ public class WebShareTest {
private static final String TEST_FILE_CSV = "/content/test/data/android/webshare-csv.html"; private static final String TEST_FILE_CSV = "/content/test/data/android/webshare-csv.html";
private static final String TEST_FILE_DEX = "/content/test/data/android/webshare-dex.html"; private static final String TEST_FILE_DEX = "/content/test/data/android/webshare-dex.html";
private static final String TEST_FILE_OGG = "/content/test/data/android/webshare-ogg.html"; private static final String TEST_FILE_OGG = "/content/test/data/android/webshare-ogg.html";
private static final String TEST_FILE_MANY = "/content/test/data/android/webshare-many.html";
private static final String TEST_FILE_LARGE = "/content/test/data/android/webshare-large.html";
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
...@@ -249,6 +251,36 @@ public class WebShareTest { ...@@ -249,6 +251,36 @@ public class WebShareTest {
"Fail: NotAllowedError: Permission denied", mUpdateWaiter.waitForUpdate()); "Fail: NotAllowedError: Permission denied", mUpdateWaiter.waitForUpdate());
} }
/**
* Verify WebShare fails if share of many files is called from a user gesture.
* @throws Exception
*/
@Test
@MediumTest
@Feature({"WebShare"})
public void testWebShareMany() throws Exception {
mActivityTestRule.loadUrl(mTestServer.getURL(TEST_FILE_MANY));
// Click (instead of directly calling the JavaScript function) to simulate a user gesture.
TouchCommon.singleClickView(mTab.getView());
Assert.assertEquals(
"Fail: NotAllowedError: Permission denied", mUpdateWaiter.waitForUpdate());
}
/**
* Verify WebShare fails if share of large files is called from a user gesture.
* @throws Exception
*/
@Test
@MediumTest
@Feature({"WebShare"})
public void testWebShareLarge() throws Exception {
mActivityTestRule.loadUrl(mTestServer.getURL(TEST_FILE_LARGE));
// Click (instead of directly calling the JavaScript function) to simulate a user gesture.
TouchCommon.singleClickView(mTab.getView());
Assert.assertEquals(
"Fail: NotAllowedError: Permission denied", mUpdateWaiter.waitForUpdate());
}
/** /**
* Verify WebShare fails if share is called from a user gesture, and canceled. * Verify WebShare fails if share is called from a user gesture, and canceled.
* *
......
<!DOCTYPE html>
<html>
<head>
<title>Web Share</title>
<script>
function initiate_share() {
if (navigator.share === undefined) {
window.document.title = 'Fail: navigator.share === undefined';
return;
}
let data = {files: []};
const fileBits = ['*'.repeat(26 * 1024 * 1024)];
const options = {type: 'text/plain'};
for (let index = 0; index < 2; ++index) {
let fileName = 'sample' + index + '.txt';
data.files.push(new File(fileBits, fileName, options));
}
navigator.share(data).then(() => {
window.document.title = 'Success';
}).catch(e => {
window.document.title = 'Fail: ' + e;
});
}
window.addEventListener('load', () => {
window.addEventListener('click', initiate_share);
});
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Web Share</title>
<script>
function initiate_share() {
if (navigator.share === undefined) {
window.document.title = 'Fail: navigator.share === undefined';
return;
}
let data = {files: []};
const fileBits = ['*'];
const options = {type: 'text/plain'};
for (let index = 0; index < 11; ++index) {
let fileName = 'sample' + index + '.txt';
data.files.push(new File(fileBits, fileName, options));
}
navigator.share(data).then(() => {
window.document.title = 'Success';
}).catch(e => {
window.document.title = 'Fail: ' + e;
});
}
window.addEventListener('load', () => {
window.addEventListener('click', initiate_share);
});
</script>
</head>
<body>
</body>
</html>
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