Commit 49792218 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Rewrite editing/style/push-down-implicit-styles-mac.html to use selection_test()

This patch changes "push-down-implicit-styles-mac.html" with utilizing
|selection_test()| for ease of maintenance.

Because of test cases specify selected range directly instead of using
|Selection#modify()|, test cases are independent from platform, e.g.
selecting whitespaces after word.

Following patch will rename this test file with remove "-mac" suffix to
"push-down-implicit-styles.html" since this test file no more depends on MacOS.

[1] http://crrev.com/c/896764 Rewrite
editing/execCommand/remove-format-multiple-elements-{mac,-win}.html to use
selection_test()

Bug: 679977
Change-Id: I5c9a77d5d48651a9f3936496ca14b195a5633828
Reviewed-on: https://chromium-review.googlesource.com/898765Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533998}
parent 3445dddf
Test to make sure we push down inline styles properly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS bold on first word of <b><div>hello</div> world</b> yields <div style="">hello</div><b> world</b>
PASS bold on first word of <b><div>hello</div>world</b> yields <div style="">hello</div><b>world</b>
PASS bold on first word of <b><div>hello</div><em>world</em></b> yields <div style="">hello</div><em style="font-weight: bold;">world</em>
PASS bold on second word of <b>hello <div>world</div></b> yields <b>hello </b><div style="">world</div>
PASS bold on second word of <b><em>hello</em> <div>world</div></b> yields <em style="font-weight: bold;">hello</em> <div style="">world</div>
PASS bold on all of <b> <div>text</div> </b> yields <div style="">text</div>
PASS bold on all of <b><strike><div>text</div></strike></b> yields <strike style=""><div style="">text</div></strike>
PASS bold on first word of <b><div>hello</div><div>world</div></b> yields <div style="">hello</div><div style="font-weight: bold;">world</div>
PASS bold on first word of <b><div>hello</div><div style="font-weight: normal;">world</div>webkit</b> yields <div style="">hello</div><div style="font-weight: normal;">world</div><b>webkit</b>
PASS bold on second word of <b style="font-style: italic;">hello world</b> yields <b style="font-style: italic;">hello</b><span style="font-style: italic;"> world</span>
PASS underline on second word of <u>hello <b>world</b> webkit</u> yields <u>hello</u> <b style="">world</b><u> webkit</u>
PASS underline on last two words of <u>hello <b>world</b> webkit</u> yields <u>hello </u><b style="">world</b> webkit
PASS underline on last two words of <u>hello <b>world webkit</b></u> yields <u>hello </u><b style="">world webkit</b>
PASS underline on second word of <u>hello <b>world webkit</b></u> yields <u>hello</u> <b style="">world<u> webkit</u></b>
PASS underline on second word of <u><b>hello world</b> webkit</u> yields <b style=""><u>hello</u> world</b><u> webkit</u>
PASS underline on second word of <u><strike>hello world</strike></u> yields <strike style=""><u>hello</u> world</strike>
PASS underline on second word of <u><strike>hello world webkit</strike></u> yields <strike style=""><u>hello</u> world<u> webkit</u></strike>
PASS underline on second word of <u><strike>hello world</strike> webkit</u> yields <strike style=""><u>hello</u> world</strike><u> webkit</u>
PASS underline on second word of <u>hello <em><code>world webkit</code></em> rocks</u> yields <u>hello</u> <em style=""><code style="">world<u> webkit</u></code></em><u> rocks</u>
PASS strikeThrough on all of <s style="color: blue;">hello world</strike> yields <span style="color: blue;">hello world</span>
PASS strikeThrough on first word of <s style="color: blue;"><div>hello</div> <b>world</b> webkit</strike> yields <span style="color: blue;"><div style="">hello</div> <b style="text-decoration-line: line-through;">world</b><strike> webkit</strike></span>
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <!doctype html>
<html> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/js-test.js"></script> <script src="../assert_selection.js"></script>
</head> <script>
<body> function editable(sample) {
<p id="description"></p> return `<div contenteditable>${sample}</div>`;
<div id="console"></div> }
<script src="script-tests/push-down-implicit-styles-mac.js"></script>
</body> function testIt(command_name, input, expected, description) {
</html> selection_test(
editable(input),
command_name,
editable(expected),
description);
}
// bold
testIt('bold',
'<b><div>^abc|</div> xyz</b>',
'<div style>^abc|</div><b> xyz</b>',
'bold-1 first wrod');
testIt('bold',
'<b><div>^abc|</div>xyz</b>',
'<div style>^abc|</div><b>xyz</b>',
'bold-2 first word');
testIt('bold',
'<b><div>^abc|</div><em>xyz</em></b>',
'<div style>^abc|</div><em style="font-weight: bold;">xyz</em>',
'bold-3 first word');
testIt('bold',
'<b>abc <div>^xyz|</div></b>',
'<b>abc </b><div style>^xyz|</div>',
'bold-4 second word');
testIt('bold',
'<b><em>abc</em> <div>^xyz|</div></b>',
'<em style="font-weight: bold;">abc</em> <div style>^xyz|</div>',
'bold-5 second word');
testIt('bold',
'^<b> <div>abc</div> </b>|',
' <div style>^abc|</div> ',
'bold-6 all');
testIt('bold',
'^<b><strike><div>abc</div></strike></b>|',
'<strike style><div style>^abc|</div></strike>',
'bold-7 all');
testIt('bold',
'<b><div>^abc|</div><div>xyz</div></b>',
'<div style>^abc|</div><div style="font-weight: bold;">xyz</div>',
'bold-8 first word');
testIt('bold',
'<b><div>^abc|</div><div style="font-weight: normal;">xyz</div>webkit</b>',
'<div style>^abc|</div><div style="font-weight: normal;">xyz</div><b>webkit</b>',
'bold-9 first word');
testIt('bold',
'<b style="font-style: italic;">abc ^xyz|</b>',
'<b style="font-style: italic;">abc </b><span style="font-style: italic;">^xyz|</span>',
'bold-10 second word');
// underline
testIt('underline',
'<u>abc <b>^xyz|</b> wxy</u>',
'<u>abc </u><b style>^xyz|</b><u> wxy</u>',
'underline-1 second word');
testIt('underline',
'<u>abc <b>^xyz</b> wxy|</u>',
'<u>abc </u><b style>^xyz</b> wxy|',
'underline-2 last two words');
testIt('underline',
'<u>abc <b>^xyz wxy|</b></u>',
'<u>abc </u><b style>^xyz wxy|</b>',
'underline-3 last two words');
testIt('underline',
'<u>abc <b>^xyz| wxy</b></u>',
'<u>abc </u><b style>^xyz|<u> wxy</u></b>',
'underline-4 second word');
testIt('underline',
'<u><b>abc ^xyz|</b> wxy</u>',
'<b style><u>abc </u>^xyz|</b><u> wxy</u>',
'underline-5 second word');
testIt('underline',
'<u><strike>abc ^xyz|</strike></u>',
'<strike style><u>abc </u>^xyz|</strike>',
'underline-6 second word');
testIt('underline',
'<u><strike>abc ^xyz| wxy</strike></u>',
'<strike style><u>abc </u>^xyz|<u> wxy</u></strike>',
'underline-7 second word');
testIt('underline',
'<u><strike>abc ^xyz|</strike> wxy</u>',
'<strike style><u>abc </u>^xyz|</strike><u> wxy</u>',
'underline-8 second word');
testIt('underline',
'<u>abc <em><code>^xyz| wxy</code></em> rocks</u>',
'<u>abc </u><em style><code style>^xyz|<u> wxy</u></code></em><u> rocks</u>',
'underline-9 second word');
// strikeThrough
testIt('strikeThrough',
'^<s style="color: blue;">abc xyz</strike>|',
'<span style="color: blue;">^abc xyz|</span>',
'strike-through-1 all');
testIt('strikeThrough',
'<s style="color: blue;"><div>^abc|</div> <b>xyz</b> webkit</strike>',
'<span style="color: blue;"><div style>^abc|</div> <b style="text-decoration-line: line-through;">xyz</b><strike> webkit</strike></span>',
'strike-through-2 first word');
</script>
description('Test to make sure we push down inline styles properly.');
if (window.internals)
internals.settings.setEditingBehavior('mac');
var testContainer = document.createElement("div");
testContainer.contentEditable = true;
document.body.appendChild(testContainer);
function testSingleToggle(toggleCommand, selector, initialContents, expectedContents)
{
testContainer.innerHTML = initialContents;
var selected = selector(testContainer);
document.execCommand('styleWithCSS', false, 'false');
document.execCommand(toggleCommand, false, null);
var action = toggleCommand + ' on ' + selected + ' of ' + initialContents + " yields " + testContainer.innerHTML;
if (testContainer.innerHTML == expectedContents)
testPassed(action);
else
testFailed(action + ", expected " + expectedContents);
}
function selectAll(container) {
window.getSelection().selectAllChildren(container);
return 'all';
}
function selectTest(container) {
window.getSelection().selectAllChildren(document.getElementById('test'));
return 'test';
}
function selectFirstWord(container) {
window.getSelection().collapse(container, 0);
window.getSelection().modify('extend', 'forward', 'word');
return 'first word';
}
function selectSecondWord(container) {
window.getSelection().collapse(container, 0);
window.getSelection().modify('move', 'forward', 'word');
window.getSelection().modify('extend', 'forward', 'word');
return 'second word';
}
function selectLastTwoWords(container) {
window.getSelection().collapse(container, container.childNodes.length);
window.getSelection().modify('extend', 'backward', 'word');
window.getSelection().modify('extend', 'backward', 'word');
return 'last two words';
}
testSingleToggle("bold", selectFirstWord, '<b><div>hello</div> world</b>', '<div style="">hello</div><b> world</b>');
testSingleToggle("bold", selectFirstWord, '<b><div>hello</div>world</b>', '<div style="">hello</div><b>world</b>');
testSingleToggle("bold", selectFirstWord, '<b><div>hello</div><em>world</em></b>', '<div style="">hello</div><em style="font-weight: bold;">world</em>');
testSingleToggle("bold", selectSecondWord, '<b>hello <div>world</div></b>', '<b>hello </b><div style="">world</div>');
testSingleToggle("bold", selectSecondWord, '<b><em>hello</em> <div>world</div></b>', '<em style="font-weight: bold;">hello</em> <div style="">world</div>');
testSingleToggle("bold", selectAll, '<b> <div>text</div> </b>', ' <div style="">text</div> ');
testSingleToggle("bold", selectAll, '<b><strike><div>text</div></strike></b>', '<strike style=""><div style="">text</div></strike>');
testSingleToggle("bold", selectFirstWord, '<b><div>hello</div><div>world</div></b>', '<div style="">hello</div><div style="font-weight: bold;">world</div>');
testSingleToggle("bold", selectFirstWord, '<b><div>hello</div><div style="font-weight: normal;">world</div>webkit</b>', '<div style="">hello</div><div style="font-weight: normal;">world</div><b>webkit</b>');
testSingleToggle("bold", selectSecondWord, '<b style="font-style: italic;">hello world</b>', '<b style="font-style: italic;">hello</b><span style="font-style: italic;"> world</span>');
testSingleToggle("underline", selectSecondWord, '<u>hello <b>world</b> webkit</u>', '<u>hello</u> <b style="">world</b><u> webkit</u>');
testSingleToggle("underline", selectLastTwoWords, '<u>hello <b>world</b> webkit</u>', '<u>hello </u><b style="">world</b> webkit');
testSingleToggle("underline", selectLastTwoWords, '<u>hello <b>world webkit</b></u>', '<u>hello </u><b style="">world webkit</b>');
testSingleToggle("underline", selectSecondWord, '<u>hello <b>world webkit</b></u>', '<u>hello</u> <b style="">world<u> webkit</u></b>');
testSingleToggle("underline", selectSecondWord, '<u><b>hello world</b> webkit</u>', '<b style=""><u>hello</u> world</b><u> webkit</u>');
testSingleToggle("underline", selectSecondWord, '<u><strike>hello world</strike></u>', '<strike style=""><u>hello</u> world</strike>');
testSingleToggle("underline", selectSecondWord, '<u><strike>hello world webkit</strike></u>', '<strike style=""><u>hello</u> world<u> webkit</u></strike>');
testSingleToggle("underline", selectSecondWord, '<u><strike>hello world</strike> webkit</u>', '<strike style=""><u>hello</u> world</strike><u> webkit</u>');
testSingleToggle("underline", selectSecondWord, '<u>hello <em><code>world webkit</code></em> rocks</u>', '<u>hello</u> <em style=""><code style="">world<u> webkit</u></code></em><u> rocks</u>');
testSingleToggle("strikeThrough", selectAll, '<s style="color: blue;">hello world</strike>', '<span style="color: blue;">hello world</span>');
testSingleToggle("strikeThrough", selectFirstWord, '<s style="color: blue;"><div>hello</div> <b>world</b> webkit</strike>', '<span style="color: blue;"><div style="">hello</div> <b style="text-decoration-line: line-through;">world</b><strike> webkit</strike></span>');
document.body.removeChild(testContainer);
var successfullyParsed = true;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment