Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

4.4 KB
Raw Blame
import CoreGraphics
import CraCore
import Foundation
import Testing

/// Arc's Picture in Picture window: where it opens and what its top bar shows (#246).
struct PictureInPictureLayoutTests {
    @Test(arguments: [("https://www.youtube.com/watch?v=x", "www.youtube.com"), ("http://127.0.0.1:8080/video.html", "127.0.0.1"),
                      ("file:///Users/me/clip.mp4", "File on your device"), ("about:blank", "")])
    func addressIsTheHost(url: String, address: String) {
        #expect(PictureInPictureLayout.address(of: url) == address)
    }

    /// Back to tab on the left, close on the right (Cra had them the other way round), the
    /// address centred on the window between them and clear of both.
    @Test(.bug("https://github.com/VictorKildahl/cra/issues/246"))
    func topBarIsArcs() {
        let bar = PictureInPictureLayout.topBar(width: 223, buttonSize: 26, addressWidth: 85)
        #expect(bar.back == CGRect(x: 13, y: 13, width: 26, height: 26))
        #expect(bar.close == CGRect(x: 184, y: 13, width: 26, height: 26))
        let a = try! #require(bar.address)
        #expect(a.midX == 111.5 && a.midY == 26 && a.width == 85)
        #expect(a.minX >= bar.back.maxX + 8 && a.maxX <= bar.close.minX - 8)
    }

    @Test func longAddressIsCutToTheRoomAndDroppedWithoutRoom() {
        let bar = PictureInPictureLayout.topBar(width: 223, buttonSize: 26, addressWidth: 400)
        #expect(bar.address?.width == 2 * (111.5 - 39 - 8))
        #expect(PictureInPictureLayout.topBar(width: 110, buttonSize: 26, addressWidth: 85).address == nil)
        #expect(PictureInPictureLayout.topBar(width: 223, buttonSize: 26, addressWidth: 0).address == nil)
    }

    /// Arc's size classes: buttons 12 pt + 8 pt padding in below 280 pt, 16 + 8 below 400, 16 + 10
    /// from there, where Back to Tab also shows its words.
    @Test func controlsMoveInWithTheWindowsSize() {
        #expect([223, 279, 280, 399, 400, 801].map { PictureInPictureLayout.buttonCentreInset(width: $0) } == [26, 26, 30, 30, 32, 32])
        #expect(!PictureInPictureLayout.labelsBackToTab(width: 399) && PictureInPictureLayout.labelsBackToTab(width: 400))
        let bar = PictureInPictureLayout.topBar(width: 801, buttonSize: 26, backWidth: 110, addressWidth: 85)
        #expect(bar.back == CGRect(x: 19, y: 19, width: 110, height: 26))
        #expect(bar.close == CGRect(x: 756, y: 19, width: 26, height: 26))
        #expect(bar.address?.midX == 400.5)
    }

    let screen = CGRect(x: 0, y: 0, width: 1920, height: 1080)
    let visible = CGRect(x: 0, y: 80, width: 1920, height: 975)

    /// Arc's limits: never below 224 × 126 for 16:9 (the 223 × 125.5 window in #246 was Arc's
    /// minimum), at most 61.7 % of the screen's width and the visible height less 20.
    @Test(.bug("https://github.com/VictorKildahl/cra/issues/246"))
    func sizeStaysInArcsLimits() {
        let l = PictureInPictureLayout.sizeLimits(aspect: 16.0 / 9, screen: screen, visible: visible)
        #expect(l.min == CGSize(width: 224, height: 126))
        #expect(l.max == CGSize(width: 1184, height: 955))
        // Portrait: 224 wide at least, not 126 tall.
        #expect(PictureInPictureLayout.sizeLimits(aspect: 9.0 / 16, screen: screen, visible: visible).min == CGSize(width: 224, height: 398))
        // A remembered frame below the minimum (Cra allowed 160 × 90) opens at Arc's minimum.
        let small = PictureInPictureLayout.initialFrame(aspect: 16.0 / 9, screen: screen, visible: visible,
                                                        remembered: CGRect(x: 100, y: 500, width: 160, height: 90))
        #expect(small == CGRect(x: 100, y: 464, width: 224, height: 126))
        // One wider than the screen allows opens at the widest Arc allows.
        let wide = PictureInPictureLayout.initialFrame(aspect: 16.0 / 9, screen: screen, visible: visible,
                                                       remembered: CGRect(x: 0, y: 100, width: 1600, height: 900))
        #expect(wide.size == CGSize(width: 1184, height: 666))
    }

    @Test func firstOpensTopRightTenPointsIn() {
        let f = PictureInPictureLayout.initialFrame(aspect: 16.0 / 9, screen: CGRect(x: 0, y: 0, width: 1728, height: 1117),
                                                    visible: CGRect(x: 0, y: 0, width: 1728, height: 1084), remembered: nil)
        #expect(f == CGRect(x: 1728 - 10 - 782, y: 1084 - 10 - 440, width: 782, height: 440))
    }
}