iframe_test.js 2.5 KB

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