Diff
Modified: trunk/LayoutTests/ChangeLog (222362 => 222363)
--- trunk/LayoutTests/ChangeLog 2017-09-21 23:07:27 UTC (rev 222362)
+++ trunk/LayoutTests/ChangeLog 2017-09-21 23:10:33 UTC (rev 222363)
@@ -1,3 +1,21 @@
+2017-09-21 Ryosuke Niwa <[email protected]>
+
+ DataTransfer.items should contain text/html and text/uri-list
+ https://bugs.webkit.org/show_bug.cgi?id=176772
+ <rdar://problem/34386899>
+
+ Reviewed by Darin Adler.
+
+ Added tests for copying text/html and text/uri-list, and updated the existing test for
+ coping & pasting plain text to explicitly set only text/plain now that
+ the data transfer item list can contain HTML markup.
+
+ * editing/pasteboard/datatransfer-items-copy-html-expected.txt: Added.
+ * editing/pasteboard/datatransfer-items-copy-html.html: Added.
+ * editing/pasteboard/datatransfer-items-copy-url-expected.txt: Added.
+ * editing/pasteboard/datatransfer-items-copy-url.html: Added.
+ * editing/pasteboard/datatransfer-items-paste-plaintext.html:
+
2017-09-21 Youenn Fablet <[email protected]>
LayoutTest platform/mac/webrtc/captureCanvas-webrtc-software-encoder.html is a flaky failure
Added: trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-html-expected.txt (0 => 222363)
--- trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-html-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-html-expected.txt 2017-09-21 23:10:33 UTC (rev 222363)
@@ -0,0 +1,48 @@
+CONSOLE MESSAGE: line 1: ReferenceError: Can't find variable: string
+This tests copying HTML markup using dataTransfer.items. To manually test, click on "Copy text" and paste (Command+V on Mac Control+V elsewhere).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS clipboardData.items.length is 0
+PASS clipboardData.setData("text/html", "rock"); clipboardData.items.length is 1
+PASS initialItem = clipboardData.items[0]; initialItem.kind is "string"
+PASS initialItem.type is "text/html"
+PASS initialItem.getAsFile() is null
+PASS initialItem.getAsString(checkContent(1, "rock")) is undefined
+PASS clipboardData.items.add("paper", "text/HTML") threw exception NotSupportedError: The operation is not supported..
+PASS clipboardData.items[0] is initialItem
+PASS clipboardData.clearData(); clipboardData.items.length is 0
+PASS clipboardData.items.add("<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>", "TEXT/html"); clipboardData.items.length is 1
+PASS clipboardData.items[0] is not initialItem
+PASS initialItem.kind is "string"
+PASS initialItem.type is ""
+PASS initialItem.getAsFile() is null
+PASS initialItem.getAsString(() => testFailed("getAsString should exit immeidately if item is disabled 1")) is undefined
+PASS clipboardData.getData("text/html") is "<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>"
+PASS clipboardData.getData("text/plain") is ""
+PASS firstItem = clipboardData.items[0]; clipboardData.items[0].kind is "string"
+PASS firstItem.type is "text/html"
+PASS firstItem.getAsFile() is null
+PASS firstItem.getAsString(checkContent(2, "<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>")) is undefined
+PASS secondItem = clipboardData.items.add("some content", "text/plain"); secondItem is clipboardData.items[1]
+PASS clipboardData.getData("text/plain") is "some content"
+PASS secondItem.kind is "string"
+PASS secondItem.type is "text/plain"
+PASS secondItem.getAsFile() is null
+PASS secondItem.getAsString(checkContent(3, "some content")) is undefined
+PASS clipboardData.items[0] is firstItem
+PASS firstItem.kind is "string"
+PASS firstItem.type is "text/html"
+PASS clipboardData.getData("text/html") is "<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>"
+PASS firstItem.getAsString(checkContent(4, "<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>")) is undefined
+PASS clipboardData.items.remove(0); clipboardData.items.length is 1
+PASS clipboardData.items[0] is secondItem
+PASS actualContent1 is "rock"
+PASS actualContent2 is "<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>"
+PASS actualContent3 is "some content"
+PASS actualContent4 is "<!DOCTYPE html><!-- hello --><script>alert('Test failed');</script>"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-html.html (0 => 222363)
--- trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-html.html (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-html.html 2017-09-21 23:10:33 UTC (rev 222363)
@@ -0,0 +1,99 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description('This tests copying HTML markup using dataTransfer.items. To manually test, click on "Copy text" and paste (Command+V on Mac Control+V elsewhere).');
+
+function copyText()
+{
+ document.getElementById('source').focus();
+ document.execCommand('SelectAll', false, null);
+ document.execCommand('Copy', false, null);
+}
+
+function copy(event)
+{
+ clipboardData = event.clipboardData;
+ shouldBe('clipboardData.items.length', '0');
+ shouldBe('clipboardData.setData("text/html", "rock"); clipboardData.items.length', '1');
+ shouldBeEqualToString('initialItem = clipboardData.items[0]; initialItem.kind', 'string');
+ shouldBeEqualToString('initialItem.type', 'text/html');
+ shouldBe('initialItem.getAsFile()', 'null');
+ shouldBe('initialItem.getAsString(checkContent(1, "rock"))', 'undefined');
+
+ shouldThrowErrorName('clipboardData.items.add("paper", "text/HTML")', 'NotSupportedError');
+ shouldBe('clipboardData.items[0]', 'initialItem');
+ shouldBe('clipboardData.clearData(); clipboardData.items.length', '0');
+
+ const markup = `<!DOCTYPE html><!-- hello --><script>alert('Test failed');</scr` + `ipt>`;
+ shouldBe(`clipboardData.items.add("${markup}", "TEXT/html"); clipboardData.items.length`, '1');
+ shouldNotBe('clipboardData.items[0]', 'initialItem');
+ shouldBeEqualToString('initialItem.kind', 'string');
+ shouldBeEqualToString('initialItem.type', '');
+ shouldBe('initialItem.getAsFile()', 'null');
+ shouldBe('initialItem.getAsString(() => testFailed("getAsString should exit immeidately if item is disabled 1"))', 'undefined');
+
+ shouldBeEqualToString('clipboardData.getData("text/html")', markup);
+ shouldBeEqualToString('clipboardData.getData("text/plain")', '');
+ shouldBeEqualToString('firstItem = clipboardData.items[0]; clipboardData.items[0].kind', 'string');
+ shouldBeEqualToString('firstItem.type', 'text/html');
+ shouldBe('firstItem.getAsFile()', 'null');
+ shouldBe(`firstItem.getAsString(checkContent(2, "${markup}"))`, 'undefined');
+
+ shouldBe('secondItem = clipboardData.items.add("some content", "text/plain"); secondItem', 'clipboardData.items[1]');
+ shouldBeEqualToString('clipboardData.getData("text/plain")', 'some content');
+ shouldBeEqualToString('secondItem.kind', 'string');
+ shouldBeEqualToString('secondItem.type', 'text/plain');
+ shouldBe('secondItem.getAsFile()', 'null');
+ shouldBe('secondItem.getAsString(checkContent(3, "some content"))', 'undefined');
+
+ shouldBe('clipboardData.items[0]', 'firstItem');
+ shouldBeEqualToString('firstItem.kind', 'string');
+ shouldBeEqualToString('firstItem.type', 'text/html');
+ shouldBeEqualToString('clipboardData.getData("text/html")', markup);
+ shouldBe(`firstItem.getAsString(checkContent(4, "${markup}"))`, 'undefined');
+
+ shouldBe('clipboardData.items.remove(0); clipboardData.items.length', '1');
+ shouldBe('clipboardData.items[0]', 'secondItem');
+ shouldBe('firstItem.kind', 'string');
+ shouldBe('firstItem.type', 'text/html');
+ shouldBe('firstItem.getAsFile()', 'null');
+ shouldBe('firstItem.getAsString(() => testFailed("getAsString should exit immeidately if item is disabled 2"))', 'undefined');
+ shouldBe('secondItem.kind', 'string');
+ shouldBe('secondItem.type', 'text/plain');
+ shouldBe('secondItem.getAsFile()', 'null');
+ shouldBe('secondItem.getAsString(checkContent(4, "some content"))', 'undefined');
+
+}
+
+let count = 0;
+function checkContent(number, expectedContent)
+{
+ count++;
+ return (content) => {
+ const variableName = 'actualContent' + number;
+ window[variableName] = content;
+ shouldBeEqualToString(variableName, expectedContent);
+ count--;
+ if (!count) {
+ document.getElementById('container').style.display = 'none';
+ finishJSTest();
+ }
+ }
+}
+
+if (window.testRunner)
+ window._onload_ = copyText;
+jsTestIsAsync = true;
+successfullyParsed = true;
+
+</script>
+<div id="container">
+ <button _onclick_="copyText();">Copy text</button>
+ <div id="source" _oncopy_="copy(event)" contenteditable="true">hello, world</div>
+</div>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-url-expected.txt (0 => 222363)
--- trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-url-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-url-expected.txt 2017-09-21 23:10:33 UTC (rev 222363)
@@ -0,0 +1,49 @@
+This tests copying URL string using dataTransfer.items. To manually test, click on "Copy text" and paste (Command+V on Mac Control+V elsewhere).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS clipboardData.items.length is 0
+PASS clipboardData.setData("text/uri-list", "rock"); clipboardData.items.length is 1
+PASS initialItem = clipboardData.items[0]; initialItem.kind is "string"
+PASS initialItem.type is "text/uri-list"
+PASS initialItem.getAsFile() is null
+PASS initialItem.getAsString(checkContent(1, "rock")) is undefined
+PASS clipboardData.items.add("paper", "text/uri-list") threw exception NotSupportedError: The operation is not supported..
+PASS clipboardData.items[0] is initialItem
+PASS clipboardData.items.clear(); clipboardData.items.length is 0
+PASS firstItem = clipboardData.items.add("https://webkit.org/", "text/uri-list"); clipboardData.items.length is 1
+PASS clipboardData.items[0] is firstItem
+PASS clipboardData.items[0] is not initialItem
+PASS firstItem.kind is "string"
+PASS firstItem.type is "text/uri-list"
+PASS firstItem.getAsFile() is null
+PASS firstItem.getAsString(checkContent(2, "https://webkit.org/")) is undefined
+PASS clipboardData.getData("url") is "https://webkit.org/"
+PASS clipboardData.getData("text/plain") is ""
+PASS secondItem = clipboardData.items.add("WebKit", "text/PLAIN"); clipboardData.items.length is 2
+PASS clipboardData.items[1] is secondItem
+PASS secondItem.kind is "string"
+PASS secondItem.type is "text/plain"
+PASS secondItem.getAsFile() is null
+PASS secondItem.getAsString(checkContent(3, "WebKit")) is undefined
+PASS clipboardData.getData("url") is "https://webkit.org/"
+PASS clipboardData.getData("TEXT/plain") is "WebKit"
+PASS clipboardData.setData("text/plain", "some text"); clipboardData.items.length is 2
+PASS clipboardData.items[0] is firstItem
+PASS firstItem.kind is "string"
+PASS firstItem.type is "text/uri-list"
+PASS firstItem.getAsString(checkContent(4, "https://webkit.org/")) is undefined
+PASS newSecondItem = clipboardData.items[1]; newSecondItem is not secondItem
+PASS newSecondItem.kind is "string"
+PASS newSecondItem.type is "text/plain"
+PASS newSecondItem.getAsString(checkContent(5, "some text")) is undefined
+PASS actualContent1 is "rock"
+PASS actualContent2 is "https://webkit.org/"
+PASS actualContent3 is "WebKit"
+PASS actualContent4 is "https://webkit.org/"
+PASS actualContent5 is "some text"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-url.html (0 => 222363)
--- trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-url.html (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/datatransfer-items-copy-url.html 2017-09-21 23:10:33 UTC (rev 222363)
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description('This tests copying URL string using dataTransfer.items. To manually test, click on "Copy text" and paste (Command+V on Mac Control+V elsewhere).');
+
+function copyText()
+{
+ document.getElementById('source').focus();
+ document.execCommand('SelectAll', false, null);
+ document.execCommand('Copy', false, null);
+}
+
+function copy(event)
+{
+ clipboardData = event.clipboardData;
+ shouldBe('clipboardData.items.length', '0');
+ shouldBe('clipboardData.setData("text/uri-list", "rock"); clipboardData.items.length', '1');
+ shouldBeEqualToString('initialItem = clipboardData.items[0]; initialItem.kind', 'string');
+ shouldBeEqualToString('initialItem.type', 'text/uri-list');
+ shouldBe('initialItem.getAsFile()', 'null');
+ shouldBe('initialItem.getAsString(checkContent(1, "rock"))', 'undefined');
+
+ shouldThrowErrorName('clipboardData.items.add("paper", "text/uri-list")', 'NotSupportedError');
+ shouldBe('clipboardData.items[0]', 'initialItem');
+ shouldBe('clipboardData.items.clear(); clipboardData.items.length', '0');
+
+ shouldBe('firstItem = clipboardData.items.add("https://webkit.org/", "text/uri-list"); clipboardData.items.length', '1');
+ shouldBe('clipboardData.items[0]', 'firstItem');
+ shouldNotBe('clipboardData.items[0]', 'initialItem');
+ shouldBeEqualToString('firstItem.kind', 'string');
+ shouldBeEqualToString('firstItem.type', 'text/uri-list');
+ shouldBe('firstItem.getAsFile()', 'null');
+ shouldBe('firstItem.getAsString(checkContent(2, "https://webkit.org/"))', 'undefined');
+ shouldBeEqualToString('clipboardData.getData("url")', 'https://webkit.org/');
+ shouldBeEqualToString('clipboardData.getData("text/plain")', '');
+
+ shouldBe('secondItem = clipboardData.items.add("WebKit", "text/PLAIN"); clipboardData.items.length', '2');
+ shouldBe('clipboardData.items[1]', 'secondItem');
+ shouldBeEqualToString('secondItem.kind', 'string');
+ shouldBeEqualToString('secondItem.type', 'text/plain');
+ shouldBe('secondItem.getAsFile()', 'null');
+ shouldBe('secondItem.getAsString(checkContent(3, "WebKit"))', 'undefined');
+ shouldBeEqualToString('clipboardData.getData("url")', 'https://webkit.org/');
+ shouldBeEqualToString('clipboardData.getData("TEXT/plain")', 'WebKit');
+
+ shouldBe('clipboardData.setData("text/plain", "some text"); clipboardData.items.length', '2');
+ shouldBe('clipboardData.items[0]', 'firstItem');
+ shouldBeEqualToString('firstItem.kind', 'string');
+ shouldBeEqualToString('firstItem.type', 'text/uri-list');
+ shouldBe('firstItem.getAsString(checkContent(4, "https://webkit.org/"))', 'undefined');
+ shouldNotBe('newSecondItem = clipboardData.items[1]; newSecondItem', 'secondItem');
+ shouldBeEqualToString('newSecondItem.kind', 'string');
+ shouldBeEqualToString('newSecondItem.type', 'text/plain');
+ shouldBe('newSecondItem.getAsString(checkContent(5, "some text"))', 'undefined');
+}
+
+let count = 0;
+function checkContent(number, expectedContent)
+{
+ count++;
+ return (content) => {
+ const variableName = 'actualContent' + number;
+ window[variableName] = content;
+ shouldBeEqualToString(variableName, expectedContent);
+ count--;
+ if (!count) {
+ document.getElementById('container').style.display = 'none';
+ finishJSTest();
+ }
+ }
+}
+
+if (window.testRunner)
+ window._onload_ = copyText;
+jsTestIsAsync = true;
+successfullyParsed = true;
+
+</script>
+<div id="container">
+ <button _onclick_="copyText();">Copy text</button>
+ <div id="source" _oncopy_="copy(event)" contenteditable="true">hello, world</div>
+</div>
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/editing/pasteboard/datatransfer-items-paste-plaintext.html (222362 => 222363)
--- trunk/LayoutTests/editing/pasteboard/datatransfer-items-paste-plaintext.html 2017-09-21 23:07:27 UTC (rev 222362)
+++ trunk/LayoutTests/editing/pasteboard/datatransfer-items-paste-plaintext.html 2017-09-21 23:10:33 UTC (rev 222363)
@@ -18,6 +18,12 @@
testRunner.execCommand('Paste', null);
}
+function copy(event)
+{
+ event.preventDefault();
+ event.clipboardData.setData('text/plain', 'hello, world');
+}
+
function paste(event)
{
clipboardData = event.clipboardData;
@@ -43,7 +49,7 @@
</script>
<div id="container">
<button _onclick_="copyText();">Copy text</button>
- <div id="source" contenteditable="true" style="display: none">hello, world</div>
+ <div id="source" contenteditable="true" _oncopy_="copy(event)" style="display: none">hello, world</div>
<div id="target" contenteditable="true" _onpaste_="paste(event)"></div>
</div>
<script src=""
Modified: trunk/Source/WebCore/ChangeLog (222362 => 222363)
--- trunk/Source/WebCore/ChangeLog 2017-09-21 23:07:27 UTC (rev 222362)
+++ trunk/Source/WebCore/ChangeLog 2017-09-21 23:10:33 UTC (rev 222363)
@@ -1,3 +1,21 @@
+2017-09-21 Ryosuke Niwa <[email protected]>
+
+ DataTransfer.items should contain text/html and text/uri-list
+ https://bugs.webkit.org/show_bug.cgi?id=176772
+ <rdar://problem/34386899>
+
+ Reviewed by Darin Adler.
+
+ Expose text/html and text/uri-list in dataTransfer.items.
+
+ Tests: editing/pasteboard/datatransfer-items-copy-html.html
+ editing/pasteboard/datatransfer-items-copy-url.html
+
+ * dom/DataTransferItemList.cpp:
+ (WebCore::isSupportedType): Added both MIME types.
+ (WebCore::DataTransferItemList::add): Fixed the bug that new data transfer item was using
+ the original type string instead of the lowercased one.
+
2017-09-21 Per Arne Vollan <[email protected]>
[Win] Compile error, PALHeaderDetection.h not found.
Modified: trunk/Source/WebCore/dom/DataTransferItemList.cpp (222362 => 222363)
--- trunk/Source/WebCore/dom/DataTransferItemList.cpp 2017-09-21 23:07:27 UTC (rev 222362)
+++ trunk/Source/WebCore/dom/DataTransferItemList.cpp 2017-09-21 23:10:33 UTC (rev 222363)
@@ -35,7 +35,9 @@
// FIXME: DataTransfer should filter types itself.
static bool isSupportedType(const String& type)
{
- return type == "text/plain";
+ return type == "text/plain"
+ || type == "text/html"
+ || type == "text/uri-list";
}
DataTransferItemList::DataTransferItemList(DataTransfer& dataTransfer)
@@ -79,7 +81,7 @@
m_dataTransfer.pasteboard().writeString(lowercasedType, data);
ASSERT(m_items);
- m_items->append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), type));
+ m_items->append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), lowercasedType));
return RefPtr<DataTransferItem> { m_items->last().copyRef() };
}