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 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | // Test CSS state is correctly determined and the corresponding suggestions are |
michael@0 | 8 | // displayed. i.e. CSS property suggestions are shown when cursor is like: |
michael@0 | 9 | // ```style="di|"``` where | is the cursor; And CSS value suggestion is |
michael@0 | 10 | // displayed when the cursor is like: ```style="display:n|"``` properly. No |
michael@0 | 11 | // suggestions should ever appear when the attribute is not a style attribute. |
michael@0 | 12 | // The correctness and cycling of the suggestions is covered in the ruleview |
michael@0 | 13 | // tests. |
michael@0 | 14 | |
michael@0 | 15 | const TEST_URL = TEST_URL_ROOT + "doc_markup_edit.html"; |
michael@0 | 16 | // test data format : |
michael@0 | 17 | // [ |
michael@0 | 18 | // what key to press, |
michael@0 | 19 | // expected input box value after keypress, |
michael@0 | 20 | // expected input.selectionStart, |
michael@0 | 21 | // expected input.selectionEnd, |
michael@0 | 22 | // is popup expected to be open ? |
michael@0 | 23 | // ] |
michael@0 | 24 | const TEST_DATA = [ |
michael@0 | 25 | ['s', 's', 1, 1, false], |
michael@0 | 26 | ['t', 'st', 2, 2, false], |
michael@0 | 27 | ['y', 'sty', 3, 3, false], |
michael@0 | 28 | ['l', 'styl', 4, 4, false], |
michael@0 | 29 | ['e', 'style', 5, 5, false], |
michael@0 | 30 | ['=', 'style=', 6, 6, false], |
michael@0 | 31 | ['"', 'style="', 7, 7, false], |
michael@0 | 32 | ['d', 'style="direction', 8, 16, true], |
michael@0 | 33 | ['VK_DOWN', 'style="display', 8, 14, true], |
michael@0 | 34 | ['VK_TAB', 'style="display', 14, 14, true], |
michael@0 | 35 | ['VK_TAB', 'style="dominant-baseline', 24, 24, true], |
michael@0 | 36 | ['VK_TAB', 'style="direction', 16, 16, true], |
michael@0 | 37 | ['click_1', 'style="display', 14, 14, false], |
michael@0 | 38 | [':', 'style="display:-moz-box', 15, 23, true], |
michael@0 | 39 | ['n', 'style="display:none', 16, 19, false], |
michael@0 | 40 | ['VK_BACK_SPACE', 'style="display:n', 16, 16, false], |
michael@0 | 41 | ['VK_BACK_SPACE', 'style="display:', 15, 15, false], |
michael@0 | 42 | [' ', 'style="display: -moz-box', 16, 24, true], |
michael@0 | 43 | [' ', 'style="display: -moz-box', 17, 25, true], |
michael@0 | 44 | ['i', 'style="display: inherit', 18, 24, true], |
michael@0 | 45 | ['VK_RIGHT', 'style="display: inherit', 24, 24, false], |
michael@0 | 46 | [';', 'style="display: inherit;', 25, 25, false], |
michael@0 | 47 | [' ', 'style="display: inherit; ', 26, 26, false], |
michael@0 | 48 | [' ', 'style="display: inherit; ', 27, 27, false], |
michael@0 | 49 | ['VK_LEFT', 'style="display: inherit; ', 26, 26, false], |
michael@0 | 50 | ['c', 'style="display: inherit; caption-side ', 27, 38, true], |
michael@0 | 51 | ['o', 'style="display: inherit; color ', 28, 31, true], |
michael@0 | 52 | ['VK_RIGHT', 'style="display: inherit; color ', 31, 31, false], |
michael@0 | 53 | [' ', 'style="display: inherit; color ', 32, 32, false], |
michael@0 | 54 | ['c', 'style="display: inherit; color c ', 33, 33, false], |
michael@0 | 55 | ['VK_BACK_SPACE', 'style="display: inherit; color ', 32, 32, false], |
michael@0 | 56 | [':', 'style="display: inherit; color :aliceblue ', 33, 42, true], |
michael@0 | 57 | ['c', 'style="display: inherit; color :cadetblue ', 34, 42, true], |
michael@0 | 58 | ['VK_DOWN', 'style="display: inherit; color :chartreuse ', 34, 43, true], |
michael@0 | 59 | ['VK_RIGHT', 'style="display: inherit; color :chartreuse ', 43, 43, false], |
michael@0 | 60 | [' ', 'style="display: inherit; color :chartreuse !important; ', 44, 55, true], |
michael@0 | 61 | ['!', 'style="display: inherit; color :chartreuse !important; ', 45, 55, false], |
michael@0 | 62 | ['VK_RIGHT', 'style="display: inherit; color :chartreuse !important; ', 55, 55, false], |
michael@0 | 63 | ['VK_RETURN', 'style="display: inherit; color :chartreuse !important;"', -1, -1, false] |
michael@0 | 64 | ]; |
michael@0 | 65 | |
michael@0 | 66 | let test = asyncTest(function*() { |
michael@0 | 67 | info("Opening the inspector on the test URL"); |
michael@0 | 68 | let {inspector} = yield addTab(TEST_URL).then(openInspector); |
michael@0 | 69 | |
michael@0 | 70 | yield inspector.markup.expandAll(); |
michael@0 | 71 | |
michael@0 | 72 | let node = getContainerForRawNode("#node14", inspector).editor; |
michael@0 | 73 | let attr = node.newAttr; |
michael@0 | 74 | attr.focus(); |
michael@0 | 75 | EventUtils.sendKey("return", inspector.panelWin); |
michael@0 | 76 | let editor = inplaceEditor(attr); |
michael@0 | 77 | |
michael@0 | 78 | for (let i = 0; i < TEST_DATA.length; i ++) { |
michael@0 | 79 | yield enterData(i, editor, inspector); |
michael@0 | 80 | checkData(i, editor, inspector); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | while (inspector.markup.undo.canUndo()) { |
michael@0 | 84 | yield undoChange(inspector); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | yield inspector.once("inspector-updated"); |
michael@0 | 88 | }); |
michael@0 | 89 | |
michael@0 | 90 | function enterData(index, editor, inspector) { |
michael@0 | 91 | let [key] = TEST_DATA[index]; |
michael@0 | 92 | info("Entering test data " + index + ": " + key + ", expecting: [" + TEST_DATA[index].slice(1) + "]"); |
michael@0 | 93 | |
michael@0 | 94 | let def = promise.defer(); |
michael@0 | 95 | |
michael@0 | 96 | if (/click_[0-9]/.test(key)) { |
michael@0 | 97 | let nb = +key.split("_")[1]; |
michael@0 | 98 | info("Clicking on item " + nb + " in the list"); |
michael@0 | 99 | editor.once("after-suggest", () => { |
michael@0 | 100 | executeSoon(def.resolve); |
michael@0 | 101 | }); |
michael@0 | 102 | editor.popup._list.childNodes[nb].click(); |
michael@0 | 103 | editor.input.blur(); |
michael@0 | 104 | return def.promise; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | if (/(down|left|right|back_space|return)/ig.test(key)) { |
michael@0 | 108 | info("Adding event listener for down|left|right|back_space|return keys"); |
michael@0 | 109 | editor.input.addEventListener("keypress", function onKeypress() { |
michael@0 | 110 | if (editor.input) { |
michael@0 | 111 | editor.input.removeEventListener("keypress", onKeypress); |
michael@0 | 112 | } |
michael@0 | 113 | executeSoon(def.resolve); |
michael@0 | 114 | }); |
michael@0 | 115 | } else { |
michael@0 | 116 | editor.once("after-suggest", () => { |
michael@0 | 117 | executeSoon(def.resolve); |
michael@0 | 118 | }); |
michael@0 | 119 | } |
michael@0 | 120 | EventUtils.synthesizeKey(key, {}, inspector.panelWin); |
michael@0 | 121 | |
michael@0 | 122 | return def.promise; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function checkData(index, editor, inspector) { |
michael@0 | 126 | let [key, completion, selStart, selEnd, popupOpen] = TEST_DATA[index]; |
michael@0 | 127 | info("Test data " + index + " entered. Checking state."); |
michael@0 | 128 | |
michael@0 | 129 | if (selEnd != -1) { |
michael@0 | 130 | is(editor.input.value, completion, "Completed value is correct"); |
michael@0 | 131 | is(editor.input.selectionStart, selStart, "Selection start position is correct"); |
michael@0 | 132 | is(editor.input.selectionEnd, selEnd, "Selection end position is correct"); |
michael@0 | 133 | if (popupOpen) { |
michael@0 | 134 | ok(editor.popup.isOpen, "Popup is open"); |
michael@0 | 135 | } else { |
michael@0 | 136 | ok(editor.popup._panel.state != "open" && editor.popup._panel.state != "showing", |
michael@0 | 137 | "Popup is closed"); |
michael@0 | 138 | } |
michael@0 | 139 | } else { |
michael@0 | 140 | let editor = getContainerForRawNode("#node14", inspector).editor; |
michael@0 | 141 | let attr = editor.attrs["style"].querySelector(".editable"); |
michael@0 | 142 | is(attr.textContent, completion, "Correct value is persisted after pressing Enter"); |
michael@0 | 143 | } |
michael@0 | 144 | } |