Files
upstream-mirror feda81bf2f
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
snapshot of https://github.com/tauri-apps/tauri.git (dev, 2026-09-23; blobs > 131072B omitted)
2026-09-23 17:00:42 +05:00

296 lines
9.3 KiB
TypeScript

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { expect } from '@wdio/globals'
import {
tauri,
eventually,
describeApi,
itWm,
itDesktop,
itOn
} from '../helpers/index.js'
describeApi('window', () => {
it('getCurrentWindow reports the main label', async () => {
expect(await tauri((api) => api.window.getCurrentWindow().label)).toBe(
'main'
)
})
it('getAllWindows includes the main window', async () => {
const labels = await tauri(async (api) =>
(await api.window.getAllWindows()).map((w) => w.label)
)
expect(labels).toContain('main')
})
// Mobile windows have no title bar: `title()` is always empty and
// `setTitle` a no-op there.
itDesktop('title can be read and set', async () => {
const original = await tauri((api) => api.window.getCurrentWindow().title())
await tauri((api) => api.window.getCurrentWindow().setTitle('e2e title'))
expect(await tauri((api) => api.window.getCurrentWindow().title())).toBe(
'e2e title'
)
// restore
await tauri(
(api, title) => api.window.getCurrentWindow().setTitle(title),
original
)
})
it('reports a positive scale factor and sizes', async () => {
const metrics = await tauri(async (api) => {
const w = api.window.getCurrentWindow()
const scale = await w.scaleFactor()
const inner = await w.innerSize()
const outer = await w.outerSize()
return {
scale,
inner: { width: inner.width, height: inner.height },
outer: { width: outer.width, height: outer.height }
}
})
expect(metrics.scale).toBeGreaterThan(0)
expect(metrics.inner.width).toBeGreaterThan(0)
expect(metrics.inner.height).toBeGreaterThan(0)
expect(metrics.outer.width).toBeGreaterThanOrEqual(metrics.inner.width)
})
itOn(
'android',
'activityName reports the activity hosting the window',
async () => {
const name = await tauri((api) =>
api.window.getCurrentWindow().activityName()
)
expect(name).toMatch(/MainActivity/)
}
)
// The window is the whole screen on mobile: `set_size` is a no-op.
itDesktop('setSize resizes the window', async () => {
const scale = await tauri((api) =>
api.window.getCurrentWindow().scaleFactor()
)
const original = await tauri(async (api) => {
const size = await api.window.getCurrentWindow().innerSize()
return { width: size.width, height: size.height }
})
await tauri(
(api, width, height) =>
api.window
.getCurrentWindow()
.setSize(new api.dpi.LogicalSize(width, height)),
600,
400
)
await eventually(async () => {
const inner = await tauri(async (api) => {
const size = await api.window.getCurrentWindow().innerSize()
return { width: size.width, height: size.height }
})
const tolerance = Math.ceil(scale) * 4
if (Math.abs(inner.width - 600 * scale) > tolerance) {
throw new Error(`width ${inner.width} not near ${600 * scale}`)
}
if (Math.abs(inner.height - 400 * scale) > tolerance) {
throw new Error(`height ${inner.height} not near ${400 * scale}`)
}
})
// restore the original physical size
await tauri(
(api, width, height) =>
api.window
.getCurrentWindow()
.setSize(new api.dpi.PhysicalSize(width, height)),
original.width,
original.height
)
})
// Mobile windows are never resizable (`is_resizable` is always `false`).
itDesktop('setResizable toggles resizability', async () => {
await tauri((api) => api.window.getCurrentWindow().setResizable(false))
expect(
await tauri((api) => api.window.getCurrentWindow().isResizable())
).toBe(false)
await tauri((api) => api.window.getCurrentWindow().setResizable(true))
expect(
await tauri((api) => api.window.getCurrentWindow().isResizable())
).toBe(true)
})
// Desktop-only commands (`#[cfg(desktop)]` in the window plugin).
itDesktop('assorted setters resolve without throwing', async () => {
await tauri(async (api) => {
const w = api.window.getCurrentWindow()
await w.setAlwaysOnTop(true)
await w.setAlwaysOnTop(false)
await w.setShadow(true)
await w.setContentProtected(false)
await w.setCursorVisible(true)
await w.requestUserAttention(null)
return null
})
})
itWm('setPosition moves the window', async () => {
const original = await tauri(async (api) => {
const pos = await api.window.getCurrentWindow().outerPosition()
return { x: pos.x, y: pos.y }
})
await tauri(
(api, x, y) =>
api.window
.getCurrentWindow()
.setPosition(new api.dpi.PhysicalPosition(x, y)),
original.x + 40,
original.y + 40
)
await eventually(async () => {
const pos = await tauri(async (api) => {
const p = await api.window.getCurrentWindow().outerPosition()
return { x: p.x, y: p.y }
})
// Window managers can nudge the final position; allow a generous tolerance.
if (
Math.abs(pos.x - (original.x + 40)) > 30
|| Math.abs(pos.y - (original.y + 40)) > 30
) {
throw new Error(
`position ${pos.x},${pos.y} not near ${original.x + 40},${original.y + 40}`
)
}
})
await tauri(
(api, x, y) =>
api.window
.getCurrentWindow()
.setPosition(new api.dpi.PhysicalPosition(x, y)),
original.x,
original.y
)
})
itWm('minimize and unminimize toggle the minimized state', async () => {
await tauri((api) => api.window.getCurrentWindow().minimize())
await eventually(async () => {
if (
!(await tauri((api) => api.window.getCurrentWindow().isMinimized()))
) {
throw new Error('window is not minimized')
}
})
await tauri((api) => api.window.getCurrentWindow().unminimize())
await eventually(async () => {
if (await tauri((api) => api.window.getCurrentWindow().isMinimized())) {
throw new Error('window is still minimized')
}
})
})
itWm('maximize and unmaximize toggle the maximized state', async () => {
await tauri((api) => api.window.getCurrentWindow().maximize())
await eventually(async () => {
if (
!(await tauri((api) => api.window.getCurrentWindow().isMaximized()))
) {
throw new Error('window is not maximized')
}
})
await tauri((api) => api.window.getCurrentWindow().unmaximize())
await eventually(async () => {
if (await tauri((api) => api.window.getCurrentWindow().isMaximized())) {
throw new Error('window is still maximized')
}
})
})
itWm('setFullscreen toggles fullscreen', async () => {
await tauri((api) => api.window.getCurrentWindow().setFullscreen(true))
await eventually(async () => {
if (
!(await tauri((api) => api.window.getCurrentWindow().isFullscreen()))
) {
throw new Error('window is not fullscreen')
}
})
await tauri((api) => api.window.getCurrentWindow().setFullscreen(false))
await eventually(async () => {
if (await tauri((api) => api.window.getCurrentWindow().isFullscreen())) {
throw new Error('window is still fullscreen')
}
})
})
itWm('setFullscreenOnMonitor goes fullscreen on that monitor', async () => {
// Use the monitor the window is on, so the assertion holds on single-monitor CI.
const origin = await tauri(async (api) => {
const monitor = await api.window.currentMonitor()
return monitor ? { x: monitor.position.x, y: monitor.position.y } : null
})
expect(origin).not.toBeNull()
await tauri(
(api, origin) =>
api.window
.getCurrentWindow()
.setFullscreenOnMonitor(
new api.dpi.PhysicalPosition(origin.x, origin.y)
),
origin!
)
await eventually(async () => {
const state = await tauri(async (api) => {
const w = api.window.getCurrentWindow()
const position = await w.outerPosition()
return {
fullscreen: await w.isFullscreen(),
x: position.x,
y: position.y
}
})
if (!state.fullscreen) {
throw new Error('window is not fullscreen')
}
// a fullscreen window sits at its monitor's origin
if (state.x !== origin!.x || state.y !== origin!.y) {
throw new Error(
`window is at (${state.x}, ${state.y}), expected (${origin!.x}, ${origin!.y})`
)
}
})
await tauri((api) => api.window.getCurrentWindow().setFullscreen(false))
await eventually(async () => {
if (await tauri((api) => api.window.getCurrentWindow().isFullscreen())) {
throw new Error('window is still fullscreen')
}
})
})
itWm('hide and show toggle visibility', async () => {
await tauri((api) => api.window.getCurrentWindow().hide())
await eventually(async () => {
if (await tauri((api) => api.window.getCurrentWindow().isVisible())) {
throw new Error('window is still visible')
}
})
await tauri((api) => api.window.getCurrentWindow().show())
await eventually(async () => {
if (!(await tauri((api) => api.window.getCurrentWindow().isVisible()))) {
throw new Error('window is not visible')
}
})
})
})