Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bhawesh committed Aug 31, 2020
1 parent b1299ba commit 41f64c0
Showing 1 changed file with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class SVGTest extends TestBase {
});
}

@Test public void testSVGRenderingWithMask() {
@Test public void testSVGRectRenderingWithMask() {
loadContent(
"<html>\n" +
" <body style='margin: 0px 0px;'>\n" +
Expand Down Expand Up @@ -180,4 +180,75 @@ public class SVGTest extends TestBase {
assertTrue("Color should be red:" + pixelAt199x199, isColorsSimilar(Color.RED, pixelAt199x199, 5));
});
}

@Test public void testSVGRoundedRectRenderingWithMask() {
loadContent(
"<html>\n" +
" <body style='margin: 0px 0px;'>\n" +
" <svg width='200' height='200'>\n" +
" <defs>\n" +
" <linearGradient id='Gradient'>\n" +
" <stop offset='0' stop-color='white' stop-opacity='0' />\n" +
" <stop offset='1' stop-color='white' stop-opacity='1' />\n" +
" </linearGradient>\n" +
" <mask id='Mask'>\n" +
" <rect x='0' y='0' width='200' height='200' fill='url(#Gradient)' />\n" +
" </mask>\n" +
" </defs>\n" +
" <rect x='0' y='0' width='200' height='200' rx='20' ry='20' fill='green' />\n" +
" <rect x='0' y='0' width='200' height='200' rx='20' ry='20' fill='red' mask='url(#Mask)' />\n" +
" </svg>\n" +
" </body>\n" +
"</html>"
);
submit(() -> {
final WebPage webPage = WebEngineShim.getPage(getEngine());
assertNotNull(webPage);
final BufferedImage img = WebPageShim.paint(webPage, 0, 0, 200, 200);
assertNotNull(img);

final Color pixelAt50x50 = new Color(img.getRGB(50, 50), true);
assertTrue("Color should be green:" + pixelAt50x50, isColorsSimilar(new Color(65, 95, 0), pixelAt50x50, 5));
final Color pixelAt50x150 = new Color(img.getRGB(50, 150), true);
assertTrue("Color should be green:" + pixelAt50x150, isColorsSimilar(new Color(65, 95, 0), pixelAt50x150, 5));

final Color pixelAt150x50 = new Color(img.getRGB(150, 50), true);
assertTrue("Color should be almost red:" + pixelAt150x50, isColorsSimilar(new Color(192, 32, 0), pixelAt150x50, 20));
final Color pixelAt150x150 = new Color(img.getRGB(150, 150), true);
assertTrue("Color should be almost red:" + pixelAt150x150, isColorsSimilar(new Color(192, 32, 0), pixelAt150x150, 20));
});
}

@Test public void testSVGPathRenderingWithMask() {
loadContent(
"<html>\n" +
" <body style='margin: 0px 0px;'>\n" +
" <svg width='200' height='200'>\n" +
" <defs>\n" +
" <linearGradient id='Gradient'>\n" +
" <stop offset='0' stop-color='white' stop-opacity='0' />\n" +
" <stop offset='1' stop-color='white' stop-opacity='1' />\n" +
" </linearGradient>\n" +
" <mask id='Mask'>\n" +
" <rect x='0' y='0' width='200' height='200' fill='url(#Gradient)' />\n" +
" </mask>\n" +
" </defs>\n" +
" <path d='M 0 200 Q 100 0 200 200' fill='green' />\n" +
" <path d='M 0 200 Q 100 0 200 200' fill='red' mask='url(#Mask)' />\n" +
" </svg>\n" +
" </body>\n" +
"</html>"
);
submit(() -> {
final WebPage webPage = WebEngineShim.getPage(getEngine());
assertNotNull(webPage);
final BufferedImage img = WebPageShim.paint(webPage, 0, 0, 200, 200);
assertNotNull(img);

final Color pixelAt150x50 = new Color(img.getRGB(150, 50), true);
assertTrue("Color should be almost red:" + pixelAt150x50, isColorsSimilar(new Color(192, 32, 0), pixelAt150x50, 20));
final Color pixelAt150x150 = new Color(img.getRGB(150, 150), true);
assertTrue("Color should be almost red:" + pixelAt150x150, isColorsSimilar(new Color(192, 32, 0), pixelAt150x150, 20));
});
}
}

0 comments on commit 41f64c0

Please sign in to comment.