Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=166235 |
michael@0 | 5 | https://bugzilla.mozilla.org/show_bug.cgi?id=816298 |
michael@0 | 6 | --> |
michael@0 | 7 | <head> |
michael@0 | 8 | <title>Test for Bug 166235</title> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=166235">Mozilla Bug 166235 and Bug 816298</a> |
michael@0 | 14 | <p id="test0">This text should be copied.</p> |
michael@0 | 15 | <p id="test1">This text should<span style="-moz-user-select: none;"> NOT</span> be copied.</p> |
michael@0 | 16 | <p id="test2">This<span style="-moz-user-select: none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p> |
michael@0 | 17 | <p id="test3">This text should<span style="-moz-user-select: -moz-none;"> NOT</span> be copied.</p> |
michael@0 | 18 | <p id="test4">This<span style="-moz-user-select: -moz-none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p> |
michael@0 | 19 | <p id="test5">This<span style="-moz-user-select: all"> text<span style="-moz-user-select: none"> should</span></span> be copied.</p> |
michael@0 | 20 | <div id="content" style="display: none"> |
michael@0 | 21 | |
michael@0 | 22 | </div> |
michael@0 | 23 | <textarea id="input"></textarea> |
michael@0 | 24 | <pre id="test"> |
michael@0 | 25 | <script type="application/javascript"> |
michael@0 | 26 | "use strict"; |
michael@0 | 27 | |
michael@0 | 28 | /** Test for Bug 166235 **/ |
michael@0 | 29 | var Cc = SpecialPowers.Cc; |
michael@0 | 30 | var Ci = SpecialPowers.Ci; |
michael@0 | 31 | |
michael@0 | 32 | var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) |
michael@0 | 33 | .getInterface(SpecialPowers.Ci.nsIWebNavigation) |
michael@0 | 34 | |
michael@0 | 35 | var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell); |
michael@0 | 36 | |
michael@0 | 37 | var documentViewer = docShell.contentViewer |
michael@0 | 38 | .QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit); |
michael@0 | 39 | |
michael@0 | 40 | var clipboard = Cc["@mozilla.org/widget/clipboard;1"] |
michael@0 | 41 | .getService(SpecialPowers.Ci.nsIClipboard); |
michael@0 | 42 | |
michael@0 | 43 | var textarea = SpecialPowers.wrap(document.getElementById('input')); |
michael@0 | 44 | |
michael@0 | 45 | function getLoadContext() { |
michael@0 | 46 | return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 47 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 48 | .QueryInterface(Ci.nsILoadContext); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function copyChildrenToClipboard(id) { |
michael@0 | 52 | textarea.blur(); |
michael@0 | 53 | clipboard.emptyClipboard(1); |
michael@0 | 54 | window.getSelection().selectAllChildren(document.getElementById(id)); |
michael@0 | 55 | documentViewer.copySelection(); |
michael@0 | 56 | |
michael@0 | 57 | is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true); |
michael@0 | 58 | is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true); |
michael@0 | 59 | } |
michael@0 | 60 | function getClipboardData(mime) { |
michael@0 | 61 | var transferable = Cc['@mozilla.org/widget/transferable;1'] |
michael@0 | 62 | .createInstance(SpecialPowers.Ci.nsITransferable); |
michael@0 | 63 | transferable.init(getLoadContext()); |
michael@0 | 64 | transferable.addDataFlavor(mime); |
michael@0 | 65 | clipboard.getData(transferable, 1); |
michael@0 | 66 | var data = SpecialPowers.createBlankObject(); |
michael@0 | 67 | transferable.getTransferData(mime, data, {}) ; |
michael@0 | 68 | return SpecialPowers.wrap(data); |
michael@0 | 69 | } |
michael@0 | 70 | function testClipboardValue(mime, expected, test) { |
michael@0 | 71 | var data = getClipboardData(mime); |
michael@0 | 72 | is (data.value == null ? data.value : |
michael@0 | 73 | data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data, |
michael@0 | 74 | expected, |
michael@0 | 75 | mime + " value in the clipboard"); |
michael@0 | 76 | return data.value; |
michael@0 | 77 | } |
michael@0 | 78 | function testPasteText(expected, test) { |
michael@0 | 79 | textarea.value=""; |
michael@0 | 80 | textarea.focus(); |
michael@0 | 81 | textarea.editor.paste(1); |
michael@0 | 82 | is(textarea.value, expected, test + ": textarea paste"); |
michael@0 | 83 | } |
michael@0 | 84 | function testInnerHTML(id, expected) { |
michael@0 | 85 | var value = document.getElementById(id).innerHTML; |
michael@0 | 86 | is(value, expected, id + ".innerHTML"); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | // expected results for Selection.toString() |
michael@0 | 90 | var originalStrings = [ |
michael@0 | 91 | 'This text should be copied.', |
michael@0 | 92 | 'This text should be copied.', |
michael@0 | 93 | 'This text should be copied.', |
michael@0 | 94 | 'This text should be copied.', |
michael@0 | 95 | 'This text should be copied.', |
michael@0 | 96 | 'This text should be copied.' |
michael@0 | 97 | ]; |
michael@0 | 98 | |
michael@0 | 99 | // expected results for clipboard text/html |
michael@0 | 100 | var clipboardHTML = [ |
michael@0 | 101 | '<p id=\"test0\">This text should be copied.</p>', |
michael@0 | 102 | '<p id=\"test1\">This text should be copied.</p>', |
michael@0 | 103 | '<p id=\"test2\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>', |
michael@0 | 104 | '<p id=\"test3\">This text should be copied.</p>', |
michael@0 | 105 | '<p id=\"test4\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>', |
michael@0 | 106 | '<p id=\"test5\">This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.</p>', |
michael@0 | 107 | ]; |
michael@0 | 108 | |
michael@0 | 109 | // expected results for clipboard text/unicode |
michael@0 | 110 | var clipboardUnicode = [ |
michael@0 | 111 | 'This text should be copied.', |
michael@0 | 112 | 'This text should be copied.', |
michael@0 | 113 | 'This text should be copied.', |
michael@0 | 114 | 'This text should be copied.', |
michael@0 | 115 | 'This text should be copied.', |
michael@0 | 116 | 'This text should be copied.' |
michael@0 | 117 | ]; |
michael@0 | 118 | |
michael@0 | 119 | // expected results for .innerHTML |
michael@0 | 120 | var innerHTMLStrings = [ |
michael@0 | 121 | 'This text should be copied.', |
michael@0 | 122 | 'This text should<span style=\"-moz-user-select: none;\"> NOT</span> be copied.', |
michael@0 | 123 | 'This<span style=\"-moz-user-select: none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.', |
michael@0 | 124 | 'This text should<span style=\"-moz-user-select: -moz-none;\"> NOT</span> be copied.', |
michael@0 | 125 | 'This<span style=\"-moz-user-select: -moz-none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.', |
michael@0 | 126 | 'This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.', |
michael@0 | 127 | ]; |
michael@0 | 128 | |
michael@0 | 129 | // expected results for pasting into a TEXTAREA |
michael@0 | 130 | var textareaStrings = [ |
michael@0 | 131 | 'This text should be copied.', |
michael@0 | 132 | 'This text should be copied.', |
michael@0 | 133 | 'This text should be copied.', |
michael@0 | 134 | 'This text should be copied.', |
michael@0 | 135 | 'This text should be copied.', |
michael@0 | 136 | 'This text should be copied.' |
michael@0 | 137 | ]; |
michael@0 | 138 | |
michael@0 | 139 | for (var i = 0; i < originalStrings.length; i++) { |
michael@0 | 140 | var id = 'test' + i; |
michael@0 | 141 | copyChildrenToClipboard(id); |
michael@0 | 142 | is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()'); |
michael@0 | 143 | testClipboardValue("text/html", clipboardHTML[i], id); |
michael@0 | 144 | testClipboardValue("text/unicode", clipboardUnicode[i], id); |
michael@0 | 145 | testInnerHTML(id, innerHTMLStrings[i]); |
michael@0 | 146 | testPasteText(textareaStrings[i], id + '.innerHTML'); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | </script> |
michael@0 | 150 | </pre> |
michael@0 | 151 | </body> |
michael@0 | 152 | </html> |