mediamodel_test.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2011 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.ui.media.MediaModelTest');
  15. goog.setTestOnly('goog.ui.media.MediaModelTest');
  16. goog.require('goog.testing.jsunit');
  17. goog.require('goog.ui.media.MediaModel');
  18. /**
  19. * A simple model used in many tests.
  20. */
  21. var model;
  22. function setUp() {
  23. model = new goog.ui.media.MediaModel(
  24. 'http://url.com', 'a caption', 'a description');
  25. }
  26. function testMediaModel() {
  27. assertEquals('http://url.com', model.getUrl());
  28. assertEquals('a caption', model.getCaption());
  29. assertEquals('a description', model.getDescription());
  30. var incompleteModel = new goog.ui.media.MediaModel(
  31. 'http://foo.bar', undefined,
  32. 'This media has no caption but has a description and a URL');
  33. assertEquals('http://foo.bar', incompleteModel.getUrl());
  34. assertUndefined(incompleteModel.getCaption());
  35. assertEquals(
  36. 'This media has no caption but has a description and a URL',
  37. incompleteModel.getDescription());
  38. assertArrayEquals([], incompleteModel.getThumbnails());
  39. }
  40. function testMediaModelFindCategoryWithScheme() {
  41. assertNull(model.findCategoryWithScheme('no such scheme'));
  42. model.setCategories([
  43. new goog.ui.media.MediaModel.Category('scheme-a', 'value-a'),
  44. new goog.ui.media.MediaModel.Category('scheme-b', 'value-b')
  45. ]);
  46. assertNull(model.findCategoryWithScheme('no such scheme'));
  47. assertEquals('value-a', model.findCategoryWithScheme('scheme-a').getValue());
  48. assertEquals('value-b', model.findCategoryWithScheme('scheme-b').getValue());
  49. }
  50. function testMediaModelFindCreditsWithRole() {
  51. assertEquals(0, model.findCreditsWithRole('no such role').length);
  52. model.setCredits([
  53. new goog.ui.media.MediaModel.Credit('value-a', 'role-a'),
  54. new goog.ui.media.MediaModel.Credit('value-a2', 'role-a'),
  55. new goog.ui.media.MediaModel.Credit('value-b', 'role-b')
  56. ]);
  57. assertEquals(0, model.findCreditsWithRole('no such role').length);
  58. assertEquals(2, model.findCreditsWithRole('role-a').length);
  59. assertEquals('value-a', model.findCreditsWithRole('role-a')[0].getValue());
  60. assertEquals('value-a2', model.findCreditsWithRole('role-a')[1].getValue());
  61. assertEquals('value-b', model.findCreditsWithRole('role-b')[0].getValue());
  62. }
  63. function testMediaModelSubtitles() {
  64. model.setSubTitles([new goog.ui.media.MediaModel.SubTitle(
  65. 'uri', '*', 'application/tts+xml')]);
  66. assertEquals(1, model.getSubTitles().length);
  67. assertEquals('uri', model.getSubTitles()[0].getHref());
  68. assertEquals('*', model.getSubTitles()[0].getLang());
  69. assertEquals('application/tts+xml', model.getSubTitles()[0].getType());
  70. }
  71. function testMediaModelNoSubtitles() {
  72. assertEquals(0, model.getSubTitles().length);
  73. }