Debian Codegraph @

closure-library/closure/goog/editor/browserfeature_test.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.editor.BrowserFeatureTest');
16 goog.setTestOnly('goog.editor.BrowserFeatureTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.dom.Range');
20 goog.require('goog.dom.TagName');
21 goog.require('goog.editor.BrowserFeature');
22 goog.require('goog.testing.ExpectedFailures');
23 goog.require('goog.testing.jsunit');
24
25 var expectedFailures;
26
27 function setUpPage() {
28 expectedFailures = new goog.testing.ExpectedFailures();
29 }
30
31 function tearDown() {
32 var root = goog.dom.getElement('root');
33 goog.dom.removeChildren(root);
34 expectedFailures.handleTearDown();
35 }
36
37 function testEmptyNodeNormalization() {
38 var root = goog.dom.getElement('root');
39 goog.dom.appendChild(root, goog.dom.createTextNode('text'));
40
41 var textNode = root.firstChild;
42 textNode.splitText(0);
43 root.normalize();
44
45 assertEquals(
46 'NORMALIZE_CORRUPTS_EMPTY_TEXT_NODES incorrect for ' +
47 navigator.userAgent,
48 goog.editor.BrowserFeature.NORMALIZE_CORRUPTS_EMPTY_TEXT_NODES,
49 textNode.parentNode == null);
50 }
51
52 function testLeavesPWhenRemovingLists() {
53 if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
54 return;
55 }
56 var root = goog.dom.getElement('root');
57 goog.dom.removeChildren(root);
58 root.innerHTML = '<div>foo</div>';
59 goog.dom.Range.createFromNodeContents(root.firstChild.firstChild).select();
60 document.execCommand('insertorderedlist', false, true);
61 document.execCommand('insertorderedlist', false, true);
62
63 assertEquals(
64 'LEAVES_P_WHEN_REMOVING_LISTS incorrect for ' + navigator.userAgent,
65 goog.editor.BrowserFeature.LEAVES_P_WHEN_REMOVING_LISTS,
66 !!goog.dom.getElementsByTagName(goog.dom.TagName.P, root).length);
67 }
68
69 function testActiveElement() {
70 var root = goog.dom.getElement('root');
71 var div = goog.dom.createElement(goog.dom.TagName.DIV);
72 root.appendChild(div);
73 div.tabIndex = 0;
74 div.focus();
75
76 expectedFailures.expectFailureFor(
77 !goog.editor.BrowserFeature.HAS_ACTIVE_ELEMENT);
78 try {
79 assertEquals(
80 'document.activeElement should be the created div', div,
81 document.activeElement);
82 } catch (e) {
83 expectedFailures.handleException(e);
84 }
85 }
86
87 function testNormalizeCorruption() {
88 var root = goog.dom.getElement('testNormalizeCorruption');
89 var textNode = root.firstChild;
90 textNode.splitText(0);
91 var secondTextNode = textNode.nextSibling;
92
93 root.normalize();
94
95 expectedFailures.expectFailureFor(
96 goog.editor.BrowserFeature.NORMALIZE_CORRUPTS_EMPTY_TEXT_NODES);
97 try {
98 assertEquals(
99 'text node should not be corrupted', textNode, root.firstChild);
100 } catch (e) {
101 expectedFailures.handleException(e);
102
103 expectedFailures.expectFailureFor(
104 goog.editor.BrowserFeature.NORMALIZE_CORRUPTS_ALL_TEXT_NODES);
105 try {
106 assertEquals(
107 'first text node should be corrupted and replaced by sibling',
108 secondTextNode, root.firstChild);
109 } catch (e) {
110 expectedFailures.handleException(e);
111 }
112 }
113 }