googlevideo_test.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.GoogleVideoTest');
  15. goog.setTestOnly('goog.ui.media.GoogleVideoTest');
  16. goog.require('goog.dom');
  17. goog.require('goog.dom.TagName');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.ui.media.FlashObject');
  20. goog.require('goog.ui.media.GoogleVideo');
  21. goog.require('goog.ui.media.GoogleVideoModel');
  22. goog.require('goog.ui.media.Media');
  23. var video;
  24. var control;
  25. var VIDEO_URL_PREFIX = 'http://video.google.com/videoplay?docid=';
  26. var VIDEO_ID = '7582902000166025817';
  27. var VIDEO_URL = VIDEO_URL_PREFIX + VIDEO_ID;
  28. var parent = goog.dom.createElement(goog.dom.TagName.DIV);
  29. function setUp() {
  30. video = new goog.ui.media.GoogleVideo();
  31. var model = new goog.ui.media.GoogleVideoModel(VIDEO_ID, 'video caption');
  32. control = new goog.ui.media.Media(model, video);
  33. control.setSelected(true);
  34. }
  35. function tearDown() {
  36. control.dispose();
  37. }
  38. function testBasicRendering() {
  39. control.render(parent);
  40. var el = goog.dom.getElementsByTagNameAndClass(
  41. goog.dom.TagName.DIV, goog.ui.media.GoogleVideo.CSS_CLASS, parent);
  42. assertEquals(1, el.length);
  43. assertEquals(VIDEO_URL, control.getDataModel().getUrl());
  44. }
  45. function testParsingUrl() {
  46. assertExtractsCorrectly(VIDEO_ID, VIDEO_URL);
  47. // Test a url with # at the end.
  48. assertExtractsCorrectly(VIDEO_ID, VIDEO_URL + '#');
  49. // Test a url with a negative docid.
  50. assertExtractsCorrectly('-123', VIDEO_URL_PREFIX + '-123');
  51. // Test a url with two docids. The valid one is the second.
  52. assertExtractsCorrectly('123', VIDEO_URL + '#docid=123');
  53. var invalidUrl = 'http://invalidUrl/filename.doc';
  54. var e = assertThrows('parser expects a well formed URL', function() {
  55. goog.ui.media.GoogleVideoModel.newInstance(invalidUrl);
  56. });
  57. assertEquals(
  58. 'failed to parse video id from GoogleVideo url: ' + invalidUrl,
  59. e.message);
  60. }
  61. function testBuildingUrl() {
  62. assertEquals(VIDEO_URL, goog.ui.media.GoogleVideoModel.buildUrl(VIDEO_ID));
  63. }
  64. function testCreatingModel() {
  65. var model = new goog.ui.media.GoogleVideoModel(VIDEO_ID);
  66. assertEquals(VIDEO_ID, model.getVideoId());
  67. assertEquals(VIDEO_URL, model.getUrl());
  68. assertUndefined(model.getCaption());
  69. }
  70. function testCreatingDomOnInitialState() {
  71. control.render(parent);
  72. var caption = goog.dom.getElementsByTagNameAndClass(
  73. goog.dom.TagName.DIV, goog.ui.media.GoogleVideo.CSS_CLASS + '-caption',
  74. parent);
  75. assertEquals(1, caption.length);
  76. var flash = goog.dom.getElementsByTagNameAndClass(
  77. goog.dom.TagName.DIV, goog.ui.media.FlashObject.CSS_CLASS, parent);
  78. assertEquals(1, flash.length);
  79. }
  80. function assertExtractsCorrectly(expectedVideoId, url) {
  81. var model = goog.ui.media.GoogleVideoModel.newInstance(url);
  82. assertEquals('Video id for ' + url, expectedVideoId, model.getVideoId());
  83. }