Commit e65fb36c authored by lfg's avatar lfg Committed by Commit bot

Adding webview tests to app_shell_browsertests.

Tests added in this CL:
TestLoadAbortChromeExtensionURLWrongPartition
TestLoadAbortIllegalChromeURL
TestLoadAbortIllegalFileURL
TestLoadAbortIllegalJavaScriptURL
TestLoadAbortInvalidNavigation
TestLoadAbortNonWebSafeScheme
TestLoadProgressEvent

BUG=352293

Review URL: https://codereview.chromium.org/601553005

Cr-Commit-Position: refs/heads/master@{#297298}
parent 16e2f280
......@@ -120,4 +120,34 @@ IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestExecuteScript) {
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestExecuteScriptFail) {
RunTest("testExecuteScriptFail", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest,
TestLoadAbortChromeExtensionURLWrongPartition) {
RunTest("testLoadAbortChromeExtensionURLWrongPartition", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortIllegalChromeURL) {
RunTest("testLoadAbortIllegalChromeURL", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortIllegalFileURL) {
RunTest("testLoadAbortIllegalFileURL", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortIllegalJavaScriptURL) {
RunTest("testLoadAbortIllegalJavaScriptURL", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortInvalidNavigation) {
RunTest("testLoadAbortInvalidNavigation", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadAbortNonWebSafeScheme) {
RunTest("testLoadAbortNonWebSafeScheme", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestLoadProgressEvent) {
RunTest("testLoadProgressEvent", "web_view/apitest");
}
} // namespace extensions
<!doctype html>
<!--
* Copyright (c) 2013 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<head>
<title>A guest that opens a new window.</title>
<script type="text/javascript">
window.onload = function() {
window.open(
'data:text/html,<html><body>Initial dummy guest</body></html>');
};
</script>
</head>
<body style="padding: 0; margin: 0;">
</body>
</html>
......@@ -537,6 +537,111 @@ function testExecuteScriptFail() {
}
}
// This test verifies that the loadabort event fires when loading a webview
// accessible resource from a partition that is not privileged.
function testLoadAbortChromeExtensionURLWrongPartition() {
var localResource = chrome.runtime.getURL('guest.html');
var webview = document.createElement('webview');
webview.addEventListener('loadabort', function(e) {
embedder.test.assertEq('ERR_ADDRESS_UNREACHABLE', e.reason);
embedder.test.succeed();
});
webview.addEventListener('loadstop', function(e) {
embedder.test.fail();
});
webview.setAttribute('src', localResource);
document.body.appendChild(webview);
}
// This test verifies that the loadabort event fires as expected when an illegal
// chrome URL is provided.
function testLoadAbortIllegalChromeURL() {
var webview = document.createElement('webview');
var onFirstLoadStop = function(e) {
webview.removeEventListener('loadstop', onFirstLoadStop);
webview.setAttribute('src', 'chrome://newtab');
};
webview.addEventListener('loadstop', onFirstLoadStop);
webview.addEventListener('loadabort', function(e) {
embedder.test.assertEq('ERR_ABORTED', e.reason);
embedder.test.succeed();
});
webview.setAttribute('src', 'about:blank');
document.body.appendChild(webview);
}
function testLoadAbortIllegalFileURL() {
var webview = document.createElement('webview');
webview.addEventListener('loadabort', function(e) {
embedder.test.assertEq('ERR_ABORTED', e.reason);
embedder.test.succeed();
});
webview.setAttribute('src', 'file://foo');
document.body.appendChild(webview);
}
function testLoadAbortIllegalJavaScriptURL() {
var webview = document.createElement('webview');
webview.addEventListener('loadabort', function(e) {
embedder.test.assertEq('ERR_ABORTED', e.reason);
embedder.test.succeed();
});
webview.setAttribute('src', 'javascript:void(document.bgColor="#0000FF")');
document.body.appendChild(webview);
}
// Verifies that navigating to invalid URL (e.g. 'http:') doesn't cause a crash.
function testLoadAbortInvalidNavigation() {
var webview = document.createElement('webview');
var validSchemeWithEmptyURL = 'http:';
webview.addEventListener('loadabort', function(e) {
embedder.test.assertEq('ERR_ABORTED', e.reason);
embedder.test.assertEq('', e.url);
embedder.test.succeed();
});
webview.addEventListener('exit', function(e) {
// We should not crash.
embedder.test.fail();
});
webview.setAttribute('src', validSchemeWithEmptyURL);
document.body.appendChild(webview);
}
// Verifies that navigation to a URL that is valid but not web-safe or
// pseudo-scheme fires loadabort and doesn't cause a crash.
function testLoadAbortNonWebSafeScheme() {
var webview = document.createElement('webview');
var chromeGuestURL = 'chrome-guest://abc123';
webview.addEventListener('loadabort', function(e) {
embedder.test.assertEq('ERR_ABORTED', e.reason);
embedder.test.assertEq('chrome-guest://abc123/', e.url);
embedder.test.succeed();
});
webview.addEventListener('exit', function(e) {
// We should not crash.
embedder.test.fail();
});
webview.setAttribute('src', chromeGuestURL);
document.body.appendChild(webview);
};
// Tests that the 'loadprogress' event is triggered correctly.
function testLoadProgressEvent() {
var webview = document.createElement('webview');
var progress = 0;
webview.addEventListener('loadstop', function(evt) {
embedder.test.assertEq(1, progress);
embedder.test.succeed();
});
webview.addEventListener('loadprogress', function(evt) {
progress = evt.progress;
});
webview.setAttribute('src', 'data:text/html,trigger navigation');
document.body.appendChild(webview);
}
// Tests end.
......@@ -556,7 +661,15 @@ embedder.test.testList = {
'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad,
'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild,
'testExecuteScript': testExecuteScript,
'testExecuteScriptFail': testExecuteScriptFail
'testExecuteScriptFail': testExecuteScriptFail,
'testLoadAbortChromeExtensionURLWrongPartition':
testLoadAbortChromeExtensionURLWrongPartition,
'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL,
'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL,
'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL,
'testLoadAbortInvalidNavigation': testLoadAbortInvalidNavigation,
'testLoadAbortNonWebSafeScheme': testLoadAbortNonWebSafeScheme,
'testLoadProgressEvent': testLoadProgressEvent
};
onload = function() {
......
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