vimeo_test.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.VimeoTest');
  15. goog.setTestOnly('goog.ui.media.VimeoTest');
  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.Media');
  21. goog.require('goog.ui.media.Vimeo');
  22. goog.require('goog.ui.media.VimeoModel');
  23. var vimeo;
  24. var control;
  25. var VIMEO_ID = '3001295';
  26. var VIMEO_URL = 'http://vimeo.com/' + VIMEO_ID;
  27. var VIMEO_URL_HD = 'http://vimeo.com/hd#' + VIMEO_ID;
  28. var VIMEO_URL_SECURE = 'https://vimeo.com/' + VIMEO_ID;
  29. var parent = goog.dom.createElement(goog.dom.TagName.DIV);
  30. function setUp() {
  31. vimeo = new goog.ui.media.Vimeo();
  32. var model = new goog.ui.media.VimeoModel(VIMEO_ID, 'vimeo caption');
  33. control = new goog.ui.media.Media(model, vimeo);
  34. control.setSelected(true);
  35. }
  36. function tearDown() {
  37. control.dispose();
  38. }
  39. function testBasicRendering() {
  40. control.render(parent);
  41. var el = goog.dom.getElementsByTagNameAndClass(
  42. goog.dom.TagName.DIV, goog.ui.media.Vimeo.CSS_CLASS, parent);
  43. assertEquals(1, el.length);
  44. assertEquals(VIMEO_URL, control.getDataModel().getUrl());
  45. }
  46. function testParsingUrl() {
  47. assertExtractsCorrectly(VIMEO_ID, VIMEO_URL);
  48. assertExtractsCorrectly(VIMEO_ID, VIMEO_URL_HD);
  49. assertExtractsCorrectly(VIMEO_ID, VIMEO_URL_SECURE);
  50. var invalidUrl = 'http://invalidUrl/filename.doc';
  51. var e = assertThrows('parser expects a well formed URL', function() {
  52. goog.ui.media.VimeoModel.newInstance(invalidUrl);
  53. });
  54. assertEquals('failed to parse vimeo url: ' + invalidUrl, e.message);
  55. }
  56. function testBuildingUrl() {
  57. assertEquals(VIMEO_URL, goog.ui.media.VimeoModel.buildUrl(VIMEO_ID));
  58. }
  59. function testCreatingModel() {
  60. var model = new goog.ui.media.VimeoModel(VIMEO_ID);
  61. assertEquals(VIMEO_ID, model.getVideoId());
  62. assertEquals(VIMEO_URL, model.getUrl());
  63. assertUndefined(model.getCaption());
  64. }
  65. function testCreatingDomOnInitialState() {
  66. control.render(parent);
  67. var caption = goog.dom.getElementsByTagNameAndClass(
  68. goog.dom.TagName.DIV, goog.ui.media.Vimeo.CSS_CLASS + '-caption', parent);
  69. assertEquals(1, caption.length);
  70. var flash = goog.dom.getElementsByTagNameAndClass(
  71. goog.dom.TagName.DIV, goog.ui.media.FlashObject.CSS_CLASS, parent);
  72. assertEquals(1, flash.length);
  73. }
  74. function assertExtractsCorrectly(expectedVideoId, url) {
  75. var model = goog.ui.media.VimeoModel.newInstance(url);
  76. assertEquals('Video id for ' + url, expectedVideoId, model.getVideoId());
  77. }