contenteditablefield_test.js 2.1 KB

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