Debian Codegraph @

closure-library/closure/goog/ui/media/mediamodel_test.js

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