rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use super::visible_box;
use pretty_assertions::assert_eq;
use rho_browser::tab::Viewport;
use rho_protocol::BrowserRect;

const VIEWPORT: Viewport = Viewport {
    width: 100,
    height: 50,
};

/// A rectangle's quad: its corners clockwise from the top left.
fn rect(left: f64, top: f64, right: f64, bottom: f64) -> [f64; 8] {
    [left, top, right, top, right, bottom, left, bottom]
}

/// A case's name, its quads, and the point a click lands on with the box
/// a client outlines.
type Case = (
    &'static str,
    Vec<[f64; 8]>,
    Option<((f64, f64), BrowserRect)>,
);

// Covers: a click by ref lands on the center of the part of the element's
// box inside the viewport, and that part, rounded out to whole pixels, is
// the box a client outlines; an element with no part a pixel each way in
// the viewport has neither. Otherwise a click lands off the element, or
// the outline is off its box or past the frame.
// Owner: browser page actions
#[test]
fn a_click_lands_on_and_outlines_the_part_of_the_box_in_the_viewport() {
    let cases: [Case; 7] = [
        (
            "inside",
            vec![rect(10.0, 10.0, 30.0, 20.0)],
            Some(((20.0, 15.0), BrowserRect::new(10, 10, 20, 10))),
        ),
        (
            "at fractional pixels",
            vec![rect(10.5, 20.25, 30.5, 25.75)],
            Some(((20.5, 23.0), BrowserRect::new(10, 20, 21, 6))),
        ),
        (
            "partly off the right and bottom",
            vec![rect(80.0, 40.0, 120.0, 60.0)],
            Some(((90.0, 45.0), BrowserRect::new(80, 40, 20, 10))),
        ),
        (
            "partly off the left and top",
            vec![rect(-20.0, -10.0, 10.0, 10.0)],
            Some(((5.0, 5.0), BrowserRect::new(0, 0, 10, 10))),
        ),
        ("wholly below", vec![rect(10.0, 60.0, 30.0, 70.0)], None),
        (
            "under a pixel wide",
            vec![rect(10.0, 10.0, 10.5, 20.0)],
            None,
        ),
        (
            "the first quad that shows, of a wrapped inline",
            vec![rect(10.0, -20.0, 30.0, -10.0), rect(0.0, 0.0, 20.0, 10.0)],
            Some(((10.0, 5.0), BrowserRect::new(0, 0, 20, 10))),
        ),
    ];
    for (case, quads, expected) in cases {
        let drawn = visible_box(&quads, VIEWPORT).map(|drawn| (drawn.center(), drawn.rect()));
        assert_eq!(drawn, expected, "{case}");
    }
}