mp3_test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2009 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.Mp3Test');
  15. goog.setTestOnly('goog.ui.media.Mp3Test');
  16. goog.require('goog.dom');
  17. goog.require('goog.dom.TagName');
  18. goog.require('goog.html.testing');
  19. goog.require('goog.testing.jsunit');
  20. goog.require('goog.ui.media.FlashObject');
  21. goog.require('goog.ui.media.Media');
  22. goog.require('goog.ui.media.MediaModel');
  23. goog.require('goog.ui.media.Mp3');
  24. var mp3;
  25. var control;
  26. var MP3_URL = 'http://www.shellworld.net/~davidsky/surf-oxy.mp3';
  27. var parent = goog.dom.createElement(goog.dom.TagName.DIV);
  28. function setUp() {
  29. mp3 = goog.ui.media.Mp3.getInstance();
  30. var flashUrl = goog.ui.media.Mp3.buildFlashUrl(MP3_URL);
  31. var model = new goog.ui.media.MediaModel(MP3_URL, 'mp3 caption', '');
  32. model.setPlayer(new goog.ui.media.MediaModel.Player(
  33. goog.html.testing.newTrustedResourceUrlForTest(flashUrl)));
  34. control = new goog.ui.media.Media(model, mp3);
  35. control.setSelected(true);
  36. }
  37. function tearDown() {
  38. control.dispose();
  39. }
  40. function testBasicRendering() {
  41. control.render(parent);
  42. var el = goog.dom.getElementsByTagNameAndClass(
  43. goog.dom.TagName.DIV, goog.ui.media.Mp3.CSS_CLASS, parent);
  44. assertEquals(1, el.length);
  45. }
  46. function testParsingUrl() {
  47. assertTrue(goog.ui.media.Mp3.MATCHER.test(MP3_URL));
  48. assertFalse(goog.ui.media.Mp3.MATCHER.test('http://invalidUrl/filename.doc'));
  49. }
  50. function testCreatingDomOnInitialState() {
  51. control.render(parent);
  52. var caption = goog.dom.getElementsByTagNameAndClass(
  53. goog.dom.TagName.DIV, goog.ui.media.Mp3.CSS_CLASS + '-caption', parent);
  54. assertEquals(1, caption.length);
  55. var flash = goog.dom.getElementsByTagNameAndClass(
  56. undefined, goog.ui.media.FlashObject.CSS_CLASS, parent);
  57. assertEquals(1, flash.length);
  58. }