Skip to content

Commit 620ef5c

Browse files
jelhanKrinkle
authored andcommitted
HTML Reporter: Avoid inline styles to support CSP without 'unsafe-inline'
Using `style` attribute in parsed HTML requires Content-Security-Policy (CSP) style-src 'unsafe-inline'. This makes testing that a library or an application does not violate a strict CSP more difficult. Closes #1369.
1 parent 1bea540 commit 620ef5c

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

reporter/html.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,16 @@ export function escapeText( s ) {
350350
}
351351

352352
function toolbarModuleFilter() {
353-
var allCheckbox, commit, reset,
353+
var commit, reset,
354354
moduleFilter = document.createElement( "form" ),
355355
label = document.createElement( "label" ),
356356
moduleSearch = document.createElement( "input" ),
357357
dropDown = document.createElement( "div" ),
358358
actions = document.createElement( "span" ),
359+
applyButton = document.createElement( "button" ),
360+
resetButton = document.createElement( "button" ),
361+
allModulesLabel = document.createElement( "label" ),
362+
allCheckbox = document.createElement( "input" ),
359363
dropDownList = document.createElement( "ul" ),
360364
dirty = false;
361365

@@ -370,15 +374,27 @@ export function escapeText( s ) {
370374
label.innerHTML = "Module: ";
371375
label.appendChild( moduleSearch );
372376

377+
applyButton.textContent = "Apply";
378+
applyButton.style.display = "none";
379+
380+
resetButton.textContent = "Reset";
381+
resetButton.type = "reset";
382+
resetButton.style.display = "none";
383+
384+
allCheckbox.type = "checkbox";
385+
allCheckbox.checked = config.moduleId.length === 0;
386+
387+
allModulesLabel.className = "clickable";
388+
if ( config.moduleId.length ) {
389+
allModulesLabel.className = "checked";
390+
}
391+
allModulesLabel.appendChild( allCheckbox );
392+
allModulesLabel.appendChild( document.createTextNode( "All modules" ) );
393+
373394
actions.id = "qunit-modulefilter-actions";
374-
actions.innerHTML =
375-
"<button style='display:none'>Apply</button>" +
376-
"<button type='reset' style='display:none'>Reset</button>" +
377-
"<label class='clickable" +
378-
( config.moduleId.length ? "" : " checked" ) +
379-
"'><input type='checkbox'" + ( config.moduleId.length ? "" : " checked='checked'" ) +
380-
" />All modules</label>";
381-
allCheckbox = actions.lastChild.firstChild;
395+
actions.appendChild( applyButton );
396+
actions.appendChild( resetButton );
397+
actions.appendChild( allModulesLabel );
382398
commit = actions.firstChild;
383399
reset = commit.nextSibling;
384400
addEvent( commit, "click", applyUrlParams );

0 commit comments

Comments
 (0)