/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javafx.scene.control.test.pagination; import com.sun.javafx.scene.control.LabeledText; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import javafx.geometry.Orientation; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.Pagination; import javafx.scene.control.ScrollBar; import javafx.scene.control.TextArea; import static javafx.scene.control.test.pagination.PaginationApp.*; import javafx.scene.control.test.util.UtilTestFunctions; import static javafx.scene.control.test.utils.ComponentsFactory.*; import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType; import javafx.scene.layout.StackPane; import org.jemmy.Point; import org.jemmy.action.GetAction; import org.jemmy.control.Wrap; import org.jemmy.env.Environment; import org.jemmy.fx.ByID; import org.jemmy.fx.Root; import org.jemmy.input.AbstractScroll; import org.jemmy.interfaces.Keyboard.KeyboardButtons; import org.jemmy.interfaces.Parent; import org.jemmy.interfaces.Text; import org.jemmy.lookup.Lookup; import org.jemmy.lookup.LookupCriteria; import org.jemmy.timing.State; import org.junit.After; import static org.junit.Assert.*; import org.junit.Before; import org.junit.BeforeClass; import static test.javaclient.shared.TestUtil.isEmbedded; /** * @author Alexander Kirov */ public class TestBase extends UtilTestFunctions { static Wrap testedControl; static Wrap scene; static Wrap popupScene; protected boolean resetHardByDefault = true;//switcher of hard and soft reset mode. protected boolean doNextResetHard = resetHardByDefault; private final static String leftArrowButtonStyleClass = "left-arrow"; private final static String rightArrowButtonStyleClass = "right-arrow"; @Before public void setUp() { initWrappers(); Environment.getEnvironment().setTimeout("wait.state", isEmbedded() ? 60000 : 2000); Environment.getEnvironment().setTimeout("wait.control", isEmbedded() ? 60000 : 1000); scene.mouse().move(new Point(0, 0)); } @BeforeClass public static void setUpClass() throws Exception { PaginationApp.main(null); currentSettingOption = SettingOption.PROGRAM; } @After public void tearDown() { if (doNextResetHard) { resetSceneHard(); } else { resetSceneSoft(); } doNextResetHard = resetHardByDefault; } protected void initWrappers() { scene = Root.ROOT.lookup().wrap(); parent = scene.as(Parent.class, Node.class); testedControl = (Wrap) parent.lookup(Pagination.class, new ByID(TESTED_PAGINATION_ID)).wrap(); } // ACTIONS protected void resetSceneSoft() { clickButtonForTestPurpose(SOFT_RESET_BUTTON_ID); } protected void resetSceneHard() { clickButtonForTestPurpose(HARD_RESET_BUTTON_ID); } protected void doNextResetHard() { doNextResetHard = true; } protected void doNextResetSoft() { doNextResetHard = false; } protected void setNewFactory() { clickButtonForTestPurpose(SET_NEW_PAGE_FACTORY_BUTTON_ID); } protected void setOldFactory() { clickButtonForTestPurpose(SET_OLD_PAGE_FACTORY_BUTTON_ID); } protected void setBulletStyleOfPageIndicators() { clickButtonForTestPurpose(SET_BULLET_PAGE_INDICATOR_BUTTON_ID); } protected void setIndeterminatePageCount() { clickButtonForTestPurpose(SET_PAGE_COUNT_TO_INDETERMINATE_BUTTON_ID); } protected void checkFormComponentButton() { clickButtonByID(FORM_BUTTON_ID); testedControl.waitState(new State() { public Integer reached() { return Integer.parseInt(findTextField(FORM_CLICK_TEXT_FIELD_ID).getControl().getText()); } }, 1); } protected void checkScrollingOfFormComponentScrollBar() { Wrap scrollBar = findScrollBar((Parent)testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true); scrollBar.mouse().turnWheel(-1); testedControl.waitState(new State() { public Integer reached() { return Integer.parseInt(findTextField(FORM_SCROLL_TEXT_FIELD_ID).getControl().getText()); } }, 1); AbstractScroll c = scrollBar.as(AbstractScroll.class); c.allowError(0.01); double meanValue = getScrollBarCenter(scrollBar); c.caret().to(meanValue); assertTrue(Math.abs(meanValue - getScrollBarValue(scrollBar)) <= 1); } protected double getScrollBarValue(final Wrap scrollBar) { return new GetAction() { @Override public void run(Object... os) throws Exception { setResult(scrollBar.getControl().getValue()); } }.dispatch(scrollBar.getEnvironment()); } protected double getScrollBarCenter(final Wrap scrollBar) { return new GetAction() { @Override public void run(Object... os) throws Exception { setResult((scrollBar.getControl().getMax() - scrollBar.getControl().getMin()) / 2); } }.dispatch(scrollBar.getEnvironment()); } protected void checkPrintingInInnerTextField() { final Wrap editWrap = parent.lookup(TextArea.class, new ByID