DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (71042f6bc4f6)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
<!DOCTYPE html>
<html>
<head>
  <title>Tests for inline style cache</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none;">

</div>

<div id="editor" contenteditable></div>
<pre id="test">

<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  var editor = document.getElementById("editor");
  editor.focus();

  document.execCommand("defaultParagraphSeparator", false, "div");

  var selection = window.getSelection();

  // #01-01 Typing something after setting some styles should insert some nodes to insert text.
  editor.innerHTML = "beforeafter";
  selection.collapse(editor.firstChild, "before".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  sendString("test");

  is(editor.innerHTML, "before<strike><i><b>test</b></i></strike>after",
     "#01-01 At typing something after setting some styles, should cause inserting some nodes to apply the style");

  // #01-02 Typing something after removing some characters after setting some styles should work as without removing some character.
  // XXX This behavior is different from Chromium.
  editor.innerHTML = "beforeafter";
  selection.collapse(editor.firstChild, "before".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Delete");
  sendString("test");

  is(editor.innerHTML, "before<strike><i><b>test</b></i></strike>fter",
     "#01-02-1 At typing something after Delete after setting style, should cause inserting some nodes to apply the style");

  editor.innerHTML = "beforeafter";
  selection.collapse(editor.firstChild, "before".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Backspace");
  sendString("test");

  is(editor.innerHTML, "befor<strike><i><b>test</b></i></strike>after",
     "#01-02-2 At typing something after Backspace after setting style, should cause inserting some nodes to apply the style");

  // #01-03 Typing Enter after setting some styles should not ignore the styles.
  editor.innerHTML = "beforeafter";
  selection.collapse(editor.firstChild, "before".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<div>before</div><div><strike><i><b>test</b></i></strike>after</div>",
     "#01-03-1 Typing Enter after setting style should not ignore the styles");

  editor.innerHTML = "<p>beforeafter</p>";
  selection.collapse(editor.firstChild.firstChild, "before".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<p>before</p><p><strike><i><b>test</b></i></strike>after</p>",
     "#01-03-2 Typing Enter after setting style should not ignore the styles");

  // #02-01 Replacing text with typing some text after setting some styles should work as just inserting text.
  // XXX Chromium works as expected.
  editor.innerHTML = "beforeselectionafter";
  selection.collapse(editor.firstChild, "before".length);
  selection.extend(editor.firstChild, "beforeselection".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  sendString("test");

  // XXX <strike> is not handled correctly in this case.
  todo_is(editor.innerHTML, "before<strike><i><b>test</b></i></strike>after",
          "#02-01 At replacing \"selection\" after setting some styles, should keep the styles at inserting text");
  // XXX For testing current (buggy) behavior for now.
  is(editor.innerHTML, "before<i><b>test</b></i><strike><i><b></b></i></strike>after",
     "#02-01 At replacing \"selection\" after setting some styles, should keep the styles");

  // #02-02 Inserting text after removing selected text after setting some styles should not keep the styles.
  // XXX Chromium keeps the style.
  editor.innerHTML = "beforeselectionafter";
  selection.collapse(editor.firstChild, "before".length);
  selection.extend(editor.firstChild, "beforeselection".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Backspace");
  sendString("test");

  is(editor.innerHTML, "beforetestafter",
     "#02-02 After removing \"selection\" after setting some styles, should not keep the styles");

  // #02-03 Inserting text after replacing selected text after setting some styles should keep the styles.
  editor.innerHTML = "beforeselectionafter";
  selection.collapse(editor.firstChild, "before".length);
  selection.extend(editor.firstChild, "beforeselection".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Enter");
  sendString("test");

  // XXX <strike> is not handled correctly in this case.
  todo_is(editor.innerHTML, "<div>before</div><div><strike><i><b>test</b></i></strike>after</div>",
          "#02-03-1 Typing Enter after setting style to selected text should keep the styles");
  // XXX For testing current (buggy) behavior for now.
  is(editor.innerHTML, "<div>before</div><div><i><b>test</b></i>after</div>",
     "#02-03-1 Typing Enter after setting style to selected text should keep the styles");

  editor.innerHTML = "<p>beforeselectionafter</p>";
  selection.collapse(editor.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild, "beforeselection".length);
  document.execCommand("bold");
  document.execCommand("italic");
  document.execCommand("strikethrough");
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<p>before</p><p><strike><i><b>test</b></i></strike>after</p>",
     "#02-03-2 Typing Enter after setting style to selected text should keep the styles");

  // #03-01 Replacing in <b style="font-weight: normal;"> shouldn't cause new <b>.
  editor.innerHTML = "<b style=\"font-weight: normal;\">beforeselectionafter</b>";
  selection.collapse(editor.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild, "beforeselection".length);
  sendString("test");

  is(editor.innerHTML, "<b style=\"font-weight: normal;\">beforetestafter</b>",
     "#03-01 Replacing text in styled inline elements should respect the styles");

  // #03-02 Typing something after removing selected text in <b style="font-weight: normal;"> shouldn't cause new <b>.
  editor.innerHTML = "<b style=\"font-weight: normal;\">beforeselectionafter</b>";
  selection.collapse(editor.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild, "beforeselection".length);
  synthesizeKey("KEY_Backspace");
  sendString("test");

  is(editor.innerHTML, "<b style=\"font-weight: normal;\">beforetestafter</b>",
     "#03-02 Inserting text after removing text in styled inline elements should respect the styles");

  // #03-03 Typing something after typing Enter at selected text in <b style="font-weight: normal;"> shouldn't cause new <b>.
  editor.innerHTML = "<b style=\"font-weight: normal;\">beforeselectionafter</b>";
  selection.collapse(editor.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild, "beforeselection".length);
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<div><b style=\"font-weight: normal;\">before</b></div><div><b style=\"font-weight: normal;\">testafter</b></div>",
     "#03-03-1 Inserting text after typing Enter at selected text in styled inline elements should respect the styles");

  editor.innerHTML = "<p><b style=\"font-weight: normal;\">beforeselectionafter</b></p>";
  selection.collapse(editor.firstChild.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild.firstChild, "beforeselection".length);
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<p><b style=\"font-weight: normal;\">before</b></p><p><b style=\"font-weight: normal;\">testafter</b></p>",
     "#03-03-2 Inserting text after typing Enter at selected text in styled inline elements should respect the styles");

  // #04-01 Replacing in some styled inline elements shouldn't cause new same elements.
  editor.innerHTML = "<strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">beforeselectionafter</b></i></strike>";
  selection.collapse(editor.firstChild.firstChild.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild.firstChild.firstChild, "beforeselection".length);
  sendString("test");

  is(editor.innerHTML, "<strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">beforetestafter</b></i></strike>",
     "#04-01 Replacing text in styled inline elements should respect the styles");

  // #04-02 Typing something after removing selected text in some styled inline elements shouldn't cause new same elements.
  editor.innerHTML = "<strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">beforeselectionafter</b>";
  selection.collapse(editor.firstChild.firstChild.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild.firstChild.firstChild, "beforeselection".length);
  synthesizeKey("KEY_Backspace");
  sendString("test");

  is(editor.innerHTML, "<strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">beforetestafter</b></i></strike>",
     "#04-02 Inserting text after removing text in styled inline elements should respect the styles");

  // #04-03 Typing something after typing Enter at selected text in some styled inline elements shouldn't cause new same elements.
  editor.innerHTML = "<strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">beforeselectionafter</b>";
  selection.collapse(editor.firstChild.firstChild.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild.firstChild.firstChild, "beforeselection".length);
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<div><strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">before</b></i></strike></div><div><strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">testafter</b></i></strike></div>",
     "#04-03-1 Inserting text after typing Enter at selected text in styled inline elements should respect the styles");

  editor.innerHTML = "<p><strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">beforeselectionafter</b></p>";
  selection.collapse(editor.firstChild.firstChild.firstChild.firstChild.firstChild, "before".length);
  selection.extend(editor.firstChild.firstChild.firstChild.firstChild.firstChild, "beforeselection".length);
  synthesizeKey("KEY_Enter");
  sendString("test");

  is(editor.innerHTML, "<p><strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">before</b></i></strike></p><p><strike style=\"text-decoration: none;\"><i style=\"font-style: normal;\"><b style=\"font-weight: normal;\">testafter</b></i></strike></p>",
     "#04-03-2 Inserting text after typing Enter at selected text in styled inline elements should respect the styles");

  SimpleTest.finish();
});
</script>
</pre>
</body>
</html>