Path: blob/master/test/jdk/javax/swing/JTextArea/8148555/JTextAreaEmojiTest.java
41153 views
/*1* Copyright (c) 2015, 2017, 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 java.awt.Color;24import java.awt.GridBagConstraints;25import java.awt.GridBagLayout;26import java.awt.event.ActionEvent;27import java.awt.event.ActionListener;28import javax.swing.BorderFactory;29import javax.swing.JButton;30import javax.swing.JFrame;31import javax.swing.JPanel;32import javax.swing.JTextArea;33import javax.swing.SwingUtilities;34import static javax.swing.WindowConstants.EXIT_ON_CLOSE;35import java.util.concurrent.CountDownLatch;36import java.util.concurrent.TimeUnit;3738/* @test39* @key headful40* @bug 8148555 818178241* @summary verifies JTextArea emoji enter exception. Emoji is not supported.42* @requires (os.family=="mac")43* @run main/manual JTextAreaEmojiTest44*/45public class JTextAreaEmojiTest implements46ActionListener {4748private static GridBagLayout layout;49private static JPanel textAreaPanel;50private static JPanel mainControlPanel;51private static JPanel instructionPanel;52private static JPanel resultButtonPanel;53private static JPanel controlPanel;54private static JTextArea instructionTextArea;55private static JTextArea emojiTextArea;56private static JButton passButton;57private static JButton failButton;5859private static JFrame mainFrame;60private static final CountDownLatch testRunLatch = new CountDownLatch(1);6162public static void main(String[] args) throws Exception {6364JTextAreaEmojiTest test = new JTextAreaEmojiTest();65boolean status = testRunLatch.await(5, TimeUnit.MINUTES);6667if (!status) {68throw new RuntimeException("Test timed out");69}70}7172public JTextAreaEmojiTest() throws Exception {73createControlPanelUI();74}7576public final void createControlPanelUI() throws Exception {77SwingUtilities.invokeAndWait(new Runnable() {78@Override79public void run() {80layout = new GridBagLayout();81mainControlPanel = new JPanel(layout);82instructionPanel = new JPanel(layout);83resultButtonPanel = new JPanel(layout);84textAreaPanel = new JPanel(layout);85controlPanel = new JPanel(layout);8687GridBagConstraints gbc = new GridBagConstraints();88String instructions89= "1) Text Area size should be zero"90+ "\n2) Select one emoji from Character Viewer"91+ "\n3) If Text Area size increases displaying"92+ "Blank or supported emoji for default font, click pass"93+ "\n4) Else press fail";94instructionTextArea = new JTextArea();95instructionTextArea.setText(instructions);96instructionTextArea.setEnabled(false);97instructionTextArea.setDisabledTextColor(Color.black);98instructionTextArea.setBackground(Color.white);99instructionTextArea.setBorder(100BorderFactory.createLineBorder(Color.black));101gbc.gridx = 0;102gbc.gridy = 0;103gbc.fill = GridBagConstraints.HORIZONTAL;104instructionPanel.add(instructionTextArea, gbc);105106emojiTextArea = new JTextArea();107emojiTextArea.setEnabled(true);108emojiTextArea.setDisabledTextColor(Color.black);109emojiTextArea.setBackground(Color.white);110emojiTextArea.setBorder(111BorderFactory.createLineBorder(Color.black));112gbc.gridx = 0;113gbc.gridy = 1;114gbc.fill = GridBagConstraints.HORIZONTAL;115textAreaPanel.add(emojiTextArea, gbc);116117passButton = new JButton("Pass");118passButton.setActionCommand("Pass");119passButton.addActionListener(JTextAreaEmojiTest.this);120failButton = new JButton("Fail");121failButton.setActionCommand("Fail");122failButton.addActionListener(JTextAreaEmojiTest.this);123gbc.gridx = 0;124gbc.gridy = 0;125resultButtonPanel.add(passButton, gbc);126gbc.gridx = 1;127gbc.gridy = 0;128resultButtonPanel.add(failButton, gbc);129130gbc.gridx = 0;131gbc.gridy = 0;132mainControlPanel.add(instructionPanel, gbc);133gbc.gridx = 0;134gbc.gridy = 1;135mainControlPanel.add(textAreaPanel, gbc);136gbc.gridx = 0;137gbc.gridy = 2;138mainControlPanel.add(resultButtonPanel, gbc);139140mainControlPanel.add(controlPanel, gbc);141mainFrame = new JFrame("Control Panel");142mainFrame.add(mainControlPanel);143mainFrame.pack();144mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);145mainFrame.setVisible(true);146}147});148}149150@Override151public void actionPerformed(ActionEvent evt) {152if (evt.getSource() instanceof JButton) {153JButton btn = (JButton) evt.getSource();154155switch (btn.getActionCommand()) {156case "Pass":157break;158case "Fail":159throw new AssertionError("Test case has failed!");160}161162cleanUp();163}164}165166private static void cleanUp() {167mainFrame.dispose();168testRunLatch.countDown();169}170}171172173