forked from hotwired/turbo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from github/fletchto99/fix-trusted-types-for-sc…
…ript-src Fix trusted types for when a script is created from source
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./export_tests" | ||
export * from "./deprecated_adapter_support_test" | ||
export * from "./stream_element_tests" | ||
export * from "./util_tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as Turbo from "../../index" | ||
import { DOMTestCase } from "../helpers/dom_test_case" | ||
import { activateScriptElement } from "../../util" | ||
|
||
export class UtilTests extends DOMTestCase { | ||
async setup() { | ||
Turbo.setCSPTrustedTypesPolicy({ | ||
createHTML: (_) => "bar", | ||
createScript: (_) => "bar", | ||
createScriptURL: (_) => "https://bar/", | ||
}) | ||
} | ||
|
||
async teardown() { | ||
Turbo.setCSPTrustedTypesPolicy(null) | ||
} | ||
|
||
async "test TrustedTypes activates a script with source code"() { | ||
const element = document.createElement("script") | ||
element.textContent = "foo" | ||
|
||
const activatedElement = activateScriptElement(element) | ||
this.assert.equal(activatedElement.textContent, "bar") | ||
} | ||
|
||
async "test TyrustedTypes activates a script with source url"() { | ||
const element = document.createElement("script") | ||
element.src = "https://foo/" | ||
|
||
const activatedElement = activateScriptElement(element) | ||
this.assert.equal(activatedElement.src, "https://bar/") | ||
} | ||
|
||
async "test activates a script with source code"() { | ||
Turbo.setCSPTrustedTypesPolicy(null) | ||
const element = document.createElement("script") | ||
element.textContent = "foo" | ||
|
||
const activatedElement = activateScriptElement(element) | ||
this.assert.equal(activatedElement.textContent, "foo") | ||
} | ||
|
||
async "test activates a script with source url"() { | ||
Turbo.setCSPTrustedTypesPolicy(null) | ||
const element = document.createElement("script") | ||
element.src = "https://foo/" | ||
|
||
const activatedElement = activateScriptElement(element) | ||
this.assert.equal(activatedElement.src, "https://foo/") | ||
} | ||
} | ||
|
||
UtilTests.registerSuite() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters