| OLD | NEW |
| 1 description("Test to make sure we can toggle text decorations correctly. The fi
rst three tests give different result on mac only.") | 1 description("Test to make sure we can toggle text decorations correctly. The fi
rst three tests give different result on mac only.") |
| 2 | 2 |
| 3 var testContainer = document.createElement("div"); | 3 var testContainer = document.createElement("div"); |
| 4 testContainer.contentEditable = true; | 4 testContainer.contentEditable = true; |
| 5 document.body.appendChild(testContainer); | 5 document.body.appendChild(testContainer); |
| 6 | 6 |
| 7 function testSingleToggle(toggleCommand, initialContents, expectedContents) | 7 function testSingleToggle(toggleCommand, initialContents, expectedContents) |
| 8 { | 8 { |
| 9 testContainer.innerHTML = initialContents; | 9 testContainer.innerHTML = initialContents; |
| 10 window.getSelection().selectAllChildren(testContainer); | 10 window.getSelection().selectAllChildren(testContainer); |
| 11 document.execCommand(toggleCommand, false, null); | 11 document.execCommand(toggleCommand, false, null); |
| 12 var action = 'one ' + toggleCommand + ' command converted "' + initialConten
ts + '" to "' + expectedContents; | 12 var actualContents = testContainer.innerHTML; |
| 13 if (testContainer.innerHTML === expectedContents) | 13 var action = 'one ' + toggleCommand + ' command converted "' + initialConten
ts + '" to "' + actualContents; |
| 14 if (actualContents === expectedContents) |
| 14 testPassed(action); | 15 testPassed(action); |
| 15 else | 16 else |
| 16 testFailed(action + '", expected "' + expectedContents + '"'); | 17 testFailed(action + '", expected "' + expectedContents + '"'); |
| 17 } | 18 } |
| 18 | 19 |
| 19 platforms = ['mac', 'win', 'unix', 'android']; | 20 platforms = ['mac', 'win', 'unix', 'android']; |
| 20 | 21 |
| 21 for (var i = 0; i < platforms.length; i++) { | 22 for (var i = 0; i < platforms.length; i++) { |
| 22 platform = platforms[i]; | 23 platform = platforms[i]; |
| 23 debug('Platform: ' + platform); | 24 debug('Platform: ' + platform); |
| 24 | 25 |
| 25 if (window.internals) | 26 if (window.internals) |
| 26 internals.settings.setEditingBehavior(platform); | 27 internals.settings.setEditingBehavior(platform); |
| 27 | 28 |
| 28 if (platform != 'mac') | 29 if (platform != 'mac') |
| 29 platform = 'nonmac'; | 30 platform = 'nonmac'; |
| 30 | 31 |
| 31 testSingleToggle("bold", "<u><b>hello</b> world</u>", {mac: '<u>hello world<
/u>', nonmac: '<u><b>hello world</b></u>'}[platform]); | 32 testSingleToggle("bold", "<u><b>hello</b> world</u>", {mac: '<u>hello world<
/u>', nonmac: '<u><b>hello world</b></u>'}[platform]); |
| 32 testSingleToggle("bold", "<b>hello </b>world", {mac: 'hello world', nonmac:
'<b>hello world</b>'}[platform]); | 33 testSingleToggle("bold", "<b>hello </b>world", {mac: 'hello world', nonmac:
'<b>hello world</b>'}[platform]); |
| 33 testSingleToggle("bold", "<u><b>hello </b></u>world", {mac: '<u>hello </u>wo
rld', nonmac: '<b><u>hello </u>world</b>'}[platform]); | 34 testSingleToggle("bold", "<u><b>hello </b></u>world", {mac: '<u>hello </u>wo
rld', nonmac: '<b><u>hello </u>world</b>'}[platform]); |
| 34 testSingleToggle("italic", "<i>hello</i> <img>", {mac: 'hello <img>', nonmac
: '<i>hello <img></i>'}[platform]); | 35 testSingleToggle("italic", "<i>hello</i> <img>", {mac: 'hello <img>', nonmac
: '<i>hello <img></i>'}[platform]); |
| 35 | 36 |
| 36 // Following tests are cross-platform | 37 // Following tests are cross-platform |
| 37 testSingleToggle("bold", "<u><span id='test'><b>hello</b></span><b>world</b>
</u>", '<u><span id="test">hello</span>world</u>'); | 38 testSingleToggle("bold", "<u><span id='test'><b>hello</b></span><b>world</b>
</u>", '<u><span id="test">hello</span>world</u>'); |
| 38 testSingleToggle("bold", "<span id='test' style='font-weight:normal;'><b>hel
lo</b></span>", '<span id="test">hello</span>'); | 39 testSingleToggle("bold", "<span id='test' style='font-weight:normal;'><b>hel
lo</b></span>", '<span id="test" style="">hello</span>'); |
| 39 testSingleToggle("bold", "<div><b>hello</b><br><br><b>world</b></div>", "<di
v>hello<br><br>world</div>"); | 40 testSingleToggle("bold", "<div><b>hello</b><br><br><b>world</b></div>", "<di
v>hello<br><br>world</div>"); |
| 40 testSingleToggle("italic", "<i>hello </i><img>", "hello <img>"); | 41 testSingleToggle("italic", "<i>hello </i><img>", "hello <img>"); |
| 41 testSingleToggle("italic", "<i><b>hello</b>world</i>", "<b>hello</b>world"); | 42 testSingleToggle("italic", "<i><b>hello</b>world</i>", "<b style=\"\">hello<
/b>world"); |
| 42 testSingleToggle("italic", "<span style='font-style: normal;'> <i> hello </i
> </span>", " hello "); | 43 testSingleToggle("italic", "<span style='font-style: normal;'> <i> hello </i
> </span>", " hello "); |
| 43 testSingleToggle("italic", "<p><i>hello</i><span style='font-style:italic;'>
world</span></p>", "<p>helloworld</p>"); | 44 testSingleToggle("italic", "<p><i>hello</i><span style='font-style:italic;'>
world</span></p>", "<p>helloworld</p>"); |
| 44 testSingleToggle("italic", "<s><b>hello<i> world</i></b></s>", "<s><b><i>hel
lo world</i></b></s>"); | 45 testSingleToggle("italic", "<s><b>hello<i> world</i></b></s>", "<s><b><i>hel
lo world</i></b></s>"); |
| 45 | 46 |
| 46 debug(''); | 47 debug(''); |
| 47 } | 48 } |
| 48 | 49 |
| 49 document.body.removeChild(testContainer); | 50 document.body.removeChild(testContainer); |
| 50 | 51 |
| 51 var successfullyParsed = true; | 52 var successfullyParsed = true; |
| OLD | NEW |