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