Skip to content

Commit c98682d

Browse files
committed
8328301: Convert Applet test ManualHTMLDataFlavorTest.java to main program
Backport-of: f7f291c5d4d2d01dab3ccda7518ebc13f6bd58f6
1 parent 9c5807b commit c98682d

File tree

2 files changed

+71
-245
lines changed

2 files changed

+71
-245
lines changed

test/jdk/java/awt/datatransfer/HTMLDataFlavors/ManualHTMLDataFlavorTest.html

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 71 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,24 +22,32 @@
2222
*/
2323

2424
/*
25-
test
25+
@test
2626
@bug 7075105
2727
@summary WIN: Provide a way to format HTML on drop
28-
@author Denis Fokin: area=datatransfer
29-
@run applet/manual=yesno ManualHTMLDataFlavorTest
28+
@library /java/awt/regtesthelpers
29+
@run main/manual ManualHTMLDataFlavorTest
3030
*/
3131

32-
import java.applet.Applet;
33-
import java.awt.*;
32+
33+
import java.awt.Color;
34+
import java.awt.Dimension;
35+
import java.awt.Frame;
36+
import java.awt.Panel;
3437
import java.awt.datatransfer.DataFlavor;
3538
import java.awt.datatransfer.Transferable;
3639
import java.awt.datatransfer.UnsupportedFlavorException;
37-
import java.awt.dnd.*;
40+
import java.awt.dnd.DnDConstants;
41+
import java.awt.dnd.DropTarget;
42+
import java.awt.dnd.DropTargetDragEvent;
43+
import java.awt.dnd.DropTargetDropEvent;
44+
import java.awt.dnd.DropTargetEvent;
45+
import java.awt.dnd.DropTargetListener;
3846
import java.io.IOException;
3947

