| OLD | NEW |
| 1 /* | 1 /* |
| 2 * THIS FILE INTENTIONALLY LEFT BLANK | 2 * THIS FILE INTENTIONALLY LEFT BLANK |
| 3 * | 3 * |
| 4 * More specifically, this file is intended for vendors to implement | 4 * More specifically, this file is intended for vendors to implement |
| 5 * code needed to integrate testharness.js tests with their own test systems. | 5 * code needed to integrate testharness.js tests with their own test systems. |
| 6 * | 6 * |
| 7 * Typically such integration will attach callbacks when each test is | 7 * Typically such integration will attach callbacks when each test is |
| 8 * has run, using add_result_callback(callback(test)), or when the whole test fi
le has | 8 * has run, using add_result_callback(callback(test)), or when the whole test fi
le has |
| 9 * completed, using add_completion_callback(callback(tests, harness_status)). | 9 * completed, using add_completion_callback(callback(tests, harness_status)). |
| 10 * | 10 * |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Escape carriage returns as they break rietveld's difftools. | 71 // Escape carriage returns as they break rietveld's difftools. |
| 72 text = text.replace(/\r/g, "\\r"); | 72 text = text.replace(/\r/g, "\\r"); |
| 73 // Replace machine-dependent path with "...". | 73 // Replace machine-dependent path with "...". |
| 74 if (localPathRegExp) | 74 if (localPathRegExp) |
| 75 text = text.replace(localPathRegExp, "..."); | 75 text = text.replace(localPathRegExp, "..."); |
| 76 return text; | 76 return text; |
| 77 } | 77 } |
| 78 | 78 |
| 79 function isWPTManualTest() { | 79 function isWPTManualTest() { |
| 80 var path = location.pathname; | 80 var path = location.pathname; |
| 81 if (location.hostname == 'web-platform.test' && path.endsWith('-manual.h
tml')) | 81 if (location.hostname == 'web-platform.test' |
| 82 && /.*-manual(\.https)?\.html$/.test(path)) { |
| 82 return true; | 83 return true; |
| 83 return /\/external\/wpt\/.*-manual\.html$/.test(path); | 84 } |
| 85 return /\/external\/wpt\/.*-manual(\.https)?\.html$/.test(path); |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Returns a directory part relative to WPT root and a basename part of the | 88 // Returns a directory part relative to WPT root and a basename part of the |
| 87 // current test. e.g. | 89 // current test. e.g. |
| 88 // Current test: file:///.../LayoutTests/external/wpt/pointerevents/foobar.h
tml | 90 // Current test: file:///.../LayoutTests/external/wpt/pointerevents/foobar.h
tml |
| 89 // Output: "/pointerevents/foobar" | 91 // Output: "/pointerevents/foobar" |
| 90 function pathAndBaseNameInWPT() { | 92 function pathAndBaseNameInWPT() { |
| 91 var path = location.pathname; | 93 var path = location.pathname; |
| 92 if (location.hostname == 'web-platform.test') { | 94 if (location.hostname == 'web-platform.test') { |
| 93 var matches = path.match(/^(\/.*)\.html$/); | 95 var matches = path.match(/^(\/.*)\.html$/); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 automationPath = '/wpt_automation'; | 108 automationPath = '/wpt_automation'; |
| 107 | 109 |
| 108 // Export importAutomationScript for use by the automation scripts. | 110 // Export importAutomationScript for use by the automation scripts. |
| 109 window.importAutomationScript = function(relativePath) { | 111 window.importAutomationScript = function(relativePath) { |
| 110 var script = document.createElement('script'); | 112 var script = document.createElement('script'); |
| 111 script.src = automationPath + relativePath; | 113 script.src = automationPath + relativePath; |
| 112 document.head.appendChild(script); | 114 document.head.appendChild(script); |
| 113 } | 115 } |
| 114 | 116 |
| 115 var src; | 117 var src; |
| 116 if (pathAndBase.startsWith('/fullscreen/')) { | 118 if (pathAndBase.startsWith('/fullscreen/') |
| 117 // Fullscreen tests all use the same automation script. | 119 || pathAndBase.startsWith('/webusb/')) { |
| 120 // Fullscreen tests all use the same automation script and WebUSB |
| 121 // tests borrow it. |
| 118 src = automationPath + '/fullscreen/auto-click.js'; | 122 src = automationPath + '/fullscreen/auto-click.js'; |
| 119 } else if (pathAndBase.startsWith('/pointerevents/') | 123 } else if (pathAndBase.startsWith('/pointerevents/') |
| 120 || pathAndBase.startsWith('/uievents/')) { | 124 || pathAndBase.startsWith('/uievents/')) { |
| 121 // Per-test automation scripts. | 125 // Per-test automation scripts. |
| 122 src = automationPath + pathAndBase + '-automation.js'; | 126 src = automationPath + pathAndBase + '-automation.js'; |
| 123 } else { | 127 } else { |
| 124 return; | 128 return; |
| 125 } | 129 } |
| 126 var script = document.createElement('script'); | 130 var script = document.createElement('script'); |
| 127 script.src = src; | 131 script.src = src; |
| 128 document.head.appendChild(script); | 132 document.head.appendChild(script); |
| 129 } | 133 } |
| 130 | 134 |
| 135 function importTestPolyfills() { |
| 136 var pathAndBase = pathAndBaseNameInWPT(); |
| 137 if (!pathAndBase) |
| 138 return; |
| 139 var automationPath = location.pathname.replace(/\/external\/wpt\/.*$/, '
/external/wpt_polyfill'); |
| 140 if (location.hostname == 'web-platform.test') |
| 141 polyfillPath = '/wpt_polyfill'; |
| 142 |
| 143 var script = document.createElement('script'); |
| 144 if (pathAndBase.startsWith('/webusb/')) { |
| 145 // WebUSB tests require a polyfill for navigator.usb.test. This |
| 146 // script will be loaded asynchronously so we need to patch in |
| 147 // a version of navigator.usb.test.initialize() that will wait for |
| 148 // the script to load. |
| 149 script.src = polyfillPath + '/webusb/webusb-test.js'; |
| 150 let initializePromise = null; |
| 151 navigator.usb.test = { |
| 152 initialize: function() { |
| 153 if (!initializePromise) { |
| 154 initializePromise = new Promise(resolve => { |
| 155 script.onload = () => { |
| 156 resolve(navigator.usb.test.initialize()); |
| 157 } |
| 158 }); |
| 159 } |
| 160 return initializePromise; |
| 161 } |
| 162 }; |
| 163 } else { |
| 164 return; |
| 165 } |
| 166 document.head.appendChild(script); |
| 167 } |
| 168 |
| 131 var didDispatchLoadEvent = false; | 169 var didDispatchLoadEvent = false; |
| 132 window.addEventListener('load', function() { | 170 window.addEventListener('load', function() { |
| 133 didDispatchLoadEvent = true; | 171 didDispatchLoadEvent = true; |
| 134 if (isWPTManualTest()) { | 172 if (isWPTManualTest()) { |
| 135 setTimeout(loadAutomationScript, 0); | 173 setTimeout(loadAutomationScript, 0); |
| 136 } | 174 } |
| 137 }, { once: true }); | 175 }, { once: true }); |
| 138 | 176 |
| 139 add_start_callback(function(properties) { | 177 add_start_callback(function(properties) { |
| 140 if (properties.output_document) | 178 if (properties.output_document) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // This function might not be the last 'completion callback', and | 297 // This function might not be the last 'completion callback', and |
| 260 // another completion callback might generate more results. So, we | 298 // another completion callback might generate more results. So, we |
| 261 // don't dump the results immediately. | 299 // don't dump the results immediately. |
| 262 setTimeout(done, 0); | 300 setTimeout(done, 0); |
| 263 } else { | 301 } else { |
| 264 // Parsing the test HTML isn't finished yet. | 302 // Parsing the test HTML isn't finished yet. |
| 265 window.addEventListener('load', done); | 303 window.addEventListener('load', done); |
| 266 } | 304 } |
| 267 }); | 305 }); |
| 268 | 306 |
| 307 importTestPolyfills(); |
| 269 })(); | 308 })(); |
| OLD | NEW |