Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/html/testing.js
2868 views
1
// Copyright 2013 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
/**
16
* @fileoverview Utilities to create arbitrary values of goog.html types for
17
* testing purposes. These utility methods perform no validation, and the
18
* resulting instances may violate type contracts.
19
*
20
* These methods are useful when types are constructed in a manner where using
21
* the production API is too inconvenient. Please do use the production API
22
* whenever possible; there is value in having tests reflect common usage and it
23
* avoids, by design, non-contract complying instances from being created.
24
*/
25
26
27
goog.provide('goog.html.testing');
28
goog.setTestOnly();
29
30
goog.require('goog.html.SafeHtml');
31
goog.require('goog.html.SafeScript');
32
goog.require('goog.html.SafeStyle');
33
goog.require('goog.html.SafeStyleSheet');
34
goog.require('goog.html.SafeUrl');
35
goog.require('goog.html.TrustedResourceUrl');
36
37
38
/**
39
* Creates a SafeHtml wrapping the given value. No validation is performed.
40
*
41
* This function is for use in tests only and must never be used in production
42
* code.
43
*
44
* @param {string} html The string to wrap into a SafeHtml.
45
* @param {?goog.i18n.bidi.Dir=} opt_dir The optional directionality of the
46
* SafeHtml to be constructed. A null or undefined value signifies an
47
* unknown directionality.
48
* @return {!goog.html.SafeHtml}
49
*/
50
goog.html.testing.newSafeHtmlForTest = function(html, opt_dir) {
51
return goog.html.SafeHtml.createSafeHtmlSecurityPrivateDoNotAccessOrElse(
52
html, (opt_dir == undefined ? null : opt_dir));
53
};
54
55
56
/**
57
* Creates a SafeScript wrapping the given value. No validation is performed.
58
*
59
* This function is for use in tests only and must never be used in production
60
* code.
61
*
62
* @param {string} script The string to wrap into a SafeScript.
63
* @return {!goog.html.SafeScript}
64
*/
65
goog.html.testing.newSafeScriptForTest = function(script) {
66
return goog.html.SafeScript.createSafeScriptSecurityPrivateDoNotAccessOrElse(
67
script);
68
};
69
70
71
/**
72
* Creates a SafeStyle wrapping the given value. No validation is performed.
73
*
74
* This function is for use in tests only and must never be used in production
75
* code.
76
*
77
* @param {string} style String to wrap into a SafeStyle.
78
* @return {!goog.html.SafeStyle}
79
*/
80
goog.html.testing.newSafeStyleForTest = function(style) {
81
return goog.html.SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(
82
style);
83
};
84
85
86
/**
87
* Creates a SafeStyleSheet wrapping the given value. No validation is
88
* performed.
89
*
90
* This function is for use in tests only and must never be used in production
91
* code.
92
*
93
* @param {string} styleSheet String to wrap into a SafeStyleSheet.
94
* @return {!goog.html.SafeStyleSheet}
95
*/
96
goog.html.testing.newSafeStyleSheetForTest = function(styleSheet) {
97
return goog.html.SafeStyleSheet
98
.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(styleSheet);
99
};
100
101
102
/**
103
* Creates a SafeUrl wrapping the given value. No validation is performed.
104
*
105
* This function is for use in tests only and must never be used in production
106
* code.
107
*
108
* @param {string} url String to wrap into a SafeUrl.
109
* @return {!goog.html.SafeUrl}
110
*/
111
goog.html.testing.newSafeUrlForTest = function(url) {
112
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
113
};
114
115
116
/**
117
* Creates a TrustedResourceUrl wrapping the given value. No validation is
118
* performed.
119
*
120
* This function is for use in tests only and must never be used in production
121
* code.
122
*
123
* @param {string} url String to wrap into a TrustedResourceUrl.
124
* @return {!goog.html.TrustedResourceUrl}
125
*/
126
goog.html.testing.newTrustedResourceUrlForTest = function(url) {
127
return goog.html.TrustedResourceUrl
128
.createTrustedResourceUrlSecurityPrivateDoNotAccessOrElse(url);
129
};
130
131