Commit abb035a0 authored by paulmeyer's avatar paulmeyer Committed by Commit bot

Got rid of the internal copies of webview attributes.

Webview attributes are now only stored in one location (in the webview node), so that all the code needed to sync up the copies could be removed (and was).

Also reworked the behavior of the |allowtransparency| and |autosize| to be both consistent with each other and more intuitive in general (they are both treated like booleans now). I updated the tests to reflect this new behavior.

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

Cr-Commit-Position: refs/heads/master@{#302661}
parent 71ffa214
......@@ -950,8 +950,10 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCannotMutateEventName) {
TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER);
}
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPartitionRaisesException) {
TestHelper("testPartitionRaisesException", "web_view/shim", NO_TEST_SERVER);
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestPartitionChangeAfterNavigation) {
TestHelper("testPartitionChangeAfterNavigation",
"web_view/shim",
NO_TEST_SERVER);
}
IN_PROC_BROWSER_TEST_F(WebViewTest,
......
......@@ -97,20 +97,28 @@ embedder.test.assertFalse = function(condition) {
// Tests begin.
// This test verifies that the allowtransparency property cannot be changed
// once set. The attribute can only be deleted.
// This test verifies that the allowtransparency property is interpreted as true
// if it exists (regardless of its value), and can be removed by setting it to
// to anything false.
function testAllowTransparencyAttribute() {
var webview = document.createElement('webview');
webview.src = 'data:text/html,webview test';
embedder.test.assertFalse(webview.hasAttribute('allowtransparency'));
embedder.test.assertFalse(webview.allowtransparency);
webview.allowtransparency = true;
webview.addEventListener('loadstop', function(e) {
embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
webview.allowtransparency = false;
embedder.test.assertTrue(webview.allowtransparency);
embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
webview.removeAttribute('allowtransparency');
webview.allowtransparency = false;
embedder.test.assertFalse(webview.hasAttribute('allowtransparency'));
embedder.test.assertFalse(webview.allowtransparency);
webview.allowtransparency = '';
embedder.test.assertFalse(webview.hasAttribute('allowtransparency'));
embedder.test.assertFalse(webview.allowtransparency);
webview.allowtransparency = 'some string';
embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
embedder.test.assertTrue(webview.allowtransparency);
embedder.test.succeed();
});
......@@ -616,7 +624,7 @@ function testLoadProgressEvent() {
// Current expected behavior is that the second event listener will still
// fire without crashing.
function testDestroyOnEventListener() {
var webview = util.createWebViewTagInDOM(arguments.callee.name);
var webview = document.createElement('webview');
var url = 'data:text/html,<body>Destroy test</body>';
var loadCommitCount = 0;
......@@ -647,13 +655,14 @@ function testDestroyOnEventListener() {
loadCommitCommon(e);
});
webview.setAttribute('src', url);
document.body.appendChild(webview);
}
// This test registers two event listeners on a same event (loadcommit).
// Each of the listener tries to change some properties on the event param,
// which should not be possible.
function testCannotMutateEventName() {
var webview = util.createWebViewTagInDOM(arguments.callee.name);
var webview = document.createElement('webview');
var url = 'data:text/html,<body>Two</body>';
var loadCommitACalled = false;
......@@ -695,23 +704,20 @@ function testCannotMutateEventName() {
webview.addEventListener('loadcommit', onLoadCommitA);
webview.addEventListener('loadcommit', onLoadCommitB);
webview.setAttribute('src', url);
document.body.appendChild(webview);
}
// This test verifies that setting the partition attribute after the src has
// been set raises an exception.
function testPartitionRaisesException() {
// This test verifies that the partion attribute cannot be changed after the src
// has been set.
function testPartitionChangeAfterNavigation() {
var webview = document.createElement('webview');
var partitionAttribute = arguments.callee.name;
webview.setAttribute('partition', partitionAttribute);
var loadstopHandler = function(e) {
try {
webview.partition = 'illegal';
embedder.test.fail();
} catch (e) {
embedder.test.assertEq(partitionAttribute, webview.partition);
embedder.test.succeed();
}
};
webview.addEventListener('loadstop', loadstopHandler);
......@@ -1999,7 +2005,7 @@ embedder.test.testList = {
'testLoadProgressEvent': testLoadProgressEvent,
'testDestroyOnEventListener': testDestroyOnEventListener,
'testCannotMutateEventName': testCannotMutateEventName,
'testPartitionRaisesException': testPartitionRaisesException,
'testPartitionChangeAfterNavigation': testPartitionChangeAfterNavigation,
'testPartitionRemovalAfterNavigationFails':
testPartitionRemovalAfterNavigationFails,
'testExecuteScriptFail': testExecuteScriptFail,
......
......@@ -615,8 +615,8 @@ IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestOnEventProperty) {
RunTest("testOnEventProperties", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestPartitionRaisesException) {
RunTest("testPartitionRaisesException", "web_view/apitest");
IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestPartitionChangeAfterNavigation) {
RunTest("testPartitionChangeAfterNavigation", "web_view/apitest");
}
IN_PROC_BROWSER_TEST_F(WebViewAPITest,
......
......@@ -13,63 +13,69 @@ var WebViewConstants = require('webViewConstants').WebViewConstants;
// Default implementation of a WebView attribute.
function WebViewAttribute(name, webViewImpl) {
this.name = name;
this.value = '';
this.webViewImpl = webViewImpl;
this.ignoreNextMutation = false;
}
// Retrieves and returns the attribute's value.
WebViewAttribute.prototype.getValue = function() {
return this.value || '';
return this.webViewImpl.webviewNode.getAttribute(this.name) || '';
};
// Sets the attribute's value.
WebViewAttribute.prototype.setValue = function(value) {
this.value = value;
this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
};
// Called when the attribute's value changes.
WebViewAttribute.prototype.handleMutation = function() {}
// Attribute specifying whether transparency is allowed in the webview.
function BooleanAttribute(name, webViewImpl) {
WebViewAttribute.call(this, name, webViewImpl);
}
BooleanAttribute.prototype = new WebViewAttribute();
BooleanAttribute.prototype.getValue = function() {
// This attribute is treated as a boolean, and is retrieved as such.
return this.webViewImpl.webviewNode.hasAttribute(this.name);
}
BooleanAttribute.prototype.setValue = function(value) {
if (!value) {
this.webViewImpl.webviewNode.removeAttribute(this.name);
} else {
this.webViewImpl.webviewNode.setAttribute(this.name, '');
}
}
// Attribute representing the state of the storage partition.
function Partition(webViewImpl) {
WebViewAttribute.call(this,
WebViewConstants.ATTRIBUTE_PARTITION,
webViewImpl);
this.validPartitionId = true;
this.persistStorage = false;
this.storagePartitionId = '';
this.webViewImpl = webViewImpl;
}
Partition.prototype = new WebViewAttribute(
WebViewConstants.ATTRIBUTE_PARTITION);
Partition.prototype = new WebViewAttribute();
Partition.prototype.getValue = function() {
if (!this.validPartitionId) {
return '';
}
return (this.persistStorage ? 'persist:' : '') + this.storagePartitionId;
};
Partition.prototype.handleMutation = function(oldValue, newValue) {
newValue = newValue || '';
Partition.prototype.setValue = function(value) {
var result = {};
var hasNavigated = !this.webViewImpl.beforeFirstNavigation;
if (hasNavigated) {
result.error = WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED;
return result;
}
if (!value) {
value = '';
// The partition cannot change if the webview has already navigated.
if (!this.webViewImpl.beforeFirstNavigation) {
window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
this.ignoreNextMutation = true;
this.webViewImpl.webviewNode.setAttribute(this.name, oldValue);
return;
}
var LEN = 'persist:'.length;
if (value.substr(0, LEN) == 'persist:') {
value = value.substr(LEN);
if (!value) {
if (newValue == 'persist:') {
this.validPartitionId = false;
result.error = WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE;
return result;
window.console.error(
WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
}
this.persistStorage = true;
} else {
this.persistStorage = false;
}
this.storagePartitionId = value;
return result;
};
}
// -----------------------------------------------------------------------------
......@@ -79,12 +85,14 @@ WebView.prototype.setupWebViewAttributes = function() {
// Initialize the attributes with special behavior (and custom attribute
// objects).
this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
new BooleanAttribute(WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, this);
this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE] =
new BooleanAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE, this);
this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this);
// Initialize the remaining attributes, which have default behavior.
var defaultAttributes = [WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY,
WebViewConstants.ATTRIBUTE_AUTOSIZE,
WebViewConstants.ATTRIBUTE_MAXHEIGHT,
var defaultAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT,
WebViewConstants.ATTRIBUTE_MAXWIDTH,
WebViewConstants.ATTRIBUTE_MINHEIGHT,
WebViewConstants.ATTRIBUTE_MINWIDTH,
......
......@@ -71,15 +71,22 @@ embedder.test.succeed = function() {
function testAllowTransparencyAttribute() {
var webview = document.createElement('webview');
webview.src = 'data:text/html,webview test';
embedder.test.assertFalse(webview.hasAttribute('allowtransparency'));
embedder.test.assertFalse(webview.allowtransparency);
webview.allowtransparency = true;
webview.addEventListener('loadstop', function(e) {
embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
webview.allowtransparency = false;
embedder.test.assertTrue(webview.allowtransparency);
embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
webview.removeAttribute('allowtransparency');
webview.allowtransparency = false;
embedder.test.assertFalse(webview.hasAttribute('allowtransparency'));
embedder.test.assertFalse(webview.allowtransparency);
webview.allowtransparency = '';
embedder.test.assertFalse(webview.hasAttribute('allowtransparency'));
embedder.test.assertFalse(webview.allowtransparency);
webview.allowtransparency = 'some string';
embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
embedder.test.assertTrue(webview.allowtransparency);
embedder.test.succeed();
});
......@@ -1282,21 +1289,17 @@ function testOnEventProperties() {
document.body.appendChild(webview);
}
// This test verifies that setting the partition attribute after the src has
// been set raises an exception.
function testPartitionRaisesException() {
// This test verifies that the partion attribute cannot be changed after the src
// has been set.
function testPartitionChangeAfterNavigation() {
var webview = document.createElement('webview');
var partitionAttribute = arguments.callee.name;
webview.setAttribute('partition', partitionAttribute);
var loadstopHandler = function(e) {
try {
webview.partition = 'illegal';
embedder.test.fail();
} catch (e) {
embedder.test.assertEq(partitionAttribute, webview.partition);
embedder.test.succeed();
}
};
webview.addEventListener('loadstop', loadstopHandler);
......@@ -1707,7 +1710,7 @@ embedder.test.testList = {
'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink,
'testNewWindowTwoListeners': testNewWindowTwoListeners,
'testOnEventProperties': testOnEventProperties,
'testPartitionRaisesException': testPartitionRaisesException,
'testPartitionChangeAfterNavigation': testPartitionChangeAfterNavigation,
'testPartitionRemovalAfterNavigationFails':
testPartitionRemovalAfterNavigationFails,
'testReassignSrcAttribute': testReassignSrcAttribute,
......
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