40-
public class ManualHTMLDataFlavorTest extends Applet {
48+
public class ManualHTMLDataFlavorTest {
4149

42-
class DropPane extends Panel implements DropTargetListener {
50+
static class DropPane extends Panel implements DropTargetListener {
4351

4452
DropPane() {
4553
requestFocus();
@@ -49,7 +57,7 @@ class DropPane extends Panel implements DropTargetListener {
4957

5058
@Override
5159
public Dimension getPreferredSize() {
52-
return new Dimension(200,200);
60+
return new Dimension(400, 400);
5361
}
5462

5563
@Override
@@ -73,15 +81,15 @@ public void dragExit(DropTargetEvent dte) {}
7381
@Override
7482
public void drop(DropTargetDropEvent dtde) {
7583
if (!dtde.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
76-
Sysout.println("DataFlavor.allHtmlFlavor is not present in the system clipboard");
84+
ManualHTMLDataFlavorTest.log("DataFlavor.allHtmlFlavor is not present in the system clipboard");
7785
dtde.rejectDrop();
7886
return;
7987
} else if (!dtde.isDataFlavorSupported(DataFlavor.fragmentHtmlFlavor)) {
80-
Sysout.println("DataFlavor.fragmentHtmlFlavor is not present in the system clipboard");
88+
ManualHTMLDataFlavorTest.log("DataFlavor.fragmentHtmlFlavor is not present in the system clipboard");
8189
dtde.rejectDrop();
8290
return;
8391
} else if (!dtde.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
84-
Sysout.println("DataFlavor.selectionHtmlFlavor is not present in the system clipboard");
92+
ManualHTMLDataFlavorTest.log("DataFlavor.selectionHtmlFlavor is not present in the system clipboard");
8593
dtde.rejectDrop();
8694
return;
8795
}
@@ -90,202 +98,63 @@ public void drop(DropTargetDropEvent dtde) {
9098

9199
Transferable t = dtde.getTransferable();
92100
try {
93-
Sysout.println("ALL:");
94-
Sysout.println(t.getTransferData(DataFlavor.allHtmlFlavor).toString());
95-
Sysout.println("FRAGMENT:");
96-
Sysout.println(t.getTransferData(DataFlavor.fragmentHtmlFlavor).toString());
97-
Sysout.println("SELECTION:");
98-
Sysout.println(t.getTransferData(DataFlavor.selectionHtmlFlavor).toString());
101+
ManualHTMLDataFlavorTest.log("ALL:");
102+
ManualHTMLDataFlavorTest.log(t.getTransferData(DataFlavor.allHtmlFlavor).toString());
103+
t.getTransferData(DataFlavor.allHtmlFlavor).toString();
104+
ManualHTMLDataFlavorTest.log("FRAGMENT:");
105+
ManualHTMLDataFlavorTest.log(t.getTransferData(DataFlavor.fragmentHtmlFlavor).toString());
106+
ManualHTMLDataFlavorTest.log("SELECTION:");
107+
ManualHTMLDataFlavorTest.log(t.getTransferData(DataFlavor.selectionHtmlFlavor).toString());
99108
} catch (UnsupportedFlavorException | IOException e) {
100109
e.printStackTrace();
101110
}
102111

103112
}
104113
}
105114

106-
public void init() {
107-
108-
String[] instructions =
109-
{
110-
"1) The test contains a drop-aware panel with a red background",
111-
"2) Open some page in a browser, select some text",
112-
" Drag and drop it on the red panel",
113-
" IMPORTANT NOTE: the page should be stored locally.",
114-
" otherwise for instance iexplore can prohibit drag and drop from",
115-
" the browser to other applications because of",
116-
" the protected mode restrictions.",
117-
" On Mac OS X do NOT use Safari, it does not provide the needed DataFlavor",
118-
"3) Check the data in the output area of this dialog",
119-
"5) The output should not contain information that any of",
120-
" flavors is not present in the system clipboard",
121-
"6) The output should contain data in three different formats",
122-
" provided by the system clipboard",
123-
" - Data after the \"ALL:\" marker should include the data",
124-
" from the \"SELECTION:\" marker",
125-
" - Data after the \"FRAGMENT\" marker should include the data",
126-
" from the \"SELECTION:\" marker and may be some closing",
127-
" tags could be added to the mark-up",
128-
" - Data after the \"SELECTION:\" marker should correspond",
129-
" to the data selected in the browser",
130-
"7) If the above requirements are met, the test is passed"
131-
};
132-
133-
add(new DropPane());
134-
Sysout.createDialogWithInstructions( instructions );
135-
136-
new ManualHTMLDataFlavorTest();
115+
static final String INSTRUCTIONS = """
116+
1) The test contains a drop-aware panel with a red background.
117+
2) Open some page in a browser, select some text.
118+
Drag and drop it on the red panel.
119+
IMPORTANT NOTE: the page should be stored locally.
120+
Otherwise for instance Internet Explorer may prohibit drag and drop from
121+
the browser to other applications because of protected mode restrictions.
122+
On MacOS do NOT use Safari, it does not provide the needed DataFlavor.
123+
3) Check the data in the output area of this window.
124+
5) The output should not contain information that any of
125+
flavors is not present in the system clipboard.
126+
6) The output should contain data in three different formats
127+
provided by the system clipboard.
128+
- Data after the "ALL:" marker should include the data
129+
from the "SELECTION:" marker".
130+
- Data after the "FRAGMENT" marker should include the data
131+
from the "SELECTION:" marker and may be some closing
132+
tags could be added to the mark-up.
133+
- Data after the "SELECTION:" marker should correspond
134+
to the data selected in the browser.
135+
7) If the above requirements are met, the test is passed.
136+
""";
137+
138+
static Frame createDropWindow() {
139+
Frame frame = new Frame("Manual HTML DataFlavor Test");
140+
frame.add(new DropPane());
141+
frame.setAlwaysOnTop(true);
142+
frame.pack();
143+
return frame;
137144
}
138145

139-
public void start ()
140-
{
141-
setSize (200,200);
142-
setVisible(true);
143-
validate();
144-
145-
}// start()
146-
146+
static void log(String msg) {
147+
PassFailJFrame.log(msg);
148+
}
149+
150+
public static void main(String[] args) throws Exception {
151+
PassFailJFrame.builder()
152+
.instructions(INSTRUCTIONS)
153+
.rows(25)
154+
.columns(50)
155+
.testUI(ManualHTMLDataFlavorTest::createDropWindow)
156+
.logArea()
157+
.build()
158+
.awaitAndCheck();
159+
}
147160
}
148-
149-
150-
/* Place other classes related to the test after this line */
151-
152-
153-
154-
155-
156-
/****************************************************
157-
Standard Test Machinery
158-
DO NOT modify anything below -- it's a standard
159-
chunk of code whose purpose is to make user
160-
interaction uniform, and thereby make it simpler
161-
to read and understand someone else's test.
162-
****************************************************/
163-
164-
/**
165-
This is part of the standard test machinery.
166-
It creates a dialog (with the instructions), and is the interface
167-
for sending text messages to the user.
168-
To print the instructions, send an array of strings to Sysout.createDialog
169-
WithInstructions method. Put one line of instructions per array entry.
170-
To display a message for the tester to see, simply call Sysout.println
171-
with the string to be displayed.
172-
This mimics System.out.println but works within the test harness as well
173-
as standalone.
174-
*/
175-
176-
class Sysout
177-
{
178-
private static TestDialog dialog;
179-
180-
public static void createDialogWithInstructions( String[] instructions )
181-
{
182-
dialog = new TestDialog( new Frame(), "Instructions" );
183-
dialog.printInstructions( instructions );
184-
dialog.setVisible(true);
185-
println( "Any messages for the tester will display here." );
186-
}
187-
188-
public static void createDialog( )
189-
{
190-
dialog = new TestDialog( new Frame(), "Instructions" );
191-
String[] defInstr = { "Instructions will appear here. ", "" } ;
192-
dialog.printInstructions( defInstr );
193-
dialog.setVisible(true);
194-
println( "Any messages for the tester will display here." );
195-
}
196-
197-
198-
public static void printInstructions( String[] instructions )
199-
{
200-
dialog.printInstructions( instructions );
201-
}
202-
203-
204-
public static void println( String messageIn )
205-
{
206-
dialog.displayMessage( messageIn );
207-
}
208-
209-
}// Sysout class
210-
211-
/**
212-
This is part of the standard test machinery. It provides a place for the
213-
test instructions to be displayed, and a place for interactive messages
214-
to the user to be displayed.
215-
To have the test instructions displayed, see Sysout.
216-
To have a message to the user be displayed, see Sysout.
217-
Do not call anything in this dialog directly.
218-
*/
219-
class TestDialog extends Dialog
220-
{
221-
222-
TextArea instructionsText;
223-
TextArea messageText;
224-
int maxStringLength = 80;
225-
226-
//DO NOT call this directly, go through Sysout
227-
public TestDialog( Frame frame, String name )
228-
{
229-
super( frame, name );
230-
int scrollBoth = TextArea.SCROLLBARS_BOTH;
231-
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
232-
add( "North", instructionsText );
233-
234-
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
235-
add("Center", messageText);
236-
237-
pack();
238-
239-
setVisible(true);
240-
}// TestDialog()
241-
242-
//DO NOT call this directly, go through Sysout
243-
public void printInstructions( String[] instructions )
244-
{
245-
//Clear out any current instructions
246-
instructionsText.setText( "" );
247-
248-
//Go down array of instruction strings
249-
250-
String printStr, remainingStr;
251-
for( int i=0; i < instructions.length; i++ )
252-
{
253-
//chop up each into pieces maxSringLength long
254-
remainingStr = instructions[ i ];
255-
while( remainingStr.length() > 0 )
256-
{
257-
//if longer than max then chop off first max chars to print
258-
if( remainingStr.length() >= maxStringLength )
259-
{
260-
//Try to chop on a word boundary
261-
int posOfSpace = remainingStr.
262-
lastIndexOf( ' ', maxStringLength - 1 );
263-
264-
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
265-
266-
printStr = remainingStr.substring( 0, posOfSpace + 1 );
267-
remainingStr = remainingStr.substring( posOfSpace + 1 );
268-
}
269-
//else just print
270-
else
271-
{
272-
printStr = remainingStr;
273-
remainingStr = "";
274-
}
275-
276-
instructionsText.append( printStr + "\n" );
277-
278-
}// while
279-
280-
}// for
281-
282-
}//printInstructions()
283-
284-
//DO NOT call this directly, go through Sysout
285-
public void displayMessage( String messageIn )
286-
{
287-
messageText.append( messageIn + "\n" );
288-
System.out.println(messageIn);
289-
}
290-
291-
}// TestDialog class

0 commit comments

Comments
 (0)