| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 onload = function() { |
| 6 chrome.test.runTests([ |
| 7 function webView() { |
| 8 var webview = document.querySelector('webview'); |
| 9 // Since we can't currently inspect the page loaded inside the <webview>, |
| 10 // the only way we can check that the shim is working is by changing the |
| 11 // size and seeing if the shim updates the size of the DOM. |
| 12 chrome.test.assertEq(300, webview.offsetWidth); |
| 13 chrome.test.assertEq(200, webview.offsetHeight); |
| 14 |
| 15 webview.setAttribute('width', 310); |
| 16 webview.setAttribute('height', 210); |
| 17 |
| 18 // Timeout is necessary to give the mutation observers a chance to fire. |
| 19 setTimeout(function() { |
| 20 chrome.test.assertEq(310, webview.offsetWidth); |
| 21 chrome.test.assertEq(210, webview.offsetHeight); |
| 22 |
| 23 // Should also be able to query/update the dimensions via getterts/ |
| 24 // setters. |
| 25 chrome.test.assertEq(310, webview.width); |
| 26 chrome.test.assertEq(210, webview.height); |
| 27 |
| 28 webview.width = 320; |
| 29 webview.height = 220; |
| 30 |
| 31 // Setters also end up operating via mutation observers. |
| 32 setTimeout(function() { |
| 33 chrome.test.assertEq(320, webview.offsetWidth); |
| 34 chrome.test.assertEq(220, webview.offsetHeight); |
| 35 |
| 36 var dynamicWebViewTag = document.createElement('webview'); |
| 37 dynamicWebViewTag.setAttribute( |
| 38 'src', 'data:text/html,dynamic browser'); |
| 39 dynamicWebViewTag.setAttribute('width', '330'); |
| 40 dynamicWebViewTag.setAttribute('height', '230'); |
| 41 document.body.appendChild(dynamicWebViewTag); |
| 42 |
| 43 setTimeout(function() { |
| 44 chrome.test.assertEq(330, dynamicWebViewTag.offsetWidth); |
| 45 chrome.test.assertEq(230, dynamicWebViewTag.offsetHeight); |
| 46 |
| 47 chrome.test.succeed(); |
| 48 }, 0); |
| 49 }, 0); |
| 50 }, 0); |
| 51 }, |
| 52 |
| 53 function webViewApiMethodExistence() { |
| 54 var webview = document.createElement('webview'); |
| 55 webview.setAttribute('src', 'data:text/html,webview check api'); |
| 56 var apiMethodsToCheck = [ |
| 57 'addEventListener', |
| 58 'back', |
| 59 'canGoBack', |
| 60 'canGoForward', |
| 61 'forward', |
| 62 'getProcessId', |
| 63 'go', |
| 64 'reload', |
| 65 'removeEventListener', |
| 66 'stop', |
| 67 'terminate' |
| 68 ]; |
| 69 document.body.appendChild(webview); |
| 70 |
| 71 // Timeout is necessary to give the mutation observers of the webview tag |
| 72 // shim a chance to fire. |
| 73 setTimeout(function() { |
| 74 for (var i = 0; i < apiMethodsToCheck.length; ++i) { |
| 75 chrome.test.assertEq('function', |
| 76 typeof webview[apiMethodsToCheck[i]]); |
| 77 } |
| 78 |
| 79 // Check contentWindow. |
| 80 chrome.test.assertEq('object', typeof webview.contentWindow); |
| 81 chrome.test.assertEq('function', |
| 82 typeof webview.contentWindow.postMessage); |
| 83 |
| 84 chrome.test.succeed(); |
| 85 }, 0); |
| 86 }, |
| 87 |
| 88 function webViewEventListeners() { |
| 89 var webview = document.createElement('webview'); |
| 90 webview.setAttribute('src', 'data:text/html,webview check api'); |
| 91 document.body.appendChild(webview); |
| 92 |
| 93 var validEvents = [ |
| 94 'exit', |
| 95 'loadabort', |
| 96 'loadredirect', |
| 97 'loadstart', |
| 98 'loadstop' |
| 99 ]; |
| 100 var invalidEvents = [ |
| 101 'makemesandwich', |
| 102 'sudomakemesandwich' |
| 103 ]; |
| 104 |
| 105 // Timeout is necessary to give the mutation observers of the webview tag |
| 106 // shim a chance to fire. |
| 107 setTimeout(function() { |
| 108 for (var i = 0; i < validEvents.length; ++i) { |
| 109 chrome.test.assertTrue( |
| 110 webview.addEventListener(validEvents[i], function() {})); |
| 111 } |
| 112 |
| 113 for (var i = 0; i < invalidEvents.length; ++i) { |
| 114 chrome.test.assertFalse( |
| 115 webview.addEventListener(invalidEvents[i], function() {})); |
| 116 } |
| 117 |
| 118 chrome.test.succeed(); |
| 119 }, 0); |
| 120 }, |
| 121 |
| 122 function webViewEventName() { |
| 123 var webview = document.createElement('webview'); |
| 124 webview.setAttribute('src', 'data:text/html,webview check api'); |
| 125 document.body.appendChild(webview); |
| 126 |
| 127 setTimeout(function() { |
| 128 webview.addEventListener('loadstart', function(evt) { |
| 129 chrome.test.assertEq('loadstart', evt.name); |
| 130 }); |
| 131 |
| 132 webview.addEventListener('loadstop', function(evt) { |
| 133 chrome.test.assertEq('loadstop', evt.name); |
| 134 webview.terminate(); |
| 135 }); |
| 136 |
| 137 webview.addEventListener('exit', function(evt) { |
| 138 chrome.test.assertEq('exit', evt.name); |
| 139 chrome.test.succeed(); |
| 140 }); |
| 141 |
| 142 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
| 143 }, 0); |
| 144 } |
| 145 ]); |
| 146 }; |
| OLD | NEW |