1 description("Tests queryCommandState('justifyCenter'), queryCommandState('justifyFull'), queryCommandState('justifyLeft'), and queryCommandState('justifyRight')")
3 var testContainer = document.createElement("div");
4 testContainer.contentEditable = true;
5 document.body.appendChild(testContainer);
7 function queryTextAlignment(selector, content, expected)
9 testContainer.innerHTML = content;
10 var selected = selector(testContainer);
11 var center = document.queryCommandState('justifyCenter');
12 var full = document.queryCommandState('justifyFull');
13 var left = document.queryCommandState('justifyLeft');
14 var right = document.queryCommandState('justifyRight');
15 var centerValue = document.queryCommandValue('justifyCenter');
16 var fullValue = document.queryCommandValue('justifyFull');
17 var leftValue = document.queryCommandValue('justifyLeft');
18 var rightValue = document.queryCommandValue('justifyRight');
19 if ((center && full) || (full && left) || (left && right) || (right && center))
20 testFailed('Inconsistent state when selecting ' + selected + ' of "' + content + '". More than one of justifyCenter, justifyFull, justifyRight, and justifyLeft returned true.')
22 var actual = center ? 'center' : full ? 'full' : left ? 'left' : right ? 'right' : '';
23 var action = "queryCommand('format') returns \"" + actual + '" when selecting ' + selected + ' of "' + content + '"';
24 if (actual != expected)
25 testFailed(action + ' but expected "' + expected + '"');
26 else if (centerValue != center.toString() || fullValue != full.toString()
27 || leftValue != left.toString() || rightValue != right.toString())
28 testFailed(action + ' but values returned by queryCommandState and queryCommandValue did not match');
33 function selectFirstPosition(container) {
34 while (container.firstChild)
35 container = container.firstChild;
36 window.getSelection().collapse(container, 0);
37 return 'first position';
40 function selectMiddleOfHelloWorld(container) {
41 window.getSelection().collapse(container, 0);
42 window.getSelection().modify('move', 'forward', 'character');
43 window.getSelection().modify('move', 'forward', 'character');
44 window.getSelection().modify('extend', 'forward', 'word');
45 window.getSelection().modify('extend', 'forward', 'character');
46 window.getSelection().modify('extend', 'forward', 'character');
47 window.getSelection().modify('extend', 'forward', 'character');
52 queryTextAlignment(function () {return 'no selection on'}, 'hello', '');
53 queryTextAlignment(selectFirstPosition, 'hello', 'left');
54 queryTextAlignment(selectFirstPosition, '<p>hello</p>', 'left');
55 queryTextAlignment(selectFirstPosition, '<p align="center">hello</p>', 'center');
56 queryTextAlignment(selectFirstPosition, '<p align="justify">hello</p>', 'full');
57 queryTextAlignment(selectFirstPosition, '<p align="left">hello</p>', 'left');
58 queryTextAlignment(selectFirstPosition, '<p align="right">hello</p>', 'right');
59 queryTextAlignment(selectFirstPosition, '<p style="text-align: center;">hello</p>', 'center');
60 queryTextAlignment(selectFirstPosition, '<p style="text-align: justify;">hello</p>', 'full');
61 queryTextAlignment(selectFirstPosition, '<p style="text-align: left;">hello</p>', 'left');
62 queryTextAlignment(selectFirstPosition, '<p style="text-align: right;">hello</p>', 'right');
63 queryTextAlignment(selectFirstPosition, '<p align="center" style="text-align: justify;">hello</p>', 'full');
64 queryTextAlignment(selectFirstPosition, '<p align="right" style="text-align: left;">hello</p>', 'left');
65 queryTextAlignment(selectFirstPosition, '<p align="center" style="text-align: right;">hello</p>', 'right');
66 queryTextAlignment(selectFirstPosition, '<p align="left" style="text-align: center;">hello</p>', 'center');
67 queryTextAlignment(selectFirstPosition, '<p align="right" style="text-align: left;">hello</p>', 'left');
68 queryTextAlignment(selectFirstPosition, '<p align="center" style="text-align: right;">hello</p>', 'right');
69 queryTextAlignment(selectFirstPosition, '<p align="left" style="text-align: center;">hello</p>', 'center');
70 queryTextAlignment(selectFirstPosition, '<h1>hello</h1>', 'left');
71 queryTextAlignment(selectFirstPosition, '<h1 align="center">hello</h1>', 'center');
72 queryTextAlignment(selectFirstPosition, '<h1 align="justify">hello</h1>', 'full');
73 queryTextAlignment(selectFirstPosition, '<h2 align="left">hello</h2>', 'left');
74 queryTextAlignment(selectFirstPosition, '<h3 align="right">hello</h3>', 'right');
75 queryTextAlignment(selectFirstPosition, '<h4 align="center">hello</h4>', 'center');
76 queryTextAlignment(selectFirstPosition, '<h5 align="left">hello</h5>', 'left');
77 queryTextAlignment(selectFirstPosition, '<h6 align="right">hello</h6>', 'right');
78 queryTextAlignment(selectFirstPosition, '<div align="justify">hello</div>', 'full');
79 queryTextAlignment(selectFirstPosition, '<div align="center">hello</div>', 'center');
80 queryTextAlignment(selectFirstPosition, '<div align="left">hello</div>', 'left');
81 queryTextAlignment(selectFirstPosition, '<div align="right">hello</div>', 'right');
83 function runRangeTests(editingBehavior)
86 internals.settings.setEditingBehavior(editingBehavior);
87 debug('Tests for ' + editingBehavior);
89 queryTextAlignment(selectMiddleOfHelloWorld, '<p>hello</p><p>world</p>', 'left');
90 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="right">hello</p><p>world</p>', {'mac': 'right', 'win': ''}[editingBehavior]);
91 queryTextAlignment(selectMiddleOfHelloWorld, '<p>hello</p><p align="left">world</p>', 'left');
92 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="left">hello</p><p align="right">world</p>', {'mac': 'left', 'win': ''}[editingBehavior]);
93 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="center">hello</p><p align="center">world</p>', 'center');
94 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="justify">hello</p><p align="justify">world</p>', 'full');
95 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="left">hello</p><p align="left">world</p>', 'left');
96 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="right">hello</p><p align="right">world</p>', 'right');
97 queryTextAlignment(selectMiddleOfHelloWorld, '<div align="right">hello<p align="left">world</p></div>', {'mac': 'right', 'win': ''}[editingBehavior]);
98 queryTextAlignment(selectMiddleOfHelloWorld, '<div align="left"><p align="center">world</p>hello</div>', {'mac': 'center', 'win': ''}[editingBehavior]);
99 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="left">hello</p><p>w</p><p align="left">orld</p>', {'mac': 'left', 'win': 'left'}[editingBehavior]);
100 queryTextAlignment(selectMiddleOfHelloWorld, '<p align="justify">hello</p><p>w</p><p align="center">orld</p>', {'mac': 'full', 'win': ''}[editingBehavior]);
104 runRangeTests('win');
106 runRangeTests('mac');
108 document.body.removeChild(testContainer);
109 var successfullyParsed = true;