Debian Codegraph @

closure-library/closure/goog/dom/iframe_test.js

raw
1 // Copyright 2008 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.dom.iframeTest');
16 goog.setTestOnly('goog.dom.iframeTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.dom.iframe');
20 goog.require('goog.html.SafeHtml');
21 goog.require('goog.html.SafeStyle');
22 goog.require('goog.string.Const');
23 goog.require('goog.testing.jsunit');
24
25 var domHelper;
26 var sandbox;
27
28 function setUpPage() {
29 domHelper = goog.dom.getDomHelper();
30 sandbox = domHelper.getElement('sandbox');
31 }
32
33 function setUp() {
34 goog.dom.removeChildren(sandbox);
35 }
36
37 function testCreateWithContent_safeTypes() {
38 var head = goog.html.SafeHtml.create('title', {}, 'Foo Title');
39 var body = goog.html.SafeHtml.create('div', {'id': 'blah'}, 'Test');
40 var style = goog.html.SafeStyle.fromConstant(
41 goog.string.Const.from('position: absolute;'));
42 var iframe = goog.dom.iframe.createWithContent(
43 sandbox, head, body, style, false /* opt_quirks */);
44
45 var doc = goog.dom.getFrameContentDocument(iframe);
46 assertNotNull(doc.getElementById('blah'));
47 assertEquals('Foo Title', doc.title);
48 assertEquals('absolute', iframe.style.position);
49 }
50
51 function testCreateBlankYieldsIframeWithNoBorderOrPadding() {
52 var iframe = goog.dom.iframe.createBlank(domHelper);
53 iframe.style.width = '350px';
54 iframe.style.height = '250px';
55 var blankElement = domHelper.getElement('blank');
56 blankElement.appendChild(iframe);
57 assertEquals(
58 'Width should be as styled: no extra borders, padding, etc.', 350,
59 blankElement.offsetWidth);
60 assertEquals(
61 'Height should be as styled: no extra borders, padding, etc.', 250,
62 blankElement.offsetHeight);
63 }
64
65 function testCreateBlankWithSafeStyles() {
66 var iframe = goog.dom.iframe.createBlank(
67 domHelper, goog.html.SafeStyle.fromConstant(
68 goog.string.Const.from('position:absolute;')));
69 assertEquals('absolute', iframe.style.position);
70 assertEquals('bottom', iframe.style.verticalAlign);
71 }