Path: blob/master/test/jdk/sanity/client/SwingSet/src/ListDemoTest.java
41153 views
/*1* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import com.sun.swingset3.demos.list.ListDemo;24import static com.sun.swingset3.demos.list.ListDemo.DEMO_TITLE;2526import java.awt.Component;27import javax.swing.JList;28import javax.swing.UIManager;2930import org.netbeans.jemmy.ClassReference;31import org.netbeans.jemmy.ComponentChooser;32import org.netbeans.jemmy.operators.JCheckBoxOperator;33import org.netbeans.jemmy.operators.JFrameOperator;34import org.netbeans.jemmy.operators.JListOperator;3536import static org.jemmy2ext.JemmyExt.*;3738import org.jtregext.GuiTestListener;3940import org.testng.annotations.Listeners;41import org.testng.annotations.Test;42import static org.testng.AssertJUnit.*;4344/*45* @test46* @key headful47* @summary Verifies SwingSet3 ListDemo page by checking and unchecking all48* the checkboxes on the page and verifying the number of items in the49* list.50*51* @library /sanity/client/lib/jemmy/src52* @library /sanity/client/lib/Extensions/src53* @library /sanity/client/lib/SwingSet3/src54* @modules java.desktop55* java.logging56* @build org.jemmy2ext.JemmyExt57* @build com.sun.swingset3.demos.list.ListDemo58* @run testng/timeout=600 ListDemoTest59*/60@Listeners(GuiTestListener.class)61public class ListDemoTest {6263private static final int CHECKBOX_COUNT = 50;6465private void waitModelSize(JListOperator listOp, int size) {66listOp.waitState(new ComponentChooser() {67public boolean checkComponent(Component comp) {68return getUIValue(listOp, (JList list) -> list.getModel().getSize()) == size;69}7071public String getDescription() {72return "Model size to be equal to " + size;73}74});75}7677@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)78public void test(String lookAndFeel) throws Exception {79UIManager.setLookAndFeel(lookAndFeel);8081new ClassReference(ListDemo.class.getCanonicalName()).startApplication();8283JFrameOperator frame = new JFrameOperator(DEMO_TITLE);84JListOperator listOp = new JListOperator(frame);8586// Check *NO* Prefix and Suffixes Marked87for (int i = 0; i < CHECKBOX_COUNT; i++) {88JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);89checkBox.changeSelection(false);90}91waitModelSize(listOp, 0);9293// Check *ALL* Prefix and Suffixes Marked94for (int i = 0; i < CHECKBOX_COUNT; i++) {95JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);96checkBox.changeSelection(true);97}98waitModelSize(listOp, CHECKBOX_COUNT * CHECKBOX_COUNT / 4);99100// Check *ALL* Prefix and *NO* Suffixes Marked101for (int i = 0; i < CHECKBOX_COUNT; i++) {102JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);103if (i < CHECKBOX_COUNT / 2) {104checkBox.changeSelection(true);105} else {106checkBox.changeSelection(false);107}108}109waitModelSize(listOp, 0);110111// Check *NO* Prefix and *ALL* Suffixes Marked112for (int i = 0; i < CHECKBOX_COUNT; i++) {113JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i);114if (i < CHECKBOX_COUNT / 2) {115checkBox.changeSelection(false);116} else {117checkBox.changeSelection(true);118}119}120waitModelSize(listOp, 0);121}122123private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) {124125// We map first half of indexes to the Prefixes panel and the second half126// to the Suffixes panel127String labelText;128int subindex;129if (index < CHECKBOX_COUNT / 2) {130labelText = "Prefixes";131subindex = index;132} else {133labelText = "Suffixes";134subindex = index - CHECKBOX_COUNT / 2;135}136137JCheckBoxOperator result = new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex);138result.setVerification(true);139return result;140}141142}143144145