Lines 47-68
Link Here
|
47 |
import java.beans.PropertyVetoException; |
47 |
import java.beans.PropertyVetoException; |
48 |
import java.beans.VetoableChangeListener; |
48 |
import java.beans.VetoableChangeListener; |
49 |
import java.io.IOException; |
49 |
import java.io.IOException; |
|
|
50 |
import java.io.OutputStream; |
50 |
import java.util.Arrays; |
51 |
import java.util.Arrays; |
51 |
import java.util.Enumeration; |
52 |
import java.util.Enumeration; |
52 |
import java.util.logging.Level; |
53 |
import java.util.logging.Level; |
53 |
import javax.swing.JEditorPane; |
54 |
import javax.swing.JEditorPane; |
54 |
import javax.swing.SwingUtilities; |
55 |
import javax.swing.SwingUtilities; |
55 |
import javax.swing.text.StyledDocument; |
56 |
import javax.swing.text.StyledDocument; |
|
|
57 |
import static junit.framework.Assert.assertNotNull; |
58 |
import static junit.framework.Assert.assertTrue; |
56 |
import org.netbeans.junit.MockServices; |
59 |
import org.netbeans.junit.MockServices; |
57 |
import org.netbeans.junit.NbTestCase; |
60 |
import org.netbeans.junit.NbTestCase; |
58 |
import org.netbeans.junit.RandomlyFails; |
61 |
import org.netbeans.junit.RandomlyFails; |
59 |
import org.openide.DialogDescriptor; |
62 |
import org.openide.DialogDescriptor; |
60 |
import org.openide.DialogDisplayer; |
63 |
import org.openide.DialogDisplayer; |
61 |
import org.openide.NotifyDescriptor; |
64 |
import org.openide.NotifyDescriptor; |
|
|
65 |
import org.openide.cookies.EditCookie; |
62 |
import org.openide.cookies.EditorCookie; |
66 |
import org.openide.cookies.EditorCookie; |
63 |
import org.openide.cookies.OpenCookie; |
67 |
import org.openide.cookies.OpenCookie; |
64 |
import org.openide.filesystems.FileObject; |
68 |
import org.openide.filesystems.FileObject; |
65 |
import org.openide.filesystems.FileSystem; |
69 |
import org.openide.filesystems.FileSystem; |
|
|
70 |
import org.openide.filesystems.FileUtil; |
66 |
import org.openide.filesystems.Repository; |
71 |
import org.openide.filesystems.Repository; |
67 |
import org.openide.nodes.Node; |
72 |
import org.openide.nodes.Node; |
68 |
import org.openide.nodes.NodeAdapter; |
73 |
import org.openide.nodes.NodeAdapter; |
Lines 338-343
Link Here
|
338 |
assertEquals(".htaccess", fo.getNameExt()); |
343 |
assertEquals(".htaccess", fo.getNameExt()); |
339 |
} |
344 |
} |
340 |
|
345 |
|
|
|
346 |
/** |
347 |
* Test that text files are not recognized as binary files. See bug 228700. |
348 |
*/ |
349 |
public void testFixCookieSetRecognizesBinaryFiles() throws IOException { |
350 |
|
351 |
byte[] allowedTextBytes = new byte[]{ |
352 |
'\n', '\r', '\t', '\f' |
353 |
}; |
354 |
for (byte b : allowedTextBytes) { |
355 |
assertNotNull("File that contains an allowed byte " + b |
356 |
+ " shouldn't be recognized as binary file", |
357 |
createDataObjectWithContent(b) |
358 |
.getLookup().lookup(EditCookie.class)); |
359 |
} |
360 |
for (byte b = 0; b <= 31; b++) { |
361 |
if (createDataObjectWithContent(b) |
362 |
.getLookup().lookup(EditCookie.class) != null) { |
363 |
boolean isAllowed = false; |
364 |
for (int j = 0; j < allowedTextBytes.length; j++) { |
365 |
if (b == allowedTextBytes[j]) { |
366 |
isAllowed = true; |
367 |
break; |
368 |
} |
369 |
} |
370 |
assertTrue("File containing byte " + b + " should not be " |
371 |
+ "recognized as text file.", isAllowed); |
372 |
} |
373 |
} |
374 |
} |
375 |
|
376 |
private DataObject createDataObjectWithContent(byte singleByteContent) |
377 |
throws IOException { |
378 |
FileSystem fs = FileUtil.createMemoryFileSystem(); |
379 |
FileObject fob = fs.getRoot().createData("test.txt"); |
380 |
OutputStream os = fob.getOutputStream(); |
381 |
try { |
382 |
os.write(new byte[]{singleByteContent}); |
383 |
} finally { |
384 |
os.close(); |
385 |
} |
386 |
DataObject dob = DataObject.find(fob); |
387 |
if (!(dob instanceof DefaultDataObject)) { |
388 |
fail("Expected an instance of DefaultDataObject"); |
389 |
} |
390 |
return dob; |
391 |
} |
392 |
|
341 |
private void waitEQ() throws Exception { |
393 |
private void waitEQ() throws Exception { |
342 |
getEPanes(null); |
394 |
getEPanes(null); |
343 |
} |
395 |
} |