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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 function isCSSWGTest() { | 72 function isCSSWGTest() { |
73 var flags = document.querySelector('meta[name=flags]'), | 73 var flags = document.querySelector('meta[name=flags]'), |
74 content = flags ? flags.getAttribute('content') : null; | 74 content = flags ? flags.getAttribute('content') : null; |
75 return content && content.match(/\bdom\b/); | 75 return content && content.match(/\bdom\b/); |
76 } | 76 } |
77 | 77 |
78 function isJSTest() { | 78 function isJSTest() { |
79 return !!document.querySelector('script[src*="/resources/testharness"]')
; | 79 return !!document.querySelector('script[src*="/resources/testharness"]')
; |
80 } | 80 } |
81 | 81 |
| 82 function isWPTManualTest() { |
| 83 var path = location.pathname; |
| 84 return /\/imported\/wpt\/.*-manual\.html$/.test(path); |
| 85 } |
82 | 86 |
83 function injectSyntheticInput() { | 87 function loadAutomationScript() { |
84 var path = window.location.pathname; | 88 var testPath = location.pathname; |
85 if (path.match(/imported\/wpt\/.*\.html$/)) { | 89 var automationPath = testPath.replace(/\/imported\/wpt\/.*$/, '/imported
/wpt_automation'); |
86 // Set a global variable for the address of automated input script i
f they need to use it. | |
87 var automated_input_scripts_folder = path.replace(/imported\/wpt\/(.
*)\.html$/, 'imported/wpt_automation'); | |
88 | 90 |
89 importAutomationScript = function(relativePath) { | 91 // Export importAutomationScript for use by the automation scripts. |
90 var common_script = document.createElement('script'); | 92 window.importAutomationScript = function(relativePath) { |
91 common_script.setAttribute('src', automated_input_scripts_folder +
relativePath); | 93 var script = document.createElement('script'); |
92 document.head.appendChild(common_script); | 94 script.src = automationPath + relativePath; |
93 } | 95 document.head.appendChild(script); |
| 96 } |
94 | 97 |
95 path = path.replace(/imported\/wpt\/(.*)\.html$/, "imported/wpt_auto
mation/$1-automation.js"); | 98 var src; |
96 var input_script = document.createElement('script'); | 99 if (testPath.includes('/imported/wpt/fullscreen/')) { |
97 input_script.setAttribute('src', path); | 100 // Fullscreen tests all use the same automation script. |
98 document.head.appendChild(input_script); | 101 src = automationPath + '/fullscreen/auto-click.js'; |
| 102 } else if (testPath.includes('/imported/wpt/pointerevents/') |
| 103 || testPath.includes('/imported/wpt/uievents/')) { |
| 104 // Per-test automation scripts. |
| 105 src = testPath.replace(/\/imported\/wpt\/(.*)\.html$/, "/imported/wp
t_automation/$1-automation.js"); |
| 106 } else { |
| 107 return; |
99 } | 108 } |
| 109 var script = document.createElement('script'); |
| 110 script.src = src; |
| 111 document.head.appendChild(script); |
100 } | 112 } |
101 | 113 |
102 var didDispatchLoadEvent = false; | 114 var didDispatchLoadEvent = false; |
103 var handleLoad = function() { | 115 window.addEventListener('load', function() { |
104 didDispatchLoadEvent = true; | 116 didDispatchLoadEvent = true; |
105 window.removeEventListener('load', handleLoad); | 117 if (isWPTManualTest()) { |
106 // Add synthetic input to pointer event manual tests | 118 setTimeout(loadAutomationScript, 0); |
107 if(window.location.pathname.includes('imported/wpt/pointerevents/') | |
108 || window.location.pathname.includes('imported/wpt/uievents/')) { | |
109 setTimeout(injectSyntheticInput, 0); | |
110 } | 119 } |
111 }; | 120 }, { once: true }); |
112 window.addEventListener('load', handleLoad, false); | |
113 | 121 |
114 // Using a callback function, test results will be added to the page in a | 122 // Using a callback function, test results will be added to the page in a |
115 // manner that allows dumpAsText to produce readable test results. | 123 // manner that allows dumpAsText to produce readable test results. |
116 add_completion_callback(function (tests, harness_status) { | 124 add_completion_callback(function (tests, harness_status) { |
117 | 125 |
118 // Create element to hold results. | 126 // Create element to hold results. |
119 var results = document.createElement("pre"); | 127 var results = document.createElement("pre"); |
120 | 128 |
121 // Declare result string. | 129 // Declare result string. |
122 var resultStr = "This is a testharness.js-based test.\n"; | 130 var resultStr = "This is a testharness.js-based test.\n"; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // another completion callback might generate more results. So, we | 207 // another completion callback might generate more results. So, we |
200 // don't dump the results immediately. | 208 // don't dump the results immediately. |
201 setTimeout(done, 0); | 209 setTimeout(done, 0); |
202 } else { | 210 } else { |
203 // Parsing the test HTML isn't finished yet. | 211 // Parsing the test HTML isn't finished yet. |
204 window.addEventListener('load', done); | 212 window.addEventListener('load', done); |
205 } | 213 } |
206 }); | 214 }); |
207 | 215 |
208 })(); | 216 })(); |
OLD | NEW |