| 1 |
/* ClipboardContentTests.java |
| 2 |
Copyright (C) 2012 Red Hat, Inc. |
| 3 |
|
| 4 |
This file is part of IcedTea. |
| 5 |
|
| 6 |
IcedTea is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, version 2. |
| 9 |
|
| 10 |
IcedTea is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with IcedTea; see the file COPYING. If not, write to |
| 17 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 |
02110-1301 USA. |
| 19 |
|
| 20 |
Linking this library statically or dynamically with other modules is |
| 21 |
making a combined work based on this library. Thus, the terms and |
| 22 |
conditions of the GNU General Public License cover the whole |
| 23 |
combination. |
| 24 |
|
| 25 |
As a special exception, the copyright holders of this library give you |
| 26 |
permission to link this library with independent modules to produce an |
| 27 |
executable, regardless of the license terms of these independent |
| 28 |
modules, and to copy and distribute the resulting executable under |
| 29 |
terms of your choice, provided that you also meet, for each linked |
| 30 |
independent module, the terms and conditions of the license of that |
| 31 |
module. An independent module is a module which is not derived from |
| 32 |
or based on this library. If you modify this library, you may extend |
| 33 |
this exception to your version of the library, but you are not |
| 34 |
obligated to do so. If you do not wish to do so, delete this |
| 35 |
exception statement from your version. |
| 36 |
*/ |
| 37 |
|
| 38 |
import net.sourceforge.jnlp.tools.WaitingForStringProcess; |
| 39 |
import java.util.Arrays; |
| 40 |
import java.util.Collections; |
| 41 |
import java.util.List; |
| 42 |
import net.sourceforge.jnlp.ContentReaderListener; |
| 43 |
import net.sourceforge.jnlp.ProcessResult; |
| 44 |
import net.sourceforge.jnlp.ServerAccess; |
| 45 |
import net.sourceforge.jnlp.annotations.Bug; |
| 46 |
import net.sourceforge.jnlp.annotations.NeedsDisplay; |
| 47 |
import net.sourceforge.jnlp.tools.AsyncJavaws; |
| 48 |
import static net.sourceforge.jnlp.tools.ClipboardHelpers.pasteFromClipboard; |
| 49 |
import static net.sourceforge.jnlp.tools.ClipboardHelpers.putToClipboard; |
| 50 |
import org.junit.Assert; |
| 51 |
import org.junit.Test; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
@Bug(id="PR708") |
| 56 |
public class ClipboardContentTests { |
| 57 |
|
| 58 |
private static final String XCEPTION = "xception"; |
| 59 |
private static final String contentC = "COPY#$REPRODUCER"; |
| 60 |
private static final String contentP = "PASTE#$REPRODUCER"; |
| 61 |
private static final String emptyContent = "empty content"; |
| 62 |
private static ServerAccess server = new ServerAccess(); |
| 63 |
private static final List<String> javawsTrustArg = Collections.unmodifiableList(Arrays.asList(new String[]{"-Xtrustall"})); |
| 64 |
|
| 65 |
|
| 66 |
@Test |
| 67 |
public void assertClipboardIsWorking() throws Exception { |
| 68 |
putToClipboard(emptyContent); |
| 69 |
Assert.assertEquals(emptyContent, pasteFromClipboard()); |
| 70 |
putToClipboard(contentC); |
| 71 |
Assert.assertEquals(contentC, pasteFromClipboard()); |
| 72 |
} |
| 73 |
|
| 74 |
@Test |
| 75 |
@Bug(id = "PR708") |
| 76 |
public void ClipboardContentTestCopy1() throws Exception { |
| 77 |
putToClipboard(emptyContent); |
| 78 |
Assert.assertEquals("Clipboard must contain new value, did not", emptyContent, pasteFromClipboard()); |
| 79 |
WaitingForStringProcess wfsp = new WaitingForStringProcess(server, "/ClipboardContentCopy1.jnlp", javawsTrustArg, true, "copied"); |
| 80 |
wfsp.run(); |
| 81 |
String ss = pasteFromClipboard(); |
| 82 |
Assert.assertEquals("Clipboard content must not be changed - was", emptyContent, ss); |
| 83 |
Assert.assertNotNull("Result had to be delivered, was not", wfsp.getAj().getResult()); |
| 84 |
Assert.assertTrue("ClipboardContentSignedCopy stderr should contain " + XCEPTION + " but did not ", wfsp.getAj().getResult().stderr.contains(XCEPTION)); |
| 85 |
} |
| 86 |
|
| 87 |
//@Test needs awt robot to close dialog |
| 88 |
@Bug(id = "PR708") |
| 89 |
@NeedsDisplay |
| 90 |
public void ClipboardContentTestCopy2() throws Exception { |
| 91 |
putToClipboard(emptyContent); |
| 92 |
Assert.assertEquals("Clipboard must contain new value, did not", emptyContent, pasteFromClipboard()); |
| 93 |
WaitingForStringProcess wfsp = new WaitingForStringProcess(server, "/ClipboardContentCopy2.jnlp", javawsTrustArg, false, "copied"); |
| 94 |
wfsp.run(); |
| 95 |
String ss = pasteFromClipboard(); |
| 96 |
Assert.assertEquals("Clipboard content must not be changed, was", emptyContent, ss); |
| 97 |
Assert.assertNotNull("Result had to be delivered, was not", wfsp.getAj().getResult()); |
| 98 |
Assert.assertTrue("ClipboardContentSignedCopy stderr should contain " + XCEPTION + " but did not", wfsp.getAj().getResult().stderr.contains(XCEPTION)); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
@Test |
| 103 |
@Bug(id = "PR708") |
| 104 |
public void ClipboardContentTestPaste1() throws Exception { |
| 105 |
//necessery errasing |
| 106 |
putToClipboard(emptyContent); |
| 107 |
Assert.assertEquals("Clipboard must contain new value, did not", emptyContent, pasteFromClipboard()); |
| 108 |
//now put the tested data |
| 109 |
putToClipboard(contentP); |
| 110 |
Assert.assertEquals("Clipboard must contain new value, did not", contentP, pasteFromClipboard()); |
| 111 |
ProcessResult pr = server.executeJavawsHeadless(javawsTrustArg, "/ClipboardContentPaste1.jnlp"); |
| 112 |
Assert.assertFalse("ClipboardContentTestPaste stdout should not contain " + contentP + " but didn't", pr.stdout.contains(contentP)); |
| 113 |
Assert.assertTrue("ClipboardContentTestPaste stderr should contain " + XCEPTION + " but didn't ", pr.stderr.contains(XCEPTION)); |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
//@Test |
| 118 |
//needs awt robot to close dialog |
| 119 |
//Q - can this test be headless,and so automated? |
| 120 |
//A - no, headless test are present. Swing is handling clipoard by little bit more complicated ways |
| 121 |
// but imho at the end its the same privlidges. So this test is kept only fo record |
| 122 |
@Bug(id = "PR708") |
| 123 |
@NeedsDisplay |
| 124 |
public void ClipboardContentTestPaste2() throws Exception { |
| 125 |
//necessery errasing |
| 126 |
putToClipboard(emptyContent); |
| 127 |
Assert.assertEquals("Clipboard must contain new value, did not", emptyContent, pasteFromClipboard()); |
| 128 |
//now put the tested data |
| 129 |
putToClipboard(contentP); |
| 130 |
Assert.assertEquals("Clipboard must contain new value, did not", contentP, pasteFromClipboard()); |
| 131 |
Assert.assertEquals("Clipboard must contain new value, did not", contentP, pasteFromClipboard()); |
| 132 |
ProcessResult pr = server.executeJavaws(javawsTrustArg, "/ClipboardContentPaste2.jnlp"); |
| 133 |
Assert.assertFalse("ClipboardContentTestPaste stdout should not contain " + contentP + " but didn't", pr.stdout.contains(contentP)); |
| 134 |
Assert.assertTrue("ClipboardContentTestPaste stderr should contain " + XCEPTION + " but didn't ", pr.stderr.contains(XCEPTION)); |
| 135 |
} |
| 136 |
} |