Debian Codegraph @

closure-library/closure/goog/soy/data_test.js

raw
1 // Copyright 2014 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.soy.dataTest');
16 goog.setTestOnly('goog.soy.dataTest');
17
18 goog.require('goog.html.SafeHtml');
19 goog.require('goog.html.SafeStyleSheet');
20 goog.require('goog.html.SafeUrl');
21 goog.require('goog.html.TrustedResourceUrl');
22 /** @suppress {extraRequire} */
23 goog.require('goog.soy.testHelper');
24 goog.require('goog.testing.jsunit');
25
26
27 function testToSafeHtml() {
28 var html;
29
30 html = example.unsanitizedTextTemplate().toSafeHtml();
31 assertEquals(
32 'I <3 Puppies & Kittens', goog.html.SafeHtml.unwrap(html));
33
34 html = example.sanitizedHtmlTemplate().toSafeHtml();
35 assertEquals('Hello <b>World</b>', goog.html.SafeHtml.unwrap(html));
36 }
37
38 function testToSafeUrl() {
39 var url;
40
41 url = example.sanitizedSmsUrlTemplate().toSafeUrl();
42 assertEquals('sms:123456789', goog.html.SafeUrl.unwrap(url));
43
44 url = example.sanitizedHttpUrlTemplate().toSafeUrl();
45 assertEquals('https://google.com/foo?n=917', goog.html.SafeUrl.unwrap(url));
46 }
47
48 function testToSafeStyleSheet() {
49 var url = example.sanitizedCssTemplate().toSafeStyleSheet();
50 assertEquals('html{display:none}', goog.html.SafeStyleSheet.unwrap(url));
51 }
52
53 function testToTrustedResourceUrl() {
54 var url;
55
56 url = example.sanitizedTrustedResourceUriTemplate({}).toTrustedResourceUrl();
57 assertEquals(
58 'https://google.com/a.js', goog.html.TrustedResourceUrl.unwrap(url));
59 }