|
| 1 | +import { assert, test, testGroup } from "test/test_helper" |
| 2 | +import { installDefaultCSSForTagName, makeElement } from "trix/core/helpers" |
| 3 | + |
| 4 | +let meta = null |
| 5 | + |
| 6 | +const insertMeta = (attributes) => { |
| 7 | + meta = makeElement("meta", attributes) |
| 8 | + document.head.append(meta) |
| 9 | +} |
| 10 | + |
| 11 | +const installDefaultCSS = (tagName, css) => { |
| 12 | + installDefaultCSSForTagName(tagName, css) |
| 13 | + |
| 14 | + return document.querySelector(`style[data-tag-name=${tagName}]`) |
| 15 | +} |
| 16 | + |
| 17 | +const teardown = () => meta.remove() |
| 18 | + |
| 19 | +testGroup("Helpers: Custom Elements", { teardown }, () => { |
| 20 | + test("reads from meta[name=csp-nonce][content]", () => { |
| 21 | + insertMeta({ name: "csp-nonce", content: "abc123" }) |
| 22 | + |
| 23 | + const style = installDefaultCSS("trix-element", "trix-element { display: block; }") |
| 24 | + |
| 25 | + assert.equal(style.getAttribute("nonce"), "abc123") |
| 26 | + assert.equal(style.innerHTML, "trix-element { display: block; }") |
| 27 | + }) |
| 28 | + |
| 29 | + test("reads from meta[name=trix-csp-nonce][content]", () => { |
| 30 | + insertMeta({ name: "trix-csp-nonce", content: "abc123" }) |
| 31 | + |
| 32 | + const style = installDefaultCSS("trix-element", "trix-element { display: block; }") |
| 33 | + |
| 34 | + assert.equal(style.getAttribute("nonce"), "abc123") |
| 35 | + assert.equal(style.innerHTML, "trix-element { display: block; }") |
| 36 | + }) |
| 37 | + |
| 38 | + test("reads from meta[name=csp-nonce][nonce]", () => { |
| 39 | + insertMeta({ name: "csp-nonce", nonce: "abc123" }) |
| 40 | + |
| 41 | + const style = installDefaultCSS("trix-element", "trix-element { display: block; }") |
| 42 | + |
| 43 | + assert.equal(style.getAttribute("nonce"), "abc123") |
| 44 | + assert.equal(style.innerHTML, "trix-element { display: block; }") |
| 45 | + }) |
| 46 | + |
| 47 | + test("reads from meta[name=trix-csp-nonce][nonce]", () => { |
| 48 | + insertMeta({ name: "trix-csp-nonce", nonce: "abc123" }) |
| 49 | + |
| 50 | + const style = installDefaultCSS("trix-element", "trix-element { display: block; }") |
| 51 | + |
| 52 | + assert.equal(style.getAttribute("nonce"), "abc123") |
| 53 | + assert.equal(style.innerHTML, "trix-element { display: block; }") |
| 54 | + }) |
| 55 | +}) |
0 commit comments