| Index: extensions/test/data/web_view/apitest/main.js
|
| diff --git a/extensions/test/data/web_view/apitest/main.js b/extensions/test/data/web_view/apitest/main.js
|
| index 14e7e97b339dd5cd24a346af61dabc5abfd5c813..377cd666b8b880d01b87dc41b2b6af2b2a870b4e 100644
|
| --- a/extensions/test/data/web_view/apitest/main.js
|
| +++ b/extensions/test/data/web_view/apitest/main.js
|
| @@ -50,6 +50,26 @@ embedder.test.succeed = function() {
|
|
|
| // Tests begin.
|
|
|
| +// This test verifies that the allowtransparency property cannot be changed
|
| +// once set. The attribute can only be deleted.
|
| +function testAllowTransparencyAttribute() {
|
| + var webview = document.createElement('webview');
|
| + webview.src = 'data:text/html,webview test';
|
| + 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');
|
| + embedder.test.assertFalse(webview.allowtransparency);
|
| + embedder.test.succeed();
|
| + });
|
| +
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| function testAPIMethodExistence() {
|
| var apiMethodsToCheck = [
|
| 'back',
|
| @@ -91,8 +111,242 @@ function testAPIMethodExistence() {
|
| document.body.appendChild(webview);
|
| }
|
|
|
| +// Makes sure 'sizechanged' event is fired only if autosize attribute is
|
| +// specified.
|
| +// After loading <webview> without autosize attribute and a size, say size1,
|
| +// we set autosize attribute and new min size with size2. We would get (only
|
| +// one) sizechanged event with size1 as old size and size2 as new size.
|
| +function testAutosizeAfterNavigation() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + var step = 1;
|
| + var sizeChangeHandler = function(e) {
|
| + switch (step) {
|
| + case 1:
|
| + // This would be triggered after we set autosize attribute.
|
| + embedder.test.assertEq(50, e.oldWidth);
|
| + embedder.test.assertEq(100, e.oldHeight);
|
| + embedder.test.assertTrue(e.newWidth >= 60 && e.newWidth <= 70);
|
| + embedder.test.assertTrue(e.newHeight >= 110 && e.newHeight <= 120);
|
| +
|
| + // Remove autosize attribute and expect webview to return to its
|
| + // original size.
|
| + webview.removeAttribute('autosize');
|
| + break;
|
| + case 2:
|
| + // Expect 50x100.
|
| + embedder.test.assertEq(50, e.newWidth);
|
| + embedder.test.assertEq(100, e.newHeight);
|
| +
|
| + embedder.test.succeed();
|
| + break;
|
| + default:
|
| + window.console.log('Unexpected sizechanged event, step = ' + step);
|
| + embedder.test.fail();
|
| + break;
|
| + }
|
| +
|
| + ++step;
|
| + };
|
| +
|
| + webview.addEventListener('sizechanged', sizeChangeHandler);
|
| +
|
| + webview.addEventListener('loadstop', function(e) {
|
| + webview.setAttribute('autosize', true);
|
| + webview.setAttribute('minwidth', 60);
|
| + webview.setAttribute('maxwidth', 70);
|
| + webview.setAttribute('minheight', 110);
|
| + webview.setAttribute('maxheight', 120);
|
| + });
|
| +
|
| + webview.style.width = '50px';
|
| + webview.style.height = '100px';
|
| + webview.setAttribute('src', 'data:text/html,webview test sizechanged event');
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +// This test verifies that if a browser plugin is in autosize mode before
|
| +// navigation then the guest starts auto-sized.
|
| +function testAutosizeBeforeNavigation() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + webview.setAttribute('autosize', 'true');
|
| + webview.setAttribute('minwidth', 200);
|
| + webview.setAttribute('maxwidth', 210);
|
| + webview.setAttribute('minheight', 100);
|
| + webview.setAttribute('maxheight', 110);
|
| +
|
| + webview.addEventListener('sizechanged', function(e) {
|
| + embedder.test.assertEq(0, e.oldWidth);
|
| + embedder.test.assertEq(0, e.oldHeight);
|
| + embedder.test.assertTrue(e.newWidth >= 200 && e.newWidth <= 210);
|
| + embedder.test.assertTrue(e.newHeight >= 100 && e.newHeight <= 110);
|
| + embedder.test.succeed();
|
| + });
|
| +
|
| + webview.setAttribute('src', 'data:text/html,webview test sizechanged event');
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +// This test verifies that a lengthy page with autosize enabled will report
|
| +// the correct height in the sizechanged event.
|
| +function testAutosizeHeight() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + webview.autosize = true;
|
| + webview.minwidth = 200;
|
| + webview.maxwidth = 210;
|
| + webview.minheight = 40;
|
| + webview.maxheight = 200;
|
| +
|
| + var step = 1;
|
| + webview.addEventListener('sizechanged', function(e) {
|
| + switch (step) {
|
| + case 1:
|
| + embedder.test.assertEq(0, e.oldHeight);
|
| + embedder.test.assertEq(200, e.newHeight);
|
| + // Change the maxheight to verify that we see the change.
|
| + webview.maxheight = 50;
|
| + break;
|
| + case 2:
|
| + embedder.test.assertEq(200, e.oldHeight);
|
| + embedder.test.assertEq(50, e.newHeight);
|
| + embedder.test.succeed();
|
| + break;
|
| + default:
|
| + window.console.log('Unexpected sizechanged event, step = ' + step);
|
| + embedder.test.fail();
|
| + break;
|
| + }
|
| + ++step;
|
| + });
|
| +
|
| + webview.src = 'data:text/html,' +
|
| + 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
|
| + 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
|
| + 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
|
| + 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
|
| + 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>';
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +// This test verifies that all autosize attributes can be removed
|
| +// without crashing the plugin, or throwing errors.
|
| +function testAutosizeRemoveAttributes() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + var step = 1;
|
| + var sizeChangeHandler = function(e) {
|
| + switch (step) {
|
| + case 1:
|
| + // This is the sizechanged event for autosize.
|
| +
|
| + // Remove attributes.
|
| + webview.removeAttribute('minwidth');
|
| + webview.removeAttribute('maxwidth');
|
| + webview.removeAttribute('minheight');
|
| + webview.removeAttribute('maxheight');
|
| + webview.removeAttribute('autosize');
|
| +
|
| + // We'd get one more sizechanged event after we turn off
|
| + // autosize.
|
| + webview.style.width = '500px';
|
| + webview.style.height = '500px';
|
| + break;
|
| + case 2:
|
| + embedder.test.succeed();
|
| + break;
|
| + }
|
| +
|
| + ++step;
|
| + };
|
| +
|
| + webview.addEventListener('loadstop', function(e) {
|
| + webview.minwidth = 300;
|
| + webview.maxwidth = 700;
|
| + webview.minheight = 600;
|
| + webview.maxheight = 400;
|
| + webview.autosize = true;
|
| + });
|
| +
|
| + webview.addEventListener('sizechanged', sizeChangeHandler);
|
| +
|
| + webview.style.width = '640px';
|
| + webview.style.height = '480px';
|
| + webview.setAttribute('src', 'data:text/html,webview check autosize');
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +// This test verifies that autosize works when some of the parameters are unset.
|
| +function testAutosizeWithPartialAttributes() {
|
| + window.console.log('testAutosizeWithPartialAttributes');
|
| + var webview = document.createElement('webview');
|
| +
|
| + var step = 1;
|
| + var sizeChangeHandler = function(e) {
|
| + window.console.log('sizeChangeHandler, new: ' +
|
| + e.newWidth + ' X ' + e.newHeight);
|
| + switch (step) {
|
| + case 1:
|
| + // Expect 300x200.
|
| + embedder.test.assertEq(300, e.newWidth);
|
| + embedder.test.assertEq(200, e.newHeight);
|
| +
|
| + // Change the min size to cause a relayout.
|
| + webview.minwidth = 500;
|
| + break;
|
| + case 2:
|
| + embedder.test.assertTrue(e.newWidth >= webview.minwidth);
|
| + embedder.test.assertTrue(e.newWidth <= webview.maxwidth);
|
| +
|
| + // Tests when minwidth > maxwidth, minwidth = maxwidth.
|
| + // i.e. minwidth is essentially 700.
|
| + webview.minwidth = 800;
|
| + break;
|
| + case 3:
|
| + // Expect 700X?
|
| + embedder.test.assertEq(700, e.newWidth);
|
| + embedder.test.assertTrue(e.newHeight >= 200);
|
| + embedder.test.assertTrue(e.newHeight <= 600);
|
| +
|
| + embedder.test.succeed();
|
| + break;
|
| + default:
|
| + window.console.log('Unexpected sizechanged event, step = ' + step);
|
| + embedder.test.fail();
|
| + break;
|
| + }
|
| +
|
| + ++step;
|
| + };
|
| +
|
| + webview.addEventListener('sizechanged', sizeChangeHandler);
|
| +
|
| + webview.addEventListener('loadstop', function(e) {
|
| + webview.minwidth = 300;
|
| + webview.maxwidth = 700;
|
| + webview.minheight = 200;
|
| + webview.maxheight = 600;
|
| + webview.autosize = true;
|
| + });
|
| +
|
| + webview.style.width = '640px';
|
| + webview.style.height = '480px';
|
| + webview.setAttribute('src', 'data:text/html,webview check autosize');
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +
|
| +// Tests end.
|
| +
|
| embedder.test.testList = {
|
| - 'testAPIMethodExistence': testAPIMethodExistence
|
| + 'testAllowTransparencyAttribute': testAllowTransparencyAttribute,
|
| + 'testAPIMethodExistence': testAPIMethodExistence,
|
| + 'testAutosizeAfterNavigation': testAutosizeAfterNavigation,
|
| + 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation,
|
| + 'testAutosizeHeight': testAutosizeHeight,
|
| + 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes,
|
| + 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes
|
| };
|
|
|
| onload = function() {
|
|
|