Path: blob/trunk/third_party/closure/goog/html/testing.js
2868 views
// Copyright 2013 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Utilities to create arbitrary values of goog.html types for16* testing purposes. These utility methods perform no validation, and the17* resulting instances may violate type contracts.18*19* These methods are useful when types are constructed in a manner where using20* the production API is too inconvenient. Please do use the production API21* whenever possible; there is value in having tests reflect common usage and it22* avoids, by design, non-contract complying instances from being created.23*/242526goog.provide('goog.html.testing');27goog.setTestOnly();2829goog.require('goog.html.SafeHtml');30goog.require('goog.html.SafeScript');31goog.require('goog.html.SafeStyle');32goog.require('goog.html.SafeStyleSheet');33goog.require('goog.html.SafeUrl');34goog.require('goog.html.TrustedResourceUrl');353637/**38* Creates a SafeHtml wrapping the given value. No validation is performed.39*40* This function is for use in tests only and must never be used in production41* code.42*43* @param {string} html The string to wrap into a SafeHtml.44* @param {?goog.i18n.bidi.Dir=} opt_dir The optional directionality of the45* SafeHtml to be constructed. A null or undefined value signifies an46* unknown directionality.47* @return {!goog.html.SafeHtml}48*/49goog.html.testing.newSafeHtmlForTest = function(html, opt_dir) {50return goog.html.SafeHtml.createSafeHtmlSecurityPrivateDoNotAccessOrElse(51html, (opt_dir == undefined ? null : opt_dir));52};535455/**56* Creates a SafeScript wrapping the given value. No validation is performed.57*58* This function is for use in tests only and must never be used in production59* code.60*61* @param {string} script The string to wrap into a SafeScript.62* @return {!goog.html.SafeScript}63*/64goog.html.testing.newSafeScriptForTest = function(script) {65return goog.html.SafeScript.createSafeScriptSecurityPrivateDoNotAccessOrElse(66script);67};686970/**71* Creates a SafeStyle wrapping the given value. No validation is performed.72*73* This function is for use in tests only and must never be used in production74* code.75*76* @param {string} style String to wrap into a SafeStyle.77* @return {!goog.html.SafeStyle}78*/79goog.html.testing.newSafeStyleForTest = function(style) {80return goog.html.SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(81style);82};838485/**86* Creates a SafeStyleSheet wrapping the given value. No validation is87* performed.88*89* This function is for use in tests only and must never be used in production90* code.91*92* @param {string} styleSheet String to wrap into a SafeStyleSheet.93* @return {!goog.html.SafeStyleSheet}94*/95goog.html.testing.newSafeStyleSheetForTest = function(styleSheet) {96return goog.html.SafeStyleSheet97.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(styleSheet);98};99100101/**102* Creates a SafeUrl wrapping the given value. No validation is performed.103*104* This function is for use in tests only and must never be used in production105* code.106*107* @param {string} url String to wrap into a SafeUrl.108* @return {!goog.html.SafeUrl}109*/110goog.html.testing.newSafeUrlForTest = function(url) {111return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);112};113114115/**116* Creates a TrustedResourceUrl wrapping the given value. No validation is117* performed.118*119* This function is for use in tests only and must never be used in production120* code.121*122* @param {string} url String to wrap into a TrustedResourceUrl.123* @return {!goog.html.TrustedResourceUrl}124*/125goog.html.testing.newTrustedResourceUrlForTest = function(url) {126return goog.html.TrustedResourceUrl127.createTrustedResourceUrlSecurityPrivateDoNotAccessOrElse(url);128};129130131