flash_test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. * @fileoverview Unit tests for goog.html.flash.
  16. */
  17. goog.provide('goog.html.flashTest');
  18. goog.require('goog.html.SafeHtml');
  19. goog.require('goog.html.TrustedResourceUrl');
  20. goog.require('goog.html.flash');
  21. goog.require('goog.string.Const');
  22. goog.require('goog.testing.jsunit');
  23. goog.setTestOnly('goog.html.flashTest');
  24. function testCreateEmbed() {
  25. var trustedResourceUrl = goog.html.TrustedResourceUrl.fromConstant(
  26. goog.string.Const.from('https://google.com/trusted&'));
  27. assertSameHtml(
  28. '<embed ' +
  29. 'src="https://google.com/trusted&amp;" ' +
  30. 'type="application/x-shockwave-flash" ' +
  31. 'pluginspage="https://www.macromedia.com/go/getflashplayer" ' +
  32. 'allownetworking="none" ' +
  33. 'allowScriptAccess="always&lt;" ' +
  34. 'class="test&lt;">',
  35. goog.html.flash.createEmbed(
  36. trustedResourceUrl,
  37. {'allowScriptAccess': 'always<', 'class': 'test<'}));
  38. // Cannot override attributes, case insensitive.
  39. assertThrows(function() {
  40. goog.html.flash.createEmbed(trustedResourceUrl, {'Type': 'cannotdothis'});
  41. });
  42. }
  43. function testCreateObject() {
  44. var trustedResourceUrl = goog.html.TrustedResourceUrl.fromConstant(
  45. goog.string.Const.from('https://google.com/trusted&'));
  46. assertSameHtml(
  47. '<object data="https://google.com/trusted&amp;" ' +
  48. 'type="application/x-shockwave-flash" typemustmatch="" ' +
  49. 'class="test&lt;">' +
  50. '<param name="allownetworking" value="none">' +
  51. '<param name="allowScriptAccess" value="always&lt;">' +
  52. '</object>',
  53. goog.html.flash.createObject(
  54. trustedResourceUrl, {'allowScriptAccess': 'always<'},
  55. {'class': 'test<'}));
  56. // Cannot override params, case insensitive.
  57. assertThrows(function() {
  58. goog.html.flash.createObject(trustedResourceUrl, {'datA': 'cantdothis'});
  59. });
  60. // Cannot override attributes, case insensitive.
  61. assertThrows(function() {
  62. goog.html.flash.createObject(
  63. trustedResourceUrl, {}, {'datA': 'cantdothis'});
  64. });
  65. }
  66. function testCreateObjectForOldIe() {
  67. var trustedResourceUrl = goog.html.TrustedResourceUrl.fromConstant(
  68. goog.string.Const.from('https://google.com/trusted&'));
  69. assertSameHtml(
  70. '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
  71. 'class="test&lt;">' +
  72. '<param name="allownetworking" value="none">' +
  73. '<param name="movie" value="https://google.com/trusted&amp;">' +
  74. '<param name="allowScriptAccess" value="always&lt;">' +
  75. '</object>',
  76. goog.html.flash.createObjectForOldIe(
  77. trustedResourceUrl, {'allowScriptAccess': 'always<'},
  78. {'class': 'test<'}));
  79. // Cannot override params, case insensitive.
  80. assertThrows(function() {
  81. goog.html.flash.createObjectForOldIe(
  82. trustedResourceUrl, {'datA': 'cantdothis'});
  83. });
  84. // Cannot override attributes, case insensitive.
  85. assertThrows(function() {
  86. goog.html.flash.createObjectForOldIe(
  87. trustedResourceUrl, {}, {'datA': 'cantdothis'});
  88. });
  89. }
  90. function assertSameHtml(expected, html) {
  91. assertEquals(expected, goog.html.SafeHtml.unwrap(html));
  92. }