// Copyright 2013 The Closure Library Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS-IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * @fileoverview Unit tests for goog.html.util. */ goog.provide('goog.html.UtilsTest'); goog.require('goog.array'); goog.require('goog.dom.TagName'); goog.require('goog.html.utils'); goog.require('goog.object'); goog.require('goog.testing.jsunit'); goog.setTestOnly('goog.html.UtilsTest'); var FAILURE_MESSAGE = 'Failed to strip all HTML.'; var STRIP = 'Hello world!'; var result; function tearDown() { result = null; } function testStripAllHtmlTagsSingle() { goog.object.forEach(goog.dom.TagName, function(tag) { result = goog.html.utils.stripHtmlTags(makeHtml_(tag, STRIP)); assertEquals(FAILURE_MESSAGE, STRIP, result); }); } function testStripAllHtmlTagsAttribute() { goog.object.forEach(goog.dom.TagName, function(tag) { result = goog.html.utils.stripHtmlTags(makeHtml_(tag, STRIP, 1, 0, 'a')); assertEquals(FAILURE_MESSAGE, STRIP, result); }); } function testStripAllHtmlTagsDouble() { var tag1 = goog.dom.TagName.B; var tag2 = goog.dom.TagName.DIV; result = goog.html.utils.stripHtmlTags(makeHtml_(tag1, STRIP, 2)); assertEquals(FAILURE_MESSAGE, STRIP + STRIP, result); result = goog.html.utils.stripHtmlTags(makeHtml_(tag2, STRIP, 2)); assertEquals(FAILURE_MESSAGE, STRIP + ' ' + STRIP, result); } function testComplex() { var html = '
Read and interact with the information below to learn about ' + 'life at Google.
' + 'Google has the best food in the world.
' + 'Google provides free transportation.
' + // Some text with symbols to make sure that it does not get stripped '<3i>