chromium/third_party/blink/web_tests/fast/events/clipboard-dataTransferItemList-remove.html

<!DOCTYPE html>
<html>
<head>
<link rel="help" href="http://www.w3.org/TR/2013/WD-html51-20130528/editing.html#dom-datatransferitemlist-remove">
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Checks that DataTransferItemList.remove() is working");

var dataTansferItemList;
function copy(event)
{
    debug("* copy event");
    event.preventDefault();
    dataTansferItemList = event.clipboardData.items;

    dataTansferItemList.add('a', 'text/plain');
    dataTansferItemList.add('http://www.google.com/', 'text/uri-list');
    dataTansferItemList.add('<em>Markup</em>', 'text/html');
    dataTansferItemList.add('hello world', 'custom-data');

    shouldBe('dataTansferItemList.length', '4');
    shouldBeEqualToString('dataTansferItemList[0].type', 'text/plain');
    shouldBeEqualToString('dataTansferItemList[1].type', 'text/uri-list');
    shouldBeEqualToString('dataTansferItemList[2].type', 'text/html');
    shouldBeEqualToString('dataTansferItemList[3].type', 'custom-data');

    // Failure cases.
    shouldThrow('dataTansferItemList.remove()', '"TypeError: Failed to execute \'remove\' on \'DataTransferItemList\': 1 argument required, but only 0 present."');
    shouldNotThrow('dataTansferItemList.remove(-1)');
    shouldBe('dataTansferItemList.length', '4');
    shouldNotThrow('dataTansferItemList.remove(999)');
    shouldBe('dataTansferItemList.length', '4');

    // Success cases.
    shouldNotThrow('dataTansferItemList.remove(0)');
    shouldBe('dataTansferItemList.length', '3');
    shouldBeEqualToString('dataTansferItemList[0].type', 'text/uri-list');
    shouldBeEqualToString('dataTansferItemList[1].type', 'text/html');
    shouldNotThrow('dataTansferItemList.remove(-4294967295)'); // Wraps to 1.
    shouldBe('dataTansferItemList.length', '2');
    shouldBeEqualToString('dataTansferItemList[1].type', 'custom-data');
}

function paste(event)
{
    debug("* paste event");
    dataTansferItemList = event.clipboardData.items;
    shouldBe('dataTansferItemList.length', '2');
    shouldThrow('dataTansferItemList.remove(0)', '"InvalidStateError: Failed to execute \'remove\' on \'DataTransferItemList\': The list is not writable."'); // List is readonly during paste.
    shouldBe('dataTansferItemList.length', '2');
}

document.oncopy = copy;
document.onpaste = paste;
document.execCommand('copy');
document.execCommand('paste');
</script>
</body>
</html>