Commit 3ea93d51 authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Update and add tests for the <webview> public-facing API functions

We update the lists of webview API functions used in tests to match
WEB_VIEW_API_METHODS. Also, we introduce
testCustomElementCallbacksInaccessible to test that the custom elements
lifecycle callbacks cannot be called from user code.

Bug: None
Change-Id: If3d2e20fe7d2aa69455628a69d6d4fec30851be2
Reviewed-on: https://chromium-review.googlesource.com/1181508Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarEhsan Karamad <ekaramad@chromium.org>
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584823}
parent 48343af1
...@@ -1239,6 +1239,12 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) { ...@@ -1239,6 +1239,12 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) {
TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER); TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER);
} }
IN_PROC_BROWSER_TEST_F(WebViewTest,
Shim_TestCustomElementCallbacksInaccessible) {
TestHelper("testCustomElementCallbacksInaccessible", "web_view/shim",
NO_TEST_SERVER);
}
// Tests the existence of WebRequest API event objects on the request // Tests the existence of WebRequest API event objects on the request
// object, on the webview element, and hanging directly off webview. // object, on the webview element, and hanging directly off webview.
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) { IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) {
......
...@@ -5,21 +5,44 @@ ...@@ -5,21 +5,44 @@
// This test verifies that the <webview> API is undefined if the webview // This test verifies that the <webview> API is undefined if the webview
// permission is not specified in the manifest file. // permission is not specified in the manifest file.
function testAPIMethodExistence() { function testAPIMethodExistence() {
var apiMethodsToCheck = [ // See public-facing API functions in web_view_api_methods.js
var WEB_VIEW_API_METHODS = [
'addContentScripts',
'back', 'back',
'canGoBack', 'canGoBack',
'canGoForward', 'canGoForward',
'captureVisibleRegion',
'clearData',
'executeScript',
'find',
'forward', 'forward',
'getAudioState',
'getProcessId', 'getProcessId',
'getUserAgent',
'getZoom',
'getZoomMode',
'go', 'go',
'insertCSS',
'isAudioMuted',
'isUserAgentOverridden',
'loadDataWithBaseUrl',
'print',
'removeContentScripts',
'reload', 'reload',
'setAudioMuted',
'setUserAgentOverride',
'setZoom',
'setZoomMode',
'stop', 'stop',
'stopFinding',
'terminate' 'terminate'
]; ];
var webview = document.createElement('webview'); var webview = document.createElement('webview');
for (var i = 0; i < apiMethodsToCheck.length; ++i) { for (var methodName of WEB_VIEW_API_METHODS) {
chrome.test.assertEq('undefined', chrome.test.assertEq(
typeof webview[apiMethodsToCheck[i]]); 'undefined', typeof webview[methodName],
'Method should not be defined: ' + methodName);
} }
// Check contentWindow. // Check contentWindow.
......
...@@ -87,9 +87,11 @@ embedder.test.fail = function() { ...@@ -87,9 +87,11 @@ embedder.test.fail = function() {
chrome.test.sendMessage('TEST_FAILED'); chrome.test.sendMessage('TEST_FAILED');
}; };
embedder.test.assertEq = function(a, b) { embedder.test.assertEq = function(a, b, message) {
if (a != b) { if (a != b) {
console.log('assertion failed: ' + a + ' != ' + b); console.log(
'assertion failed: ' + a + ' != ' + b +
(message ? (': ' + message) : ''));
embedder.test.fail(); embedder.test.fail();
} }
}; };
...@@ -363,25 +365,49 @@ function testAutosizeRemoveAttributes() { ...@@ -363,25 +365,49 @@ function testAutosizeRemoveAttributes() {
} }
function testAPIMethodExistence() { function testAPIMethodExistence() {
var apiMethodsToCheck = [ // See public-facing API functions in web_view_api_methods.js
var WEB_VIEW_API_METHODS = [
'addContentScripts',
'back', 'back',
'canGoBack', 'canGoBack',
'canGoForward', 'canGoForward',
'captureVisibleRegion',
'clearData',
'executeScript',
'find',
'forward', 'forward',
'getAudioState',
'getProcessId', 'getProcessId',
'getUserAgent',
'getZoom',
'getZoomMode',
'go', 'go',
'insertCSS',
'isAudioMuted',
'isUserAgentOverridden',
'loadDataWithBaseUrl',
'print',
'removeContentScripts',
'reload', 'reload',
'setAudioMuted',
'setUserAgentOverride',
'setZoom',
'setZoomMode',
'stop', 'stop',
'stopFinding',
'terminate' 'terminate'
]; ];
var webview = document.createElement('webview'); var webview = document.createElement('webview');
for (var methodName of WEB_VIEW_API_METHODS) {
embedder.test.assertEq(
'function', typeof webview[methodName],
methodName + ' should be defined');
}
webview.setAttribute('partition', arguments.callee.name); webview.setAttribute('partition', arguments.callee.name);
webview.addEventListener('loadstop', function(e) { webview.addEventListener('loadstop', function(e) {
for (var i = 0; i < apiMethodsToCheck.length; ++i) {
embedder.test.assertEq('function',
typeof webview[apiMethodsToCheck[i]]);
}
// Check contentWindow. // Check contentWindow.
embedder.test.assertEq('object', typeof webview.contentWindow); embedder.test.assertEq('object', typeof webview.contentWindow);
embedder.test.assertEq('function', embedder.test.assertEq('function',
...@@ -392,6 +418,32 @@ function testAPIMethodExistence() { ...@@ -392,6 +418,32 @@ function testAPIMethodExistence() {
document.body.appendChild(webview); document.body.appendChild(webview);
} }
function testCustomElementCallbacksInaccessible() {
var CUSTOM_ELEMENT_CALLBACKS = [
// Custom Elements V0
// TODO(867831): Once we migrate to V1, we'll no longer need to check
// the V0 callbacks.
'createdCallback',
'attachedCallback',
'detachedCallback',
'attributeChangedCallback',
// Custom Elements V1
'connectedCallback',
'disconnectedCallback',
'attributeChangedCallback',
'adoptedCallback'
];
var webview = document.createElement('webview');
for (var callbackName of CUSTOM_ELEMENT_CALLBACKS) {
embedder.test.assertEq(
'undefined', typeof webview[callbackName],
callbackName + ' should not be accessible');
}
embedder.test.succeed();
}
// This test verifies that the loadstop event fires when loading a webview // This test verifies that the loadstop event fires when loading a webview
// accessible resource from a partition that is privileged. // accessible resource from a partition that is privileged.
function testChromeExtensionURL() { function testChromeExtensionURL() {
...@@ -3209,6 +3261,8 @@ embedder.test.testList = { ...@@ -3209,6 +3261,8 @@ embedder.test.testList = {
'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes,
'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes,
'testAPIMethodExistence': testAPIMethodExistence, 'testAPIMethodExistence': testAPIMethodExistence,
'testCustomElementCallbacksInaccessible':
testCustomElementCallbacksInaccessible,
'testChromeExtensionURL': testChromeExtensionURL, 'testChromeExtensionURL': testChromeExtensionURL,
'testChromeExtensionRelativePath': testChromeExtensionRelativePath, 'testChromeExtensionRelativePath': testChromeExtensionRelativePath,
'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad,
......
...@@ -381,6 +381,10 @@ IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAPIMethodExistence) { ...@@ -381,6 +381,10 @@ IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAPIMethodExistence) {
RunTest("testAPIMethodExistence", "web_view/apitest"); RunTest("testAPIMethodExistence", "web_view/apitest");
} }
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestCustomElementCallbacksInaccessible) {
RunTest("testCustomElementCallbacksInaccessible", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAssignSrcAfterCrash) { IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAssignSrcAfterCrash) {
RunTest("testAssignSrcAfterCrash", "web_view/apitest"); RunTest("testAssignSrcAfterCrash", "web_view/apitest");
} }
......
...@@ -36,9 +36,11 @@ window.runTest = function(testName) { ...@@ -36,9 +36,11 @@ window.runTest = function(testName) {
embedder.test = {}; embedder.test = {};
embedder.test.assertEq = function(a, b) { embedder.test.assertEq = function(a, b, message) {
if (a != b) { if (a != b) {
window.console.warn('assertion failed: ' + a + ' != ' + b); window.console.warn(
'assertion failed: ' + a + ' != ' + b +
(message ? (': ' + message) : ''));
embedder.test.fail(); embedder.test.fail();
} }
}; };
...@@ -96,36 +98,49 @@ function testAllowTransparencyAttribute() { ...@@ -96,36 +98,49 @@ function testAllowTransparencyAttribute() {
} }
function testAPIMethodExistence() { function testAPIMethodExistence() {
var apiMethodsToCheck = [ // See public-facing API functions in web_view_api_methods.js
var WEB_VIEW_API_METHODS = [
'addContentScripts',
'back', 'back',
'find',
'forward',
'canGoBack', 'canGoBack',
'canGoForward', 'canGoForward',
'captureVisibleRegion',
'clearData', 'clearData',
'executeScript',
'find',
'forward',
'getAudioState',
'getProcessId', 'getProcessId',
'getUserAgent',
'getZoom', 'getZoom',
'getZoomMode',
'go', 'go',
'insertCSS',
'isAudioMuted',
'isUserAgentOverridden',
'loadDataWithBaseUrl',
'print', 'print',
'removeContentScripts',
'reload', 'reload',
'setAudioMuted',
'setUserAgentOverride',
'setZoom', 'setZoom',
'setZoomMode',
'stop', 'stop',
'stopFinding', 'stopFinding',
'terminate', 'terminate'
'executeScript',
'insertCSS',
'getUserAgent',
'isUserAgentOverridden',
'setUserAgentOverride'
]; ];
var webview = document.createElement('webview'); var webview = document.createElement('webview');
for (var methodName of WEB_VIEW_API_METHODS) {
embedder.test.assertEq(
'function', typeof webview[methodName],
methodName + ' should be defined');
}
webview.setAttribute('partition', arguments.callee.name); webview.setAttribute('partition', arguments.callee.name);
webview.addEventListener('loadstop', function(e) { webview.addEventListener('loadstop', function(e) {
for (var i = 0; i < apiMethodsToCheck.length; ++i) {
embedder.test.assertEq('function',
typeof webview[apiMethodsToCheck[i]]);
}
// Check contentWindow. // Check contentWindow.
embedder.test.assertEq('object', typeof webview.contentWindow); embedder.test.assertEq('object', typeof webview.contentWindow);
embedder.test.assertEq('function', embedder.test.assertEq('function',
...@@ -136,6 +151,32 @@ function testAPIMethodExistence() { ...@@ -136,6 +151,32 @@ function testAPIMethodExistence() {
document.body.appendChild(webview); document.body.appendChild(webview);
} }
function testCustomElementCallbacksInaccessible() {
var CUSTOM_ELEMENT_CALLBACKS = [
// Custom Elements V0
// TODO(867831): Once we migrate to V1, we'll no longer need to check
// the V0 callbacks.
'createdCallback',
'attachedCallback',
'detachedCallback',
'attributeChangedCallback',
// Custom Elements V1
'connectedCallback',
'disconnectedCallback',
'attributeChangedCallback',
'adoptedCallback'
];
var webview = document.createElement('webview');
for (var callbackName of CUSTOM_ELEMENT_CALLBACKS) {
embedder.test.assertEq(
'undefined', typeof webview[callbackName],
callbackName + ' should not be accessible');
}
embedder.test.succeed();
}
// This test verifies that assigning the src attribute the same value it had // This test verifies that assigning the src attribute the same value it had
// prior to a crash spawns off a new guest process. // prior to a crash spawns off a new guest process.
function testAssignSrcAfterCrash() { function testAssignSrcAfterCrash() {
...@@ -1797,6 +1838,8 @@ function captureVisibleRegionDoCapture() {} ...@@ -1797,6 +1838,8 @@ function captureVisibleRegionDoCapture() {}
embedder.test.testList = { embedder.test.testList = {
'testAllowTransparencyAttribute': testAllowTransparencyAttribute, 'testAllowTransparencyAttribute': testAllowTransparencyAttribute,
'testAPIMethodExistence': testAPIMethodExistence, 'testAPIMethodExistence': testAPIMethodExistence,
'testCustomElementCallbacksInaccessible':
testCustomElementCallbacksInaccessible,
'testAssignSrcAfterCrash': testAssignSrcAfterCrash, 'testAssignSrcAfterCrash': testAssignSrcAfterCrash,
'testAutosizeAfterNavigation': testAutosizeAfterNavigation, 'testAutosizeAfterNavigation': testAutosizeAfterNavigation,
'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation,
......
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