silverlight_test.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.silverlight.
  16. */
  17. goog.provide('goog.html.silverlightTest');
  18. goog.require('goog.html.SafeHtml');
  19. goog.require('goog.html.TrustedResourceUrl');
  20. goog.require('goog.html.silverlight');
  21. goog.require('goog.string.Const');
  22. goog.require('goog.testing.jsunit');
  23. goog.setTestOnly('goog.html.silverlightTest');
  24. function testCreateObjectForSilverlight() {
  25. var trustedResourceUrl = goog.html.TrustedResourceUrl.fromConstant(
  26. goog.string.Const.from('https://google.com/trusted&'));
  27. assertSameHtml(
  28. '<object data="data:application/x-silverlight-2," ' +
  29. 'type="application/x-silverlight-2" typemustmatch="" ' +
  30. 'class="test&lt;">' +
  31. '<param name="source" value="https://google.com/trusted&amp;">' +
  32. '<param name="onload" value="onload&lt;">' +
  33. '</object>',
  34. goog.html.silverlight.createObject(
  35. trustedResourceUrl, {'onload': 'onload<'}, {'class': 'test<'}));
  36. // Cannot override params, case insensitive.
  37. assertThrows(function() {
  38. goog.html.silverlight.createObject(
  39. trustedResourceUrl, {'datA': 'cantdothis'});
  40. });
  41. // Cannot override attributes, case insensitive.
  42. assertThrows(function() {
  43. goog.html.silverlight.createObject(
  44. trustedResourceUrl, {}, {'datA': 'cantdothis'});
  45. });
  46. }
  47. function assertSameHtml(expected, html) {
  48. assertEquals(expected, goog.html.SafeHtml.unwrap(html));
  49. }