summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/editing/execCommand/use-css.html
blob: c8ad298404f4c5e9bb4df6aca5e475259a285884 (plain)
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
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Test useCSS command');

var testContainer = document.createElement("div");
testContainer.contentEditable = true;
document.body.appendChild(testContainer);

function testUseCSS(styleArg, expectedState)
{
    document.execCommand('useCSS', false, styleArg); 
    if (document.queryCommandState('styleWithCSS') === expectedState)
        testPassed('useCSS changed the state successfully');
    else
        testFailed('useCSS failed with the argument ' + styleArg);
}

function testSingleToggle(toggleCommand, initialContents, expectedContents)
{
    testContainer.innerHTML = initialContents;
    window.getSelection().selectAllChildren(testContainer);
    document.execCommand("useCSS", false, false);
    document.execCommand(toggleCommand, false, null);
    if (testContainer.innerHTML === expectedContents)
        testPassed("one " + toggleCommand + " command converted " + initialContents + " to " + expectedContents);
    else
        testFailed("one " + toggleCommand + " command converted " + initialContents + " to " + testContainer.innerHTML + ", expected " + expectedContents);
}

testUseCSS(false, true);
testUseCSS('false', true);
testUseCSS('FALSE', true);
testUseCSS(true, false);
testUseCSS('random string', false);

if (document.queryCommandState('useCSS') === false)
    testPassed("queryCommandState('useCSS') returns false");
else
    testFailed("queryCommandState('useCSS') should return boolean false");

if (document.queryCommandValue('useCSS') === "")
    testPassed("queryCommandValue('useCSS') returns ''");
else
    testFailed("queryCommandValue('useCSS') should return string ''");

testSingleToggle("underline", "test", "<span style=\"text-decoration-line: underline;\">test</span>");

document.body.removeChild(testContainer);

</script>
</body>
</html>