Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,44 @@
name: ${{ steps.artifact.outputs.filename }}
path: ./build/distributions/content/*/*

# Run Playwright UI tests
ui-test:
name: UI Tests
needs: [ build ]
runs-on: ubuntu-latest
steps:

- name: Fetch Sources
uses: actions/checkout@v6

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
cache-dependency-path: ui/package-lock.json

- name: Install dependencies
run: npm ci
working-directory: ui

- name: Install Playwright browsers
run: npx playwright install chromium --with-deps
working-directory: ui

- name: Run Playwright tests
run: npx playwright test
working-directory: ui

- name: Upload Playwright report
if: ${{ failure() }}
uses: actions/upload-artifact@v6
with:
name: playwright-report
path: ui/playwright-report/

# Run tests and upload a code coverage report
test:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
name: Test
needs: [ build ]
runs-on: ubuntu-latest
Expand Down
65 changes: 0 additions & 65 deletions .github/workflows/run-ui-tests.yml

This file was deleted.

21 changes: 0 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,3 @@ tasks {
gradleVersion = providers.gradleProperty("gradleVersion").get()
}
}

intellijPlatformTesting {
runIde {
register("runIdeForUiTests") {
task {
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"-Drobot-server.port=8082",
"-Dide.mac.message.dialogs.as.sheets=false",
"-Djb.privacy.policy.text=<!--999.999-->",
"-Djb.consents.confirmation.enabled=false",
)
}
}

plugins {
robotServerPlugin()
}
}
}
}
42 changes: 21 additions & 21 deletions src/main/kotlin/dev/twango/jetplay/browser/PlayerHtmlLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ class PlayerHtmlLoader(private val bridge: PlayerBridge) {
PlayerHtmlLoader::class.java.getResource("/player/index.html")?.readText()
?: error("Player UI not found — run 'npm run build' in the ui/ directory")
}

internal fun buildConfigScript(config: PlayerConfig, openLinkJs: String): String = buildString {
append("<script>")
append("window.jetplayOpenLink = function(url) { $openLinkJs };")
append("window.jetplay = {")
append("state: '${config.state}',")
append("isVideo: ${config.isVideo},")
append("fileName: '${PlayerBridge.escapeJs(config.fileName)}',")
append("fileExtension: '${PlayerBridge.escapeJs(config.fileExtension)}',")
config.mediaUrl?.let { append("mediaUrl: '${PlayerBridge.escapeJs(it)}',") }
if (config.errorMessage.isNotEmpty()) append("errorMessage: '${PlayerBridge.escapeJs(config.errorMessage)}',")
if (config.transcodingReason.isNotEmpty()) append("transcodingReason: '${PlayerBridge.escapeJs(config.transcodingReason)}',")
if (config.downloadingReason.isNotEmpty()) append("downloadingReason: '${PlayerBridge.escapeJs(config.downloadingReason)}',")
append("ui: {")
append("downloadingLabel: '${PlayerBridge.escapeJs(config.ui.downloadingLabel)}',")
append("transcodingLabel: '${PlayerBridge.escapeJs(config.ui.transcodingLabel)}',")
append("transcodingTip: '${PlayerBridge.escapeJs(config.ui.transcodingTip)}',")
append("errorTitle: '${PlayerBridge.escapeJs(config.ui.errorTitle)}',")
append("},")
append("};</script>")
}
}

fun load(config: PlayerConfig) {
val openLinkJs = bridge.openLinkQuery.inject("url")
val configScript = buildConfigScript(config, openLinkJs)
bridge.loadHtml(playerHtml.replace("</head>", "$configScript</head>"))
}

private fun buildConfigScript(config: PlayerConfig, openLinkJs: String): String = buildString {
append("<script>")
append("window.jetplayOpenLink = function(url) { $openLinkJs };")
append("window.jetplay = {")
append("state: '${config.state}',")
append("isVideo: ${config.isVideo},")
append("fileName: '${PlayerBridge.escapeJs(config.fileName)}',")
append("fileExtension: '${PlayerBridge.escapeJs(config.fileExtension)}',")
config.mediaUrl?.let { append("mediaUrl: '${PlayerBridge.escapeJs(it)}',") }
if (config.errorMessage.isNotEmpty()) append("errorMessage: '${PlayerBridge.escapeJs(config.errorMessage)}',")
if (config.transcodingReason.isNotEmpty()) append("transcodingReason: '${PlayerBridge.escapeJs(config.transcodingReason)}',")
if (config.downloadingReason.isNotEmpty()) append("downloadingReason: '${PlayerBridge.escapeJs(config.downloadingReason)}',")
append("ui: {")
append("downloadingLabel: '${PlayerBridge.escapeJs(config.ui.downloadingLabel)}',")
append("transcodingLabel: '${PlayerBridge.escapeJs(config.ui.transcodingLabel)}',")
append("transcodingTip: '${PlayerBridge.escapeJs(config.ui.transcodingTip)}',")
append("errorTitle: '${PlayerBridge.escapeJs(config.ui.errorTitle)}',")
append("},")
append("};</script>")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.twango.jetplay.browser

import org.junit.Assert.assertEquals
import org.junit.Test

class PlayerBridgeEscapeTest {

@Test
fun plainStringUnchanged() {
assertEquals("hello world", PlayerBridge.escapeJs("hello world"))
}

@Test
fun backslashEscaped() {
assertEquals("a\\\\b", PlayerBridge.escapeJs("a\\b"))
}

@Test
fun singleQuoteEscaped() {
assertEquals("it\\'s", PlayerBridge.escapeJs("it's"))
}

@Test
fun doubleQuoteEscaped() {
assertEquals("say \\\"hi\\\"", PlayerBridge.escapeJs("say \"hi\""))
}

@Test
fun newlineEscaped() {
assertEquals("line1\\nline2", PlayerBridge.escapeJs("line1\nline2"))
}

@Test
fun carriageReturnRemoved() {
assertEquals("ab", PlayerBridge.escapeJs("a\rb"))
}

@Test
fun angleBracketsEscaped() {
assertEquals("\\x3cscript\\x3e", PlayerBridge.escapeJs("<script>"))
}

@Test
fun combinedSpecialCharacters() {
val input = "it's a <b>\"test\"</b>\nwith\\stuff\r"
val expected = "it\\'s a \\x3cb\\x3e\\\"test\\\"\\x3c/b\\x3e\\nwith\\\\stuff"
assertEquals(expected, PlayerBridge.escapeJs(input))
}

@Test
fun emptyString() {
assertEquals("", PlayerBridge.escapeJs(""))
}
}
93 changes: 93 additions & 0 deletions src/test/kotlin/dev/twango/jetplay/browser/PlayerHtmlLoaderTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package dev.twango.jetplay.browser

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class PlayerHtmlLoaderTest {

private fun buildScript(config: PlayerConfig, openLinkJs: String = ""): String =
PlayerHtmlLoader.buildConfigScript(config, openLinkJs)

@Test
fun wrapsInScriptTags() {
val result = buildScript(PlayerConfig())
assertTrue(result.startsWith("<script>"))
assertTrue(result.endsWith("</script>"))
}

@Test
fun containsState() {
val result = buildScript(PlayerConfig(state = "loading"))
assertTrue(result.contains("state: 'loading'"))
}

@Test
fun containsFileName() {
val result = buildScript(PlayerConfig(fileName = "my-track"))
assertTrue(result.contains("fileName: 'my-track'"))
}

@Test
fun containsIsVideo() {
val resultTrue = buildScript(PlayerConfig(isVideo = true))
assertTrue(resultTrue.contains("isVideo: true"))

val resultFalse = buildScript(PlayerConfig(isVideo = false))
assertTrue(resultFalse.contains("isVideo: false"))
}

@Test
fun includesMediaUrlWhenPresent() {
val result = buildScript(PlayerConfig(mediaUrl = "file:///test.webm"))
assertTrue(result.contains("mediaUrl: 'file:///test.webm'"))
}

@Test
fun omitsMediaUrlWhenNull() {
val result = buildScript(PlayerConfig(mediaUrl = null))
assertFalse(result.contains("mediaUrl:"))
}

@Test
fun escapesSpecialCharsInFileName() {
val result = buildScript(PlayerConfig(fileName = "it's <a> \"test\""))
assertTrue(result.contains("fileName: 'it\\'s \\x3ca\\x3e \\\"test\\\"'"))
}

@Test
fun includesErrorMessageWhenNotEmpty() {
val result = buildScript(PlayerConfig(errorMessage = "Something broke"))
assertTrue(result.contains("errorMessage: 'Something broke'"))
}

@Test
fun omitsErrorMessageWhenEmpty() {
val result = buildScript(PlayerConfig(errorMessage = ""))
assertFalse(result.contains("errorMessage:"))
}

@Test
fun includesUiStrings() {
val result = buildScript(
PlayerConfig(
ui = UiStrings(
downloadingLabel = "Loading...",
transcodingLabel = "Converting...",
transcodingTip = "Use webm",
errorTitle = "Error!",
),
),
)
assertTrue(result.contains("downloadingLabel: 'Loading...'"))
assertTrue(result.contains("transcodingLabel: 'Converting...'"))
assertTrue(result.contains("transcodingTip: 'Use webm'"))
assertTrue(result.contains("errorTitle: 'Error!'"))
}

@Test
fun includesOpenLinkJs() {
val result = buildScript(PlayerConfig(), openLinkJs = "console.log(url)")
assertTrue(result.contains("window.jetplayOpenLink = function(url) { console.log(url) }"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ class MediaFileEditorProviderTest : BasePlatformTestCase() {
assertFalse(provider.accept(project, file))
}

fun testAcceptsMkv() {
val file = myFixture.addFileToProject("test.mkv", "").virtualFile
assertTrue(provider.accept(project, file))
}

fun testAcceptsAvi() {
val file = myFixture.addFileToProject("test.avi", "").virtualFile
assertTrue(provider.accept(project, file))
}

fun testAcceptsMov() {
val file = myFixture.addFileToProject("test.mov", "").virtualFile
assertTrue(provider.accept(project, file))
}

fun testAcceptsFlac() {
val file = myFixture.addFileToProject("test.flac", "").virtualFile
assertTrue(provider.accept(project, file))
}

fun testAcceptsAac() {
val file = myFixture.addFileToProject("test.aac", "").virtualFile
assertTrue(provider.accept(project, file))
}

fun testAcceptsOpus() {
val file = myFixture.addFileToProject("test.opus", "").virtualFile
assertTrue(provider.accept(project, file))
}

fun testRejectsPng() {
val file = myFixture.addFileToProject("test.png", "").virtualFile
assertFalse(provider.accept(project, file))
}

fun testRejectsJson() {
val file = myFixture.addFileToProject("test.json", "").virtualFile
assertFalse(provider.accept(project, file))
}

fun testEditorTypeId() {
assertEquals("media-player", provider.editorTypeId)
}
Expand Down
4 changes: 4 additions & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Playwright
playwright-report/
test-results/
Loading
Loading