Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

2.8 KB
Raw Blame
package opensuite.dashboard;

import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.awt.Dimension;
import java.awt.image.BufferedImage;

/** The size a page's picture is shown at in the Live crawl view, and how it is shrunk to it. */
public final class PageImageTest {

    public void run() {
        Harness.suite("page image");

        Harness.test("a page fills the width there is, and is never blown up", () -> {
            // A page 1366 points across, sent with two dots to the point.
            Dimension fill = PageImage.fitSize(2732, 1536, 1366, 1492, 1.0);
            Expect.equal(fill.width, 1492, "it fills the width, a little larger than it is");
            Expect.equal(fill.height, 839, "and keeps its shape, running on below if it must");
            Dimension tight = PageImage.fitSize(2732, 1536, 1366, 1000, 1.0);
            Expect.equal(tight.width, 1000, "in less room it is shrunk to fit across");
            Expect.equal(tight.height, 562, "and keeps its shape");
            Dimension wide = PageImage.fitSize(2732, 1536, 1366, 2600, 1.0);
            Expect.equal(wide.width, 1708, "in a very wide view it stops at a quarter larger than it is");
            Dimension dense = PageImage.fitSize(2732, 1536, 1366, 4000, 2.0);
            Expect.equal(dense.width, 2732, "on a screen of two dots to the point it uses every dot it has, and no more");
            Dimension plain = PageImage.fitSize(800, 600, 0, 4000, 1.0);
            Expect.equal(plain.width, 800, "a picture of unknown scale is never enlarged");
        });

        Harness.test("shrinking averages the dots under each one shown", () -> {
            BufferedImage src = new BufferedImage(4, 2, BufferedImage.TYPE_INT_RGB);
            int[] row = {0x000000, 0xFFFFFF, 0xFF0000, 0xFF0000};
            for (int y = 0; y < 2; y++) for (int x = 0; x < 4; x++) src.setRGB(x, y, row[x]);
            BufferedImage out = PageImage.scaled(src, 2, 1);
            Expect.equal(out.getWidth(), 2, "width");
            Expect.equal(out.getHeight(), 1, "height");
            Expect.equal(out.getRGB(0, 0) & 0xFFFFFF, 0x7F7F7F, "black and white make grey");
            Expect.equal(out.getRGB(1, 0) & 0xFFFFFF, 0xFF0000, "red stays red");
            Expect.isTrue(PageImage.scaled(src, 4, 2) == src, "the same size is the same picture");
        });

        Harness.test("a page stays on show long enough to be read", () -> {
            Expect.isTrue(CrawlGraph.held("http://a/1", "http://a/1", 1000, 1100), "the same page: its picture keeps up");
            Expect.isTrue(!CrawlGraph.held("http://a/1", "http://a/2", 1000, 1100), "another page waits its turn");
            Expect.isTrue(CrawlGraph.held("http://a/1", "http://a/2", 1000, 1000 + CrawlGraph.HOLD_MS), "and is shown once the first has had its time");
        });
    }
}