Commit 48b64bcc authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Rewrite editing/style/push-down-font-styles{,-mac}.html to use selection_test()

This patch changes "push-down-font-styles{,-mac}.html" into
"push-down-font-styles.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.

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

Bug: 679977
Change-Id: If2a26ed1d3007048d6799ce8f7fb20e12903d9c4
Reviewed-on: https://chromium-review.googlesource.com/898764Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533996}
parent 60fcf0a9
Test to make sure we push down inline styles properly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Font size
PASS fontsize 2 on all of "hello world" yields "<font size="2">hello world</font>"
PASS fontsize 4 on all of "hello world" yields "<font size="4">hello world</font>"
PASS fontsize 5 on first word of "hello world" yields "<font size="5">hello</font> world"
PASS fontsize 3 on first word of "<font size="7">hello <div>world</div></font>" yields "hello <div style="font-size: -webkit-xxx-large;">world</div>"
PASS fontsize 3 on first word of "<font size="7"><div>hello</div><div>world</div></font>" yields "<div style="">hello</div><div style="font-size: -webkit-xxx-large;">world</div>"
PASS fontsize 3 on second word of "<font size="7"><div>hello</div>world</font>" yields "<div style="font-size: -webkit-xxx-large;">hello</div>world"
PASS fontsize 7 on all of "<font size="7"><div>hello</div>world</font>" yields "<font size="7"><div>hello</div>world</font>"
PASS fontsize 7 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><font size="7">hello</font></div><font size="7">world</font>"
PASS fontsize 6 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><font size="6">hello</font></div><font size="6">world</font>"
PASS fontsize 5 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><font size="5">hello</font></div><font size="5">world</font>"
PASS fontsize 3 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style="">hello</div>world"
PASS fontsize 3 on all of "<font size="3"><div>hello</div>world</font>" yields "<font size="3"><div>hello</div>world</font>"
PASS fontsize 1 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><font size="1">hello</font></div><font size="1">world</font>"
Font size (with CSS)
PASS fontsize 7 on all of "<font size="7"><div>hello</div>world</font>" yields "<font size="7"><div>hello</div>world</font>"
PASS fontsize 7 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: -webkit-xxx-large;">hello</span></div><span style="font-size: -webkit-xxx-large;">world</span>"
PASS fontsize 6 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: xx-large;">hello</span></div><span style="font-size: xx-large;">world</span>"
PASS fontsize 5 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: x-large;">hello</span></div><span style="font-size: x-large;">world</span>"
PASS fontsize 3 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style="">hello</div>world"
PASS fontsize 3 on all of "<font size="3"><div>hello</div>world</font>" yields "<font size="3"><div>hello</div>world</font>"
PASS fontsize 1 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: x-small;">hello</span></div><span style="font-size: x-small;">world</span>"
Font family
PASS fontname Arial on all of "hello world" yields "<font face="Arial">hello world</font>"
PASS fontname Arial on first word of "<font face="sans-serif">hello world</font>" yields "<font face="Arial">hello</font><font face="sans-serif"> world</font>"
PASS fontname Arial on first word of "<font face="sans-serif">hello<div>world</div></font>" yields "<font face="Arial">hello</font><div style="font-family: sans-serif;">world</div>"
PASS fontname Arial on second word of "<font face="sans-serif">hello<div>world</div></font>" yields "<font face="sans-serif">hello</font><div style=""><font face="Arial">world</font></div>"
PASS fontname Sans-Serif on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<font face="sans-serif"><div>hello</div><div>world</div></font>"
FAIL fontname Arial on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<div style=""><font face="Arial">hello</font></div><div style=""><font face="Arial">world</font></div>", expected "<div><font face="Arial">hello</font></div><div><font face="Arial">world</font></div>"
Font family (with CSS)
PASS fontname Arial on all of "hello world" yields "<span style="font-family: Arial;">hello world</span>"
PASS fontname Arial on first word of "<font face="sans-serif">hello world</font>" yields "<span style="font-family: Arial;">hello</span><font face="sans-serif"> world</font>"
PASS fontname Arial on first word of "<font face="sans-serif">hello<div>world</div></font>" yields "<span style="font-family: Arial;">hello</span><div style="font-family: sans-serif;">world</div>"
PASS fontname Arial on second word of "<font face="sans-serif">hello<div>world</div></font>" yields "<span style="font-family: sans-serif;">hello</span><div style=""><span style="font-family: Arial;">world</span></div>"
PASS fontname Sans-Serif on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<font face="sans-serif"><div>hello</div><div>world</div></font>"
FAIL fontname Arial on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<div style=""><span style="font-family: Arial;">hello</span></div><div style=""><span style="font-family: Arial;">world</span></div>", expected "<div><span style="font-family: Arial;">hello</span></div><div style=""><span style="font-family: Arial;">world</span></div>"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="script-tests/push-down-font-styles-mac.js"></script>
</body>
</html>
Test to make sure we push down inline styles properly.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Font size
PASS fontsize 2 on all of "hello world" yields "<font size="2">hello world</font>"
PASS fontsize 4 on all of "hello world" yields "<font size="4">hello world</font>"
PASS fontsize 5 on first word of "hello world" yields "<font size="5">hello </font>world"
PASS fontsize 3 on first word of "<font size="7">hello <div>world</div></font>" yields "hello <div style="font-size: -webkit-xxx-large;">world</div>"
PASS fontsize 3 on first word of "<font size="7"><div>hello</div><div>world</div></font>" yields "<div style="">hello</div><div style="font-size: -webkit-xxx-large;">world</div>"
PASS fontsize 3 on second word of "<font size="7"><div>hello</div>world</font>" yields "<div style="font-size: -webkit-xxx-large;">hello</div>world"
PASS fontsize 7 on all of "<font size="7"><div>hello</div>world</font>" yields "<font size="7"><div>hello</div>world</font>"
PASS fontsize 7 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><font size="7">hello</font></div><font size="7">world</font>"
PASS fontsize 6 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><font size="6">hello</font></div><font size="6">world</font>"
PASS fontsize 5 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><font size="5">hello</font></div><font size="5">world</font>"
PASS fontsize 3 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style="">hello</div>world"
PASS fontsize 3 on all of "<font size="3"><div>hello</div>world</font>" yields "<font size="3"><div>hello</div>world</font>"
PASS fontsize 1 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><font size="1">hello</font></div><font size="1">world</font>"
Font size (with CSS)
PASS fontsize 7 on all of "<font size="7"><div>hello</div>world</font>" yields "<font size="7"><div>hello</div>world</font>"
PASS fontsize 7 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: -webkit-xxx-large;">hello</span></div><span style="font-size: -webkit-xxx-large;">world</span>"
PASS fontsize 6 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: xx-large;">hello</span></div><span style="font-size: xx-large;">world</span>"
PASS fontsize 5 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: x-large;">hello</span></div><span style="font-size: x-large;">world</span>"
PASS fontsize 3 on all of "<font size="7"><div>hello</div>world</font>" yields "<div style="">hello</div>world"
PASS fontsize 3 on all of "<font size="3"><div>hello</div>world</font>" yields "<font size="3"><div>hello</div>world</font>"
PASS fontsize 1 on all of "<font size="3"><div>hello</div>world</font>" yields "<div style=""><span style="font-size: x-small;">hello</span></div><span style="font-size: x-small;">world</span>"
Font family
PASS fontname Arial on all of "hello world" yields "<font face="Arial">hello world</font>"
PASS fontname Arial on first word of "<font face="sans-serif">hello world</font>" yields "<font face="Arial">hello </font><font face="sans-serif">world</font>"
PASS fontname Arial on first word of "<font face="sans-serif">hello<div>world</div></font>" yields "<font face="Arial">hello</font><div style="font-family: sans-serif;">world</div>"
PASS fontname Arial on second word of "<font face="sans-serif">hello<div>world</div></font>" yields "<font face="sans-serif">hello</font><div style=""><font face="Arial">world</font></div>"
PASS fontname Sans-Serif on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<font face="sans-serif"><div>hello</div><div>world</div></font>"
FAIL fontname Arial on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<div style=""><font face="Arial">hello</font></div><div style=""><font face="Arial">world</font></div>", expected "<div><font face="Arial">hello</font></div><div><font face="Arial">world</font></div>"
Font family (with CSS)
PASS fontname Arial on all of "hello world" yields "<span style="font-family: Arial;">hello world</span>"
PASS fontname Arial on first word of "<font face="sans-serif">hello world</font>" yields "<span style="font-family: Arial;">hello </span><font face="sans-serif">world</font>"
PASS fontname Arial on first word of "<font face="sans-serif">hello<div>world</div></font>" yields "<span style="font-family: Arial;">hello</span><div style="font-family: sans-serif;">world</div>"
PASS fontname Arial on second word of "<font face="sans-serif">hello<div>world</div></font>" yields "<span style="font-family: sans-serif;">hello</span><div style=""><span style="font-family: Arial;">world</span></div>"
PASS fontname Sans-Serif on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<font face="sans-serif"><div>hello</div><div>world</div></font>"
FAIL fontname Arial on all of "<font face="sans-serif"><div>hello</div><div>world</div></font>" yields "<div style=""><span style="font-family: Arial;">hello</span></div><div style=""><span style="font-family: Arial;">world</span></div>", expected "<div><span style="font-family: Arial;">hello</span></div><div style=""><span style="font-family: Arial;">world</span></div>"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="script-tests/push-down-font-styles-win.js"></script>
</body>
</html>
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
function editable(sample) {
return `<div contenteditable>${sample}</div>`;
}
function testIt(styleWithCSS, command_name, command_value, input, expected, description) {
selection_test(
editable(input),
selection => {
selection.document.execCommand('styleWithCSS', false, styleWithCSS);
selection.document.execCommand(command_name, false, command_value);
},
editable(expected),
description);
}
function testStyleWithoutCSS(...params) {
testIt('false', ...params);
}
function testStyleWithCSS(...params) {
testIt('true', ...params);
}
// Font size
testStyleWithoutCSS('fontsize', 2, '^abc xyz|', '<font size="2">^abc xyz|</font>',
'font-size-1 all')
testStyleWithoutCSS('fontsize', 4, '^abc xyz|', '<font size="4">^abc xyz|</font>',
'font-size-2 all')
testStyleWithoutCSS('fontsize', 5, '^abc| xyz', '<font size="5">^abc|</font> xyz',
'font-size-3 first word');
testStyleWithoutCSS('fontsize', 3,
'<font size="7">^abc| <div>xyz</div></font>',
'^abc| <div style="font-size: -webkit-xxx-large;">xyz</div>',
'font-size-4 first word');
testStyleWithoutCSS('fontsize', 3,
'<font size="7"><div>^abc|</div><div>xyz</div></font>',
'<div style>^abc|</div><div style="font-size: -webkit-xxx-large;">xyz</div>',
'font-size-5 first word');
testStyleWithoutCSS('fontsize', 3,
'<font size="7"><div>abc</div>^xyz|</font>',
'<div style="font-size: -webkit-xxx-large;">abc</div>^xyz|',
'font-size-6 second word');
testStyleWithoutCSS('fontsize', 7,
'^<font size="7"><div>abc</div>xyz</font>|',
'<font size="7"><div>^abc</div>xyz|</font>',
'font-size-7 all');
testStyleWithoutCSS('fontsize', 7,
'^<font size="3"><div>abc</div>xyz</font>|',
'<div style><font size="7">^abc</font></div><font size="7">xyz|</font>',
'font-size-8 all');
testStyleWithoutCSS('fontsize', 6,
'^<font size="7"><div>abc</div>xyz</font>|',
'<div style><font size="6">^abc</font></div><font size="6">xyz|</font>',
'font-size-9 all');
testStyleWithoutCSS('fontsize', 5,
'^<font size="7"><div>abc</div>xyz</font>|',
'<div style><font size="5">^abc</font></div><font size="5">xyz|</font>',
'font-size-10 all');
testStyleWithoutCSS('fontsize', 3,
'^<font size="7"><div>abc</div>xyz</font>|',
'<div style>^abc</div>xyz|',
'font-size-11 all');
testStyleWithoutCSS('fontsize', 3,
'^<font size="3"><div>abc</div>xyz</font>|',
'<font size="3"><div>^abc</div>xyz|</font>',
'font-size-12 all');
testStyleWithoutCSS('fontsize', 1,
'^<font size="3"><div>abc</div>xyz</font>|',
'<div style><font size="1">^abc</font></div><font size="1">xyz|</font>',
'font-size-13 all');
// Font size (with CSS)
testStyleWithCSS('fontsize', 7,
'^<font size="7"><div>abc</div>xyz</font>|',
'<font size="7"><div>^abc</div>xyz|</font>',
'1 font-size-with-css all');
testStyleWithCSS('fontsize', 7,
'^<font size="3"><div>abc</div>xyz</font>|',
'<div style><span style="font-size: -webkit-xxx-large;">^abc</span></div><span style="font-size: -webkit-xxx-large;">xyz|</span>',
'2 font-size-with-css all');
testStyleWithCSS('fontsize', 6,
'^<font size="7"><div>abc</div>xyz</font>|',
'<div style><span style="font-size: xx-large;">^abc</span></div><span style="font-size: xx-large;">xyz|</span>',
'3 font-size-with-css all');
testStyleWithCSS('fontsize', 5,
'^<font size="7"><div>abc</div>xyz</font>|',
'<div style><span style="font-size: x-large;">^abc</span></div><span style="font-size: x-large;">xyz|</span>',
'4 font-size-with-css all');
testStyleWithCSS('fontsize', 3,
'^<font size="7"><div>abc</div>xyz</font>|',
'<div style>^abc</div>xyz|',
'5 font-size-with-css all');
testStyleWithCSS('fontsize', 3,
'^<font size="3"><div>abc</div>xyz</font>|',
'<font size="3"><div>^abc</div>xyz|</font>',
'6 font-size-with-css all');
testStyleWithCSS('fontsize', 1,
'^<font size="3"><div>abc</div>xyz</font>|',
'<div style><span style="font-size: x-small;">^abc</span></div><span style="font-size: x-small;">xyz|</span>',
'7 font-size-with-css all');
// Font family
testStyleWithoutCSS('fontname', 'Arial',
'^abc xyz|',
'<font face="Arial">^abc xyz|</font>',
'font-family-1 all');
testStyleWithoutCSS('fontname', 'Arial',
'<font face="sans-serif">^abc| xyz</font>',
'<font face="Arial">^abc|</font><font face="sans-serif"> xyz</font>',
'font-family-2 first word');
testStyleWithoutCSS('fontname', 'Arial',
'<font face="sans-serif">^abc|<div>xyz</div></font>',
'<font face="Arial">^abc|</font><div style="font-family: sans-serif;">xyz</div>',
'font-family-3 first word');
testStyleWithoutCSS('fontname', 'Arial',
'<font face="sans-serif">abc<div>^xyz|</div></font>',
'<font face="sans-serif">abc</font><div style><font face="Arial">^xyz|</font></div>',
'font-family-4 second word');
testStyleWithoutCSS('fontname', 'Sans-Serif',
'^<font face="sans-serif"><div>abc</div><div>xyz</div></font>|',
'<font face="sans-serif"><div>^abc</div><div>xyz|</div></font>',
'font-family-5 all');
testStyleWithoutCSS('fontname', 'Arial',
'^<font face="sans-serif"><div>abc</div><div>xyz</div></font>|',
'<div style><font face="Arial">^abc</font></div><div style><font face="Arial">xyz|</font></div>',
'font-family-6 all');
// Font family (with CSS)
styleWithCSS = true;
testStyleWithCSS('fontname', 'Arial',
'^abc xyz|',
'<span style="font-family: Arial;">^abc xyz|</span>',
'font-family-with-css-1 all');
testStyleWithCSS('fontname',
'Arial',
'<font face="sans-serif">^abc| xyz</font>',
'<span style="font-family: Arial;">^abc|</span><font face="sans-serif"> xyz</font>',
'font-family-with-css-2 first word');
testStyleWithCSS('fontname', 'Arial',
'<font face="sans-serif">^abc|<div>xyz</div></font>',
'<span style="font-family: Arial;">^abc|</span><div style="font-family: sans-serif;">xyz</div>',
'font-family-with-css-3 first word');
testStyleWithCSS('fontname', 'Arial',
'<font face="sans-serif">abc<div>^xyz|</div></font>',
'<span style="font-family: sans-serif;">abc</span><div style><span style="font-family: Arial;">^xyz|</span></div>',
'font-family-with-css-4 second word');
testStyleWithCSS('fontname', 'Sans-Serif',
'^<font face="sans-serif"><div>abc</div><div>xyz</div></font>|',
'<font face="sans-serif"><div>^abc</div><div>xyz|</div></font>',
'font-family-with-css-5 all');
testStyleWithCSS('fontname', 'Arial',
'^<font face="sans-serif"><div style>abc</div><div style>xyz</div></font>|',
'<div style><span style="font-family: Arial;">^abc</span></div><div style><span style="font-family: Arial;">xyz|</span></div>',
'font-family-with-css-6 all');
</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);
var styleWithCSS = false;
function testSingleToggle(toggleCommand, value, selector, initialContents, expectedContents)
{
testContainer.innerHTML = initialContents;
var selected = selector(testContainer);
document.execCommand('styleWithCSS', false, styleWithCSS ? 'true' : 'false');
document.execCommand(toggleCommand, false, value);
var action = toggleCommand + ' ' + value + ' 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';
}
debug("Font size");
styleWithCSS = false;
testSingleToggle("fontsize", 2, selectAll, 'hello world', '<font size="2">hello world</font>');
testSingleToggle("fontsize", 4, selectAll, 'hello world', '<font size="4">hello world</font>');
testSingleToggle("fontsize", 5, selectFirstWord, 'hello world', '<font size="5">hello</font> world');
testSingleToggle("fontsize", 3, selectFirstWord, '<font size="7">hello <div>world</div></font>', 'hello <div style="font-size: -webkit-xxx-large;">world</div>');
testSingleToggle("fontsize", 3, selectFirstWord, '<font size="7"><div>hello</div><div>world</div></font>', '<div style="">hello</div><div style="font-size: -webkit-xxx-large;">world</div>');
testSingleToggle("fontsize", 3, selectSecondWord, '<font size="7"><div>hello</div>world</font>', '<div style="font-size: -webkit-xxx-large;">hello</div>world');
testSingleToggle("fontsize", 7, selectAll, '<font size="7"><div>hello</div>world</font>', '<font size="7"><div>hello</div>world</font>');
testSingleToggle("fontsize", 7, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><font size="7">hello</font></div><font size="7">world</font>');
testSingleToggle("fontsize", 6, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><font size="6">hello</font></div><font size="6">world</font>');
testSingleToggle("fontsize", 5, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><font size="5">hello</font></div><font size="5">world</font>');
testSingleToggle("fontsize", 3, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style="">hello</div>world');
testSingleToggle("fontsize", 3, selectAll, '<font size="3"><div>hello</div>world</font>', '<font size="3"><div>hello</div>world</font>');
testSingleToggle("fontsize", 1, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><font size="1">hello</font></div><font size="1">world</font>');
debug("");
debug("Font size (with CSS)");
styleWithCSS = true;
testSingleToggle("fontsize", 7, selectAll, '<font size="7"><div>hello</div>world</font>', '<font size="7"><div>hello</div>world</font>');
testSingleToggle("fontsize", 7, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><span style="font-size: -webkit-xxx-large;">hello</span></div><span style="font-size: -webkit-xxx-large;">world</span>');
testSingleToggle("fontsize", 6, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><span style="font-size: xx-large;">hello</span></div><span style="font-size: xx-large;">world</span>');
testSingleToggle("fontsize", 5, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><span style="font-size: x-large;">hello</span></div><span style="font-size: x-large;">world</span>');
testSingleToggle("fontsize", 3, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style="">hello</div>world');
testSingleToggle("fontsize", 3, selectAll, '<font size="3"><div>hello</div>world</font>', '<font size="3"><div>hello</div>world</font>');
testSingleToggle("fontsize", 1, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><span style="font-size: x-small;">hello</span></div><span style="font-size: x-small;">world</span>');
debug("");
debug("Font family");
styleWithCSS = false;
testSingleToggle("fontname", "Arial", selectAll, 'hello world', '<font face="Arial">hello world</font>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello world</font>', '<font face="Arial">hello</font><font face="sans-serif"> world</font>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello<div>world</div></font>', '<font face="Arial">hello</font><div style="font-family: sans-serif;">world</div>');
testSingleToggle("fontname", "Arial", selectSecondWord, '<font face="sans-serif">hello<div>world</div></font>', '<font face="sans-serif">hello</font><div style=""><font face="Arial">world</font></div>');
testSingleToggle("fontname", "Sans-Serif", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<font face="sans-serif"><div>hello</div><div>world</div></font>');
testSingleToggle("fontname", "Arial", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<div><font face="Arial">hello</font></div><div><font face="Arial">world</font></div>');
debug("");
debug("Font family (with CSS)");
styleWithCSS = true;
testSingleToggle("fontname", "Arial", selectAll, 'hello world', '<span style="font-family: Arial;">hello world</span>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello world</font>', '<span style="font-family: Arial;">hello</span><font face="sans-serif"> world</font>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello<div>world</div></font>', '<span style="font-family: Arial;">hello</span><div style="font-family: sans-serif;">world</div>');
testSingleToggle("fontname", "Arial", selectSecondWord, '<font face="sans-serif">hello<div>world</div></font>', '<span style="font-family: sans-serif;">hello</span><div style=""><span style="font-family: Arial;">world</span></div>');
testSingleToggle("fontname", "Sans-Serif", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<font face="sans-serif"><div>hello</div><div>world</div></font>');
testSingleToggle("fontname", "Arial", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<div><span style="font-family: Arial;">hello</span></div><div style=""><span style="font-family: Arial;">world</span></div>');
document.body.removeChild(testContainer);
var successfullyParsed = true;
description('Test to make sure we push down inline styles properly.');
if (window.internals)
internals.settings.setEditingBehavior('win');
var testContainer = document.createElement("div");
testContainer.contentEditable = true;
document.body.appendChild(testContainer);
var styleWithCSS = false;
function testSingleToggle(toggleCommand, value, selector, initialContents, expectedContents)
{
testContainer.innerHTML = initialContents;
var selected = selector(testContainer);
document.execCommand('styleWithCSS', false, styleWithCSS ? 'true' : 'false');
document.execCommand(toggleCommand, false, value);
var action = toggleCommand + ' ' + value + ' 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';
}
debug("Font size");
styleWithCSS = false;
testSingleToggle("fontsize", 2, selectAll, 'hello world', '<font size="2">hello world</font>');
testSingleToggle("fontsize", 4, selectAll, 'hello world', '<font size="4">hello world</font>');
testSingleToggle("fontsize", 5, selectFirstWord, 'hello world', '<font size="5">hello </font>world');
testSingleToggle("fontsize", 3, selectFirstWord, '<font size="7">hello <div>world</div></font>', 'hello <div style="font-size: -webkit-xxx-large;">world</div>');
testSingleToggle("fontsize", 3, selectFirstWord, '<font size="7"><div>hello</div><div>world</div></font>', '<div style="">hello</div><div style="font-size: -webkit-xxx-large;">world</div>');
testSingleToggle("fontsize", 3, selectSecondWord, '<font size="7"><div>hello</div>world</font>', '<div style="font-size: -webkit-xxx-large;">hello</div>world');
testSingleToggle("fontsize", 7, selectAll, '<font size="7"><div>hello</div>world</font>', '<font size="7"><div>hello</div>world</font>');
testSingleToggle("fontsize", 7, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><font size="7">hello</font></div><font size="7">world</font>');
testSingleToggle("fontsize", 6, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><font size="6">hello</font></div><font size="6">world</font>');
testSingleToggle("fontsize", 5, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><font size="5">hello</font></div><font size="5">world</font>');
testSingleToggle("fontsize", 3, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style="">hello</div>world');
testSingleToggle("fontsize", 3, selectAll, '<font size="3"><div>hello</div>world</font>', '<font size="3"><div>hello</div>world</font>');
testSingleToggle("fontsize", 1, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><font size="1">hello</font></div><font size="1">world</font>');
debug("");
debug("Font size (with CSS)");
styleWithCSS = true;
testSingleToggle("fontsize", 7, selectAll, '<font size="7"><div>hello</div>world</font>', '<font size="7"><div>hello</div>world</font>');
testSingleToggle("fontsize", 7, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><span style="font-size: -webkit-xxx-large;">hello</span></div><span style="font-size: -webkit-xxx-large;">world</span>');
testSingleToggle("fontsize", 6, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><span style="font-size: xx-large;">hello</span></div><span style="font-size: xx-large;">world</span>');
testSingleToggle("fontsize", 5, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style=""><span style="font-size: x-large;">hello</span></div><span style="font-size: x-large;">world</span>');
testSingleToggle("fontsize", 3, selectAll, '<font size="7"><div>hello</div>world</font>', '<div style="">hello</div>world');
testSingleToggle("fontsize", 3, selectAll, '<font size="3"><div>hello</div>world</font>', '<font size="3"><div>hello</div>world</font>');
testSingleToggle("fontsize", 1, selectAll, '<font size="3"><div>hello</div>world</font>', '<div style=""><span style="font-size: x-small;">hello</span></div><span style="font-size: x-small;">world</span>');
debug("");
debug("Font family");
styleWithCSS = false;
testSingleToggle("fontname", "Arial", selectAll, 'hello world', '<font face="Arial">hello world</font>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello world</font>', '<font face="Arial">hello </font><font face="sans-serif">world</font>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello<div>world</div></font>', '<font face="Arial">hello</font><div style="font-family: sans-serif;">world</div>');
testSingleToggle("fontname", "Arial", selectSecondWord, '<font face="sans-serif">hello<div>world</div></font>', '<font face="sans-serif">hello</font><div style=""><font face="Arial">world</font></div>');
testSingleToggle("fontname", "Sans-Serif", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<font face="sans-serif"><div>hello</div><div>world</div></font>');
testSingleToggle("fontname", "Arial", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<div><font face="Arial">hello</font></div><div><font face="Arial">world</font></div>');
debug("");
debug("Font family (with CSS)");
styleWithCSS = true;
testSingleToggle("fontname", "Arial", selectAll, 'hello world', '<span style="font-family: Arial;">hello world</span>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello world</font>', '<span style="font-family: Arial;">hello </span><font face="sans-serif">world</font>');
testSingleToggle("fontname", "Arial", selectFirstWord, '<font face="sans-serif">hello<div>world</div></font>', '<span style="font-family: Arial;">hello</span><div style="font-family: sans-serif;">world</div>');
testSingleToggle("fontname", "Arial", selectSecondWord, '<font face="sans-serif">hello<div>world</div></font>', '<span style="font-family: sans-serif;">hello</span><div style=""><span style="font-family: Arial;">world</span></div>');
testSingleToggle("fontname", "Sans-Serif", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<font face="sans-serif"><div>hello</div><div>world</div></font>');
testSingleToggle("fontname", "Arial", selectAll, '<font face="sans-serif"><div>hello</div><div>world</div></font>', '<div><span style="font-family: Arial;">hello</span></div><div style=""><span style="font-family: Arial;">world</span></div>');
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