1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package test.css.controls.style.size; 26 27 import javafx.scene.Node; 28 import javafx.scene.Scene; 29 import javafx.scene.control.Control; 30 import javafx.scene.layout.Region; 31 import org.jemmy.control.Wrap; 32 import org.jemmy.fx.ByID; 33 import org.jemmy.fx.Root; 34 import org.jemmy.image.Image; 35 import org.jemmy.image.pixel.Raster; 36 import org.jemmy.image.pixel.RasterComparator; 37 import org.jemmy.interfaces.Parent; 38 import org.jemmy.timing.State; 39 import org.junit.Assert; 40 import org.junit.Before; 41 import org.junit.Test; 42 import test.css.controls.api.SizeStyleApp; 43 import test.javaclient.shared.TestBase; 44 import test.javaclient.shared.screenshots.ImagesManager; 45 import test.javaclient.shared.screenshots.ScreenshotUtils; 46 47 /** 48 * 49 * @author sergey.lugovoy@oracle.com 50 */ 51 abstract public class SizeStyleBaseTest extends TestBase { 52 53 protected Wrap<? extends Region> golden_control; 54 protected Wrap<? extends Region> control; 55 protected Wrap<? extends Scene> sceneWrap; 56 57 abstract String getPageName(); 58 59 @Before 60 public void clean() { 61 sceneWrap = null; 62 control = null; 63 golden_control = null; 64 } 65 66 /** 67 * Compare two Controls, first with set API,second with set stylesheet style 68 * "-fx-min-width" 69 */ 70 @Test 71 public void minWidthTest() { 72 testCommon(getPageName(), SizeStyleApp.SizePages.MIN_WIDTH.toString(), false, false); 73 lookupControls(); 74 checkMinWidth(); 75 checkScreenShots(SizeStyleApp.SizePages.MIN_WIDTH.toString()); 76 } 77 78 /** 79 * Compare two Controls, first with set API,second with set stylesheet style 80 * "-fx-min-height" 81 */ 82 @Test 83 public void minHeightTest() { 84 testCommon(getPageName(), SizeStyleApp.SizePages.MIN_HEIGHT.toString(), false, false); 85 lookupControls(); 86 checkMinHeight(); 87 checkScreenShots(SizeStyleApp.SizePages.MIN_HEIGHT.toString()); 88 } 89 90 /** 91 * Compare two Controls, first with set API,second with set stylesheet style 92 * "-fx-max-height" 93 */ 94 @Test 95 public void maxHeightTest() { 96 testCommon(getPageName(), SizeStyleApp.SizePages.MAX_HEIGHT.toString(), false, false); 97 lookupControls(); 98 checkMaxHeight(); 99 checkScreenShots(SizeStyleApp.SizePages.MAX_HEIGHT.toString()); 100 } 101 102 /** 103 * Compare two Controls, first with set API,second with set stylesheet style 104 * "-fx-max-width" 105 */ 106 @Test 107 public void maxWidthTest() { 108 testCommon(getPageName(), SizeStyleApp.SizePages.MAX_WIDTH.toString(), false, false); 109 lookupControls(); 110 checkMaxWidth(); 111 checkScreenShots(SizeStyleApp.SizePages.MAX_WIDTH.toString()); 112 } 113 114 /** 115 * Compare two Controls, first with set API,second with set stylesheet style 116 * "-fx-pref-width" 117 */ 118 @Test 119 public void prefWidthTest() { 120 testCommon(getPageName(), SizeStyleApp.SizePages.PREF_WIDTH.toString(), false, false); 121 lookupControls(); 122 checkPrefWidth(); 123 checkScreenShots(SizeStyleApp.SizePages.PREF_WIDTH.toString()); 124 } 125 126 /** 127 * Compare two Controls, first with set API,second with set stylesheet style 128 * "-fx-pref-height" 129 */ 130 @Test 131 public void prefHeightTest() { 132 testCommon(getPageName(), SizeStyleApp.SizePages.PREF_HEIGHT.toString(), false, false); 133 lookupControls(); 134 checkPrefHeight(); 135 checkScreenShots(SizeStyleApp.SizePages.PREF_HEIGHT.toString()); 136 } 137 138 public void lookupControls() { 139 sceneWrap = Root.ROOT.lookup(Scene.class).wrap(); 140 control = sceneWrap.as(Parent.class, Node.class).lookup(Region.class, new ByID(SizeStyleApp.CONTROL_ID)).wrap(); 141 golden_control = sceneWrap.as(Parent.class, Node.class).lookup(Region.class, new ByID(SizeStyleApp.GOLDEN_CONTROL_ID)).wrap(); 142 } 143 144 public void checkMinWidth() { 145 Assert.assertNotNull(control); 146 Assert.assertNotNull(golden_control); 147 Assert.assertEquals(control.getControl().getMinWidth(), golden_control.getControl().getMinWidth(), 0.0); 148 } 149 150 public void checkMinHeight() { 151 Assert.assertNotNull(control); 152 Assert.assertNotNull(golden_control); 153 Assert.assertEquals(control.getControl().getMinHeight(), golden_control.getControl().getMinHeight(), 0.0); 154 } 155 156 public void checkPrefWidth() { 157 Assert.assertNotNull(control); 158 Assert.assertNotNull(golden_control); 159 Assert.assertEquals(control.getControl().getPrefWidth(), golden_control.getControl().getPrefWidth(), 0.0); 160 } 161 162 public void checkPrefHeight() { 163 Assert.assertNotNull(control); 164 Assert.assertNotNull(golden_control); 165 Assert.assertEquals(control.getControl().getPrefHeight(), golden_control.getControl().getPrefHeight(), 0.0); 166 } 167 168 public void checkMaxWidth() { 169 Assert.assertNotNull(control); 170 Assert.assertNotNull(golden_control); 171 Assert.assertEquals(control.getControl().getMaxWidth(), golden_control.getControl().getMaxWidth(), 0.0); 172 } 173 174 public void checkMaxHeight() { 175 Assert.assertNotNull(control); 176 Assert.assertNotNull(golden_control); 177 Assert.assertEquals(control.getControl().getMaxHeight(), golden_control.getControl().getMaxHeight(), 0.0); 178 } 179 180 public void checkScreenShots(final String testName) { 181 control.waitState(new State<Boolean>() { 182 public Boolean reached() { 183 Image testedImage = control.getScreenImage(); 184 Image goldenImage = golden_control.getScreenImage(); 185 RasterComparator comparator = sceneWrap.getEnvironment().getProperty(RasterComparator.class); 186 if (comparator.compare((Raster) testedImage, (Raster) goldenImage)) { 187 return true; 188 } 189 else { 190 String cssStyleImage = ImagesManager.getInstance().getScreenshotPath(getPageName() + testName + "_css"); 191 String apiImage = ImagesManager.getInstance().getScreenshotPath(getPageName() + testName + "_api"); 192 String diffPath = ImagesManager.getInstance().getScreenshotPath(getPageName() + testName + "_diff"); 193 testedImage.save(cssStyleImage); 194 goldenImage.save(apiImage); 195 testedImage.compareTo(goldenImage).save(diffPath); 196 } 197 return null; 198 } 199 }); 200 } 201 }