From d1b3ba1b2656ce27945e3e2eaffffa7f6563c78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Daoust?= Date: Fri, 26 Aug 2016 12:16:21 +0200 Subject: [PATCH] Make HTTPS tests fail if they are loaded over HTTP Test files that end with ".https.html" trigger a check on the current protocol. If the current protocol is not "https:", all tests in this test file fail with a "Test page must be loaded over HTTPS" message. --- testharness.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/testharness.js b/testharness.js index 91dfab5..0398931 100644 --- a/testharness.js +++ b/testharness.js @@ -489,6 +489,19 @@ policies and contribution forms [3]. return 'ServiceWorker' in self && worker instanceof ServiceWorker; } + function enforce_https() { + var pos = 0; + if (location && location.pathname) { + pos = location.pathname.indexOf(".https.html"); + if ((pos !== -1) && + (pos === (location.pathname.length - ".https.html".length)) && + (location.protocol !== "https:")) { + assert(false, "enforce_https", "Test page must be loaded over HTTPS.", + "Protocol is ${protocol}", {protocol:location.protocol}); + } + } + } + /* * API functions */ @@ -498,6 +511,7 @@ policies and contribution forms [3]. var test_name = name ? name : test_environment.next_default_test_name(); properties = properties ? properties : {}; var test_obj = new Test(test_name, properties); + test_obj.step(enforce_https, test_obj, test_obj); test_obj.step(func, test_obj, test_obj); if (test_obj.phase === test_obj.phases.STARTED) { test_obj.done(); @@ -514,6 +528,7 @@ policies and contribution forms [3]. var test_name = name ? name : test_environment.next_default_test_name(); properties = properties ? properties : {}; var test_obj = new Test(test_name, properties); + test_obj.step(enforce_https, test_obj, test_obj); if (func) { test_obj.step(func, test_obj, test_obj); }