3 <body oncopy=
"copy(event)" onpaste=
"paste(event)">
4 <div>This file tests the basic functionality and properties of DataTransferItems. This test requires DRT.
</div>
5 <div id=
"console"></div>
7 <script src=
"../editing.js"></script>
10 var pendingCallbacks
= 0;
11 var savedDataTransferItems
= null;
12 var savedDataTransferItem
= null;
16 var console
= document
.getElementById('console');
17 console
.appendChild(document
.createTextNode(text
));
18 console
.appendChild(document
.createElement('br'));
21 function removeFontName(text
)
25 return text
.replace(/font-family: [^;]+;/g, '');
28 function handleEvent(data
)
31 if (--pendingCallbacks
== 0) {
32 window
.testRunner
.notifyDone();
38 var items
= event
.clipboardData
.items
;
39 log('Populating DataTransferItems...');
40 items
.add('Hello World!', 'text/plain');
41 items
.add('<b>Hello World!', 'text/html');
43 // Check that an exception is properly raised when attempting to add a duplicate string type.
45 items
.add('Moo', 'text/plain');
47 log('Caught exception "' + e
+ '" as expected.');
50 // Check that the container didn't change.
51 log('Verifying contents of DataTransferItems...');
52 log('items.length: ' + items
.length
);
53 log('items[0].kind: ' + items
[0].kind
);
54 log('items[0].type: ' + items
[0].type
);
55 log('items[1].kind: ' + items
[1].kind
);
56 log('items[1].type: ' + items
[1].type
);
57 items
[0].getAsString(function (data
) { handleEvent('copy: items[0] value: ' + data
); });
59 items
[1].getAsString(function (data
) { handleEvent('copy: items[1] value: ' + data
); });
62 log('Checking if items past the end of the collection can be indexed:');
63 log('items[2] is undefined: ' + typeof items
[2]);
68 var items
= event
.clipboardData
.items
;
70 // Cache references to make sure they aren't accessible outside the event handler.
71 savedDataTransferItems
= items
;
72 savedDataTransferItem
= items
[0];
74 var originalLength
= items
.length
;
75 log('Checking that a read-only DataTransferItems cannot be mutated...');
76 // Should be immutable.
77 items
.add('Hello World!', 'text/plain');
78 log('items.length: ' + items
.length
);
79 log('items[0].kind: ' + items
[0].kind
);
80 log('items[0].type: ' + items
[0].type
);
81 items
[0].getAsString(function (data
) { handleEvent('paste: items[0] value: ' + removeFontName(data
)); });
83 log('items[1].kind: ' + items
[1].kind
);
84 log('items[1].type: ' + items
[1].type
);
85 items
[1].getAsString(function (data
) { handleEvent('paste: items[1] value: ' + removeFontName(data
)); });
87 log('items[2] is undefined: ' + typeof items
[2]);
91 if (!window
.testRunner
)
93 testRunner
.waitUntilDone();
94 testRunner
.dumpAsText();
96 eventSender
.mouseMoveTo(0, 0);
97 for (var i
= 0; i
< 3; i
++) {
98 eventSender
.mouseDown();
99 eventSender
.mouseUp();
104 log('Testing if DataTransferItems can be accessed outside an event handler...');
105 if (savedDataTransferItems
.length
!= 0) {
106 log('DataTransferItems.length non-zero outside event handler!');
108 savedDataTransferItems
.add('Security?', 'text/foo');
109 if (savedDataTransferItems
.length
!= 0) {
110 log('DataTransferItems mutated outside event handler!');
112 if (typeof savedDataTransferItems
[0] == 'undefined') {
113 log('DataTransferItem accessed outside event handler!');
115 if (typeof savedDataTransferItem
== 'undefined') {
116 log('DataTransferItem accessed outside event handler!');