From f487ebd109f6cdbb920e1f8b7a782f1436107e49 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 24 Apr 2018 20:03:10 -0400 Subject: [PATCH] [feature-policy] Avoid timeouts in absence of API Many tests written for the `document.policy.allowedFeatures` method reference the API without first ensuring its availability. The method is a new addition to the web platform, so this pattern produces a ReferenceError in many browsers (i.e. all major browsers at the time of this writing). Because the error occurs in the context of an iframe, the test harness is unable to detect it, and the affected tests report an error only following an extended delay. Guard the reference with a `try`/`catch` block so that failures are detected and reported immediately. --- .../resources/feature-policy-allowedfeatures.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/feature-policy/resources/feature-policy-allowedfeatures.html b/feature-policy/resources/feature-policy-allowedfeatures.html index 9cc8e1e33a32d2..7bd90a0d01ce92 100644 --- a/feature-policy/resources/feature-policy-allowedfeatures.html +++ b/feature-policy/resources/feature-policy-allowedfeatures.html @@ -2,6 +2,14 @@ 'use strict'; window.onload = function() { - parent.postMessage(document.policy.allowedFeatures(), '*'); + var value; + + try { + value = document.policy.allowedFeatures(); + } catch (error) { + value = [error && error.message]; + } + + parent.postMessage(value, '*'); }