From 4410ddcd840388707ebfd89cff4abd4486cd519a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 13:39:23 +0200 Subject: [PATCH] adding tests for UiHelper.reloadHome, making UiHelper unit testable and handling JSVerify RNG states 846932d5afb10ce748 & 012c1f9483adb6e750 --- js/privatebin.js | 6 ++---- js/test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 3db3fae4..74db28c9 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -845,11 +845,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { * everything directly UI-related, which fits nowhere else * * @name UiHelper - * @param {object} window - * @param {object} document * @class */ - var UiHelper = (function (window, document) { + var UiHelper = (function () { var me = {}; /** @@ -990,7 +988,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { } return me; - })(window, document); + })(); /** * Alert/error manager diff --git a/js/test.js b/js/test.js index 6ac42102..e14cdde5 100644 --- a/js/test.js +++ b/js/test.js @@ -803,8 +803,8 @@ describe('Model', function () { element = element.join(''); value = value.join('').trim(); - //
tags can't contain strings, so test with a

instead - if (element == 'br') { + //
tags can't contain strings, table tags can't be alone, so test with a

instead + if (['br', 'tr', 'td', 'th'].indexOf(element) >= 0) { element = 'p'; } @@ -840,7 +840,13 @@ describe('UiHelper', function () { var expected = schema + '://' + address.join('') + '/', clean = jsdom('', {url: expected}); + // make window.location.href writable + Object.defineProperty(window.location, 'href', { + writable: true, + value: window.location.href + }); $.PrivateBin.UiHelper.mockHistoryChange(); + $.PrivateBin.Helper.reset(); var result = window.location.href; clean(); return expected === result; @@ -857,7 +863,43 @@ describe('UiHelper', function () { var expected = schema + '://' + address.join('') + '/' + '?' + query.join('') + '#' + fragment.join(''), clean = jsdom('', {url: expected}); + // make window.location.href writable + Object.defineProperty(window.location, 'href', { + writable: true, + value: window.location.href + }); $.PrivateBin.UiHelper.mockHistoryChange([{type: 'newpaste'}, '', expected]); + $.PrivateBin.Helper.reset(); + var result = window.location.href; + clean(); + return expected === result; + } + ); + }); + + describe('reloadHome', function () { + this.timeout(30000); + before(function () { + $.PrivateBin.Helper.reset(); + }); + + jsc.property( + 'redirects to home', + jsc.elements(schemas), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + jsc.nearray(jsc.elements(base64String)), + function (schema, address, query, fragment) { + var expected = schema + '://' + address.join('') + '/', + clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment.join('')}); + + // make window.location.href writable + Object.defineProperty(window.location, 'href', { + writable: true, + value: window.location.href + }); + $.PrivateBin.UiHelper.reloadHome(); + $.PrivateBin.Helper.reset(); var result = window.location.href; clean(); return expected === result; diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 4fbd6c02..609ccb73 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 2fa90ce6..8b8fcad6 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - +