Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <html> |
michael@0 | 2 | |
michael@0 | 3 | <head> |
michael@0 | 4 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
michael@0 | 5 | |
michael@0 | 6 | <script type="application/javascript" |
michael@0 | 7 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | <script type="application/javascript" |
michael@0 | 9 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <script type="application/javascript" |
michael@0 | 11 | src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> |
michael@0 | 12 | </head> |
michael@0 | 13 | |
michael@0 | 14 | <body> |
michael@0 | 15 | <span id="text" style="font-size: 40px;">Some Text</span> |
michael@0 | 16 | |
michael@0 | 17 | <input id="input" value="Drag Me"> |
michael@0 | 18 | <textarea id="textarea">Some Text To Drag</textarea> |
michael@0 | 19 | <p id="contenteditable" contenteditable="true">This is some <b id="bold">editable</b> text.</p> |
michael@0 | 20 | <p id="nestedce" contenteditable="true"><span id="first"> </span>First letter <span id="noneditable" contenteditable="false">Middle</span> Last part</p> |
michael@0 | 21 | |
michael@0 | 22 | <script type="application/javascript"> |
michael@0 | 23 | |
michael@0 | 24 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 25 | |
michael@0 | 26 | // This listener allows us to clear the default data for the selection added for the drag. |
michael@0 | 27 | var shouldClear = false; |
michael@0 | 28 | window.addEventListener("dragstart", function (event) { if (shouldClear) event.dataTransfer.clearData() }, true); |
michael@0 | 29 | |
michael@0 | 30 | function doTest() |
michael@0 | 31 | { |
michael@0 | 32 | const htmlContextData = { type: 'text/_moz_htmlcontext', |
michael@0 | 33 | data: '<html><body></body></html>' }; |
michael@0 | 34 | const htmlInfoData = { type: 'text/_moz_htmlinfo', data: '0,0' }; |
michael@0 | 35 | const htmlData = { type: 'text/html', data: '<span id="text" style="font-size: 40px;">Some Text</span>' }; |
michael@0 | 36 | |
michael@0 | 37 | const htmlContextDataEditable = { type: 'text/_moz_htmlcontext', |
michael@0 | 38 | data: '<html><body><p id="contenteditable" contenteditable="true"></p></body></html>' }; |
michael@0 | 39 | |
michael@0 | 40 | var text = document.getElementById("text"); |
michael@0 | 41 | var input = document.getElementById("input"); |
michael@0 | 42 | var contenteditable = document.getElementById("contenteditable"); |
michael@0 | 43 | |
michael@0 | 44 | var selection = window.getSelection(); |
michael@0 | 45 | |
michael@0 | 46 | // -------- Test dragging regular text |
michael@0 | 47 | selection.selectAllChildren(text); |
michael@0 | 48 | var result = synthesizeDragStart(text, [[htmlContextData, htmlInfoData, htmlData, |
michael@0 | 49 | {type: "text/plain", data: "Some Text"}]], window, 40, 10); |
michael@0 | 50 | ok(!result, "Test dragging regular text"); |
michael@0 | 51 | |
michael@0 | 52 | // -------- Test dragging text from an <input> |
michael@0 | 53 | input.setSelectionRange(1, 4); |
michael@0 | 54 | result = synthesizeDragStart(input, [[{type: "text/plain", data: "rag"}]], window, 25, 6); |
michael@0 | 55 | ok(!result, "Test dragging input"); |
michael@0 | 56 | |
michael@0 | 57 | // -------- Test dragging text from a <textarea> |
michael@0 | 58 | textarea.setSelectionRange(1, 7); |
michael@0 | 59 | result = synthesizeDragStart(textarea, [[{type: "text/plain", data: "ome Te"}]], window, 25, 6); |
michael@0 | 60 | ok(!result, "Test dragging textarea"); |
michael@0 | 61 | textarea.blur(); |
michael@0 | 62 | |
michael@0 | 63 | // -------- Test dragging text from a contenteditable |
michael@0 | 64 | selection.selectAllChildren(contenteditable.childNodes[1]); |
michael@0 | 65 | result = synthesizeDragStart(contenteditable.childNodes[1], |
michael@0 | 66 | [[htmlContextDataEditable, htmlInfoData, |
michael@0 | 67 | {type: 'text/html', data: '<b id="bold">editable</b>' }, |
michael@0 | 68 | {type: "text/plain", data: "editable"}]], window, 5, 6); |
michael@0 | 69 | ok(!result, "Test dragging contenteditable"); |
michael@0 | 70 | contenteditable.blur(); |
michael@0 | 71 | |
michael@0 | 72 | // -------- Test dragging regular text of text/html to <input> |
michael@0 | 73 | |
michael@0 | 74 | selection.selectAllChildren(text); |
michael@0 | 75 | input.value = ""; |
michael@0 | 76 | synthesizeDrop(text, input, [], "copy"); |
michael@0 | 77 | is(input.value, "Some Text", "Drag text/html onto input"); |
michael@0 | 78 | |
michael@0 | 79 | // -------- Test dragging regular text of text/html to disabled <input> |
michael@0 | 80 | |
michael@0 | 81 | selection.selectAllChildren(text); |
michael@0 | 82 | input.value = ""; |
michael@0 | 83 | input.disabled = true; |
michael@0 | 84 | synthesizeDrop(text, input, [], "copy"); |
michael@0 | 85 | is(input.value, "", "Drag text/html onto disabled input"); |
michael@0 | 86 | input.disabled = false; |
michael@0 | 87 | |
michael@0 | 88 | // -------- Test dragging regular text of text/html to readonly <input> |
michael@0 | 89 | |
michael@0 | 90 | selection.selectAllChildren(text); |
michael@0 | 91 | input.readOnly = true; |
michael@0 | 92 | synthesizeDrop(text, input, [], "copy"); |
michael@0 | 93 | is(input.value, "", "Drag text/html onto readonly input"); |
michael@0 | 94 | input.readOnly = false; |
michael@0 | 95 | |
michael@0 | 96 | // -------- Test dragging regular text of text/html to <input>. This sets |
michael@0 | 97 | // shouldClear to true so that the default drag data is not present |
michael@0 | 98 | // and we can use the data passed to synthesizeDrop. This allows |
michael@0 | 99 | // testing of a drop with just text/html. |
michael@0 | 100 | shouldClear = true; |
michael@0 | 101 | selection.selectAllChildren(text); |
michael@0 | 102 | input.value = ""; |
michael@0 | 103 | synthesizeDrop(text, input, [[{type: "text/html", data: "Some <b>Bold<b> Text"}]], "copy"); |
michael@0 | 104 | is(input.value, "", "Drag text/html onto input"); |
michael@0 | 105 | |
michael@0 | 106 | // -------- Test dragging regular text of text/plain and text/html to <input> |
michael@0 | 107 | |
michael@0 | 108 | selection.selectAllChildren(text); |
michael@0 | 109 | input.value = ""; |
michael@0 | 110 | synthesizeDrop(text, input, [[{type: "text/html", data: "Some <b>Bold<b> Text"}, |
michael@0 | 111 | {type: "text/plain", data: "Some Plain Text"}]], "copy"); |
michael@0 | 112 | is(input.value, "Some Plain Text", "Drag text/html and text/plain onto input"); |
michael@0 | 113 | |
michael@0 | 114 | // -------- Test dragging regular text of text/plain to <textarea> |
michael@0 | 115 | |
michael@0 | 116 | // XXXndeakin Can't test textareas due to some event handling issue |
michael@0 | 117 | // selection.selectAllChildren(text); |
michael@0 | 118 | // synthesizeDrop(text, textarea, [[{type: "text/plain", data: "Somewhat Longer Text"}]], "copy"); |
michael@0 | 119 | // is(textarea.value, "Somewhat Longer Text", "Drag text/plain onto textarea"); |
michael@0 | 120 | |
michael@0 | 121 | // -------- Test dragging special text type of text/plain to contenteditable |
michael@0 | 122 | |
michael@0 | 123 | selection.selectAllChildren(text); |
michael@0 | 124 | synthesizeDrop(text, input, [[{type: "text/x-moz-text-internal", data: "Some Special Text"}]], "copy"); |
michael@0 | 125 | is(input.value, "Some Plain Text", "Drag text/x-moz-text-internal onto input"); |
michael@0 | 126 | |
michael@0 | 127 | // -------- Test dragging regular text of text/plain to contenteditable |
michael@0 | 128 | |
michael@0 | 129 | selection.selectAllChildren(text); |
michael@0 | 130 | synthesizeDrop(text, contenteditable, [[{type: "text/plain", data: "Sample Text"}]], "copy"); |
michael@0 | 131 | is(contenteditable.childNodes.length, 3, "Drag text/plain onto contenteditable child nodes"); |
michael@0 | 132 | is(contenteditable.textContent, "This is some editable text.Sample Text", |
michael@0 | 133 | "Drag text/plain onto contenteditable text"); |
michael@0 | 134 | |
michael@0 | 135 | // -------- Test dragging regular text of text/html to contenteditable |
michael@0 | 136 | |
michael@0 | 137 | selection.selectAllChildren(text); |
michael@0 | 138 | synthesizeDrop(text, contenteditable, [[{type: "text/html", data: "Sample <i>Italic</i> Text"}]], "copy"); |
michael@0 | 139 | is(contenteditable.childNodes.length, 6, "Drag text/html onto contenteditable child nodes"); |
michael@0 | 140 | is(contenteditable.childNodes[4].tagName, "I", "Drag text/html onto contenteditable italic"); |
michael@0 | 141 | is(contenteditable.childNodes[4].textContent, "Italic", "Drag text/html onto contenteditable italic text"); |
michael@0 | 142 | |
michael@0 | 143 | // -------- Test dragging contenteditable to <input> |
michael@0 | 144 | |
michael@0 | 145 | selection.selectAllChildren(document.getElementById("bold")); |
michael@0 | 146 | synthesizeDrop(bold, input, [[{type: "text/html", data: "<b>editable</b>"}, |
michael@0 | 147 | {type: "text/plain", data: "editable"}]], "copy"); |
michael@0 | 148 | is(input.value, "Some Plain Texteditable", "Move text/html and text/plain from contenteditable onto input"); |
michael@0 | 149 | |
michael@0 | 150 | // -------- Test dragging contenteditable to contenteditable |
michael@0 | 151 | |
michael@0 | 152 | shouldClear = false; |
michael@0 | 153 | |
michael@0 | 154 | selection.selectAllChildren(contenteditable.childNodes[4]); |
michael@0 | 155 | synthesizeDrop(contenteditable.childNodes[4], contenteditable, [], "copy"); |
michael@0 | 156 | is(contenteditable.childNodes.length, 7, "Move text/html and text/plain from contenteditable onto itself child nodes"); |
michael@0 | 157 | is(contenteditable.childNodes[6].tagName, "I", "Move text/html and text/plain from contenteditable onto itself italic"); |
michael@0 | 158 | is(contenteditable.childNodes[6].textContent, "Italic", "Move text/html and text/plain from contenteditable onto itself text"); |
michael@0 | 159 | |
michael@0 | 160 | // We'd test 'move' here as well as 'copy', but that requires knowledge of |
michael@0 | 161 | // the source of the drag which drag simulation doesn't provide. |
michael@0 | 162 | |
michael@0 | 163 | // -------- Test dragging non-editable nested inside contenteditable to contenteditable |
michael@0 | 164 | |
michael@0 | 165 | input.focus(); // this resets some state in the selection otherwise an inexplicable error occurs calling selectAllChildren. |
michael@0 | 166 | input.blur(); |
michael@0 | 167 | |
michael@0 | 168 | var nonEditable = document.getElementById("noneditable"); |
michael@0 | 169 | selection.selectAllChildren(nonEditable); |
michael@0 | 170 | synthesizeDrop(nonEditable, document.getElementById("first"), [], "copy"); |
michael@0 | 171 | is(document.getElementById("nestedce").textContent, " MiddleFirst letter Middle Last part", |
michael@0 | 172 | "Drag non-editable text/html onto contenteditable text"); |
michael@0 | 173 | |
michael@0 | 174 | SimpleTest.finish(); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | SimpleTest.waitForFocus(doTest); |
michael@0 | 178 | |
michael@0 | 179 | </script> |
michael@0 | 180 | </body> |
michael@0 | 181 | </html> |