Index: third_party/WebKit/LayoutTests/resources/testharnessreport.js |
diff --git a/third_party/WebKit/LayoutTests/resources/testharnessreport.js b/third_party/WebKit/LayoutTests/resources/testharnessreport.js |
index cbcfbe2ef00ba6b126a33e2f9f34f238cd51f102..d247c158f7cd376de0638bc0a48d12f6b164de07 100644 |
--- a/third_party/WebKit/LayoutTests/resources/testharnessreport.js |
+++ b/third_party/WebKit/LayoutTests/resources/testharnessreport.js |
@@ -128,6 +128,40 @@ |
document.head.appendChild(script); |
} |
+ function importTestPolyfils() { |
+ var pathAndBase = pathAndBaseNameInWPT(); |
+ if (!pathAndBase) |
+ return; |
+ var automationPath = location.pathname.replace(/\/external\/wpt\/.*$/, '/external/wpt_automation'); |
ortuno
2017/04/03 01:47:19
wpt_automation has a very specific purpose: Turn m
Reilly Grant (use Gerrit)
2017/04/05 18:39:37
Created a new wpt_polyfill directory for these.
|
+ if (location.hostname == 'web-platform.test') |
+ automationPath = '/wpt_automation'; |
+ |
+ var script = document.createElement('script'); |
+ if (pathAndBase.startsWith('/webusb/')) { |
+ // WebUSB tests require a polyfil for navigator.usb.test. This |
+ // script will be loaded asynchronously so we need to patch in |
+ // a version of navigator.usb.test.initialize() that will wait for |
+ // the script to load. |
+ script.src = automationPath + '/webusb/webusb-test.js'; |
+ let initializePromise = null; |
+ navigator.usb.test = { |
+ initialize: function() { |
+ if (!initializePromise) { |
+ initializePromise = new Promise(resolve => { |
+ script.onload = () => { |
+ resolve(navigator.usb.test.initialize()); |
+ } |
+ }); |
+ } |
+ return initializePromise; |
+ } |
+ }; |
+ } else { |
+ return; |
+ } |
+ document.head.appendChild(script); |
+ } |
+ |
var didDispatchLoadEvent = false; |
window.addEventListener('load', function() { |
didDispatchLoadEvent = true; |
@@ -266,4 +300,5 @@ |
} |
}); |
+ importTestPolyfils(); |
})(); |