Debian Codegraph @

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

raw
1 // Copyright 2012 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.ContentEditableFieldTest');
16 goog.setTestOnly('goog.editor.ContentEditableFieldTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.editor.ContentEditableField');
20 /** @suppress {extraRequire} needed for test setup */
21 goog.require('goog.editor.field_test');
22 goog.require('goog.html.SafeHtml');
23 goog.require('goog.testing.jsunit');
24
25 FieldConstructor = goog.editor.ContentEditableField;
26
27 function testNoIframeAndSameElement() {
28 var field = new goog.editor.ContentEditableField('testField');
29 field.makeEditable();
30 assertFalse(field.usesIframe());
31 assertEquals(
32 'Original element should equal field element', field.getOriginalElement(),
33 field.getElement());
34 assertEquals(
35 'Sanity check on original element', 'testField',
36 field.getOriginalElement().id);
37 assertEquals(
38 'Editable document should be same as main document', document,
39 field.getEditableDomHelper().getDocument());
40 field.dispose();
41 }
42
43 function testMakeEditableAndUnEditable() {
44 var elem = goog.dom.getElement('testField');
45 goog.dom.setTextContent(elem, 'Hello world');
46 var field = new goog.editor.ContentEditableField('testField');
47
48 field.makeEditable();
49 assertEquals('true', String(elem.contentEditable));
50 assertEquals('Hello world', goog.dom.getTextContent(elem));
51 field.setSafeHtml(
52 false /* addParas */, goog.html.SafeHtml.htmlEscape('Goodbye world'));
53 assertEquals('Goodbye world', goog.dom.getTextContent(elem));
54
55 field.makeUneditable();
56 assertNotEquals('true', String(elem.contentEditable));
57 assertEquals('Goodbye world', goog.dom.getTextContent(elem));
58 field.dispose();
59 }