package render import ( "image" "image/color" "image/draw" "strings" "testing" ) // fixtureImage is a capture as the fixture page paints it, with the // block in colour c. func fixtureImage(w, h int, c color.Color) *image.RGBA { img := image.NewRGBA(image.Rect(0, 0, w, h)) draw.Draw(img, img.Bounds(), image.NewUniform(fixtureBackground), image.Point{}, draw.Src) draw.Draw(img, fixtureBlock, image.NewUniform(c), image.Point{}, draw.Src) return img } // A capture passes only as the fixture page paints it at the desktop // viewport: the block in its colour, the rest in the background. func TestFixtureCaptureIsSampled(t *testing.T) { w, h, _ := Desktop.Size() if err := checkFixtureCapture(fixtureImage(w, h, fixtureColour)); err != nil { t.Fatalf("the fixture's own capture refused: %v", err) } blank := image.NewRGBA(image.Rect(0, 0, w, h)) draw.Draw(blank, blank.Bounds(), image.NewUniform(fixtureBackground), image.Point{}, draw.Src) for name, img := range map[string]image.Image{ "no block": blank, "other colour": fixtureImage(w, h, color.RGBA{0x1e, 0x6b, 0x53, 0xff}), "all block": fixtureImage(w, h, fixtureColour).SubImage(fixtureBlock), "smaller": fixtureImage(w-1, h, fixtureColour), "larger": fixtureImage(w, h+1, fixtureColour), } { if checkFixtureCapture(img) == nil { t.Errorf("a capture with %s passed", name) } } } // The page is static: no script, no external load, nothing that could // make two renders differ. func TestFixturePageIsStatic(t *testing.T) { for _, banned := range []string{"