Skip to content

Commit

Permalink
WebShare: Test that .apk and .dex are rejected
Browse files Browse the repository at this point in the history
Test that executable .apk and .dex files are rejected on Android.

BUG=903010

Change-Id: I5a000f5a129fad0d324aa8f830a173c09e798cde
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1588068
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#655431}
  • Loading branch information
ericwilligers authored and Commit Bot committed Apr 30, 2019
1 parent 69b258c commit 3a39216
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ android_library("chrome_test_java") {
"//content/test/data/android/permission_navigation.html",
"//content/test/data/android/quota_permissions.html",
"//content/test/data/android/webshare.html",
"//content/test/data/android/webshare-apk.html",
"//content/test/data/android/webshare-dex.html",
"//content/test/data/media/bear.webm",
"//content/test/data/media/getusermedia.html",
"//content/test/data/media/session/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class WebShareTest {
public final NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule();

private static final String TEST_FILE = "/content/test/data/android/webshare.html";
private static final String TEST_FILE_APK = "/content/test/data/android/webshare-apk.html";
private static final String TEST_FILE_DEX = "/content/test/data/android/webshare-dex.html";

private EmbeddedTestServer mTestServer;

Expand Down Expand Up @@ -153,6 +155,36 @@ public void fireIntent(Context context, Intent intent) {
Assert.assertEquals("Fail: AbortError: Share canceled", mUpdateWaiter.waitForUpdate());
}

/**
* Verify WebShare fails if share of .apk is called from a user gesture.
* @throws Exception
*/
@Test
@MediumTest
@Feature({"WebShare"})
public void testWebShareApk() throws Exception {
mActivityTestRule.loadUrl(mTestServer.getURL(TEST_FILE_APK));
// 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 .dex is called from a user gesture.
* @throws Exception
*/
@Test
@MediumTest
@Feature({"WebShare"})
public void testWebShareDex() throws Exception {
mActivityTestRule.loadUrl(mTestServer.getURL(TEST_FILE_DEX));
// 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 succeeds if share is called from a user gesture, and app chosen.
* @throws Exception
Expand Down
30 changes: 30 additions & 0 deletions content/test/data/android/webshare-apk.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Web Share</title>
<script>
function initiate_share() {
if (navigator.share === undefined) {
window.document.title = 'Fail: navigator.share === undefined';
return;
}

const fileBits = ['contents'];
const fileName = 'blocked.apk';
const options = {type: 'text/plain'};
const data = {files: [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>
30 changes: 30 additions & 0 deletions content/test/data/android/webshare-dex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Web Share</title>
<script>
function initiate_share() {
if (navigator.share === undefined) {
window.document.title = 'Fail: navigator.share === undefined';
return;
}

const fileBits = ['contents'];
const fileName = 'blocked.dex';
const options = {type: 'text/plain'};
const data = {files: [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>

0 comments on commit 3a39216

Please sign in to comment.