Skip to content

Commit

Permalink
HTML Reporter: Avoid inline styles to support CSP without 'unsafe-inl…
Browse files Browse the repository at this point in the history
…ine'

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.
  • Loading branch information
jelhan authored and Krinkle committed Feb 18, 2019
1 parent 1bea540 commit 620ef5c
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions reporter/html.js
Expand Up @@ -350,12 +350,16 @@ export function escapeText( s ) {
}

function toolbarModuleFilter() {
var allCheckbox, commit, reset,
var commit, reset,
moduleFilter = document.createElement( "form" ),
label = document.createElement( "label" ),
moduleSearch = document.createElement( "input" ),
dropDown = document.createElement( "div" ),
actions = document.createElement( "span" ),
applyButton = document.createElement( "button" ),
resetButton = document.createElement( "button" ),
allModulesLabel = document.createElement( "label" ),
allCheckbox = document.createElement( "input" ),
dropDownList = document.createElement( "ul" ),
dirty = false;

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

applyButton.textContent = "Apply";
applyButton.style.display = "none";

resetButton.textContent = "Reset";
resetButton.type = "reset";
resetButton.style.display = "none";

allCheckbox.type = "checkbox";
allCheckbox.checked = config.moduleId.length === 0;

allModulesLabel.className = "clickable";
if ( config.moduleId.length ) {
allModulesLabel.className = "checked";
}
allModulesLabel.appendChild( allCheckbox );
allModulesLabel.appendChild( document.createTextNode( "All modules" ) );

actions.id = "qunit-modulefilter-actions";
actions.innerHTML =
"<button style='display:none'>Apply</button>" +
"<button type='reset' style='display:none'>Reset</button>" +
"<label class='clickable" +
( config.moduleId.length ? "" : " checked" ) +
"'><input type='checkbox'" + ( config.moduleId.length ? "" : " checked='checked'" ) +
" />All modules</label>";
allCheckbox = actions.lastChild.firstChild;
actions.appendChild( applyButton );
actions.appendChild( resetButton );
actions.appendChild( allModulesLabel );
commit = actions.firstChild;
reset = commit.nextSibling;
addEvent( commit, "click", applyUrlParams );
Expand Down

0 comments on commit 620ef5c

Please sign in to comment.