flickr_test.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.FlickrSetTest');
  15. goog.setTestOnly('goog.ui.media.FlickrSetTest');
  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.FlickrSet');
  22. goog.require('goog.ui.media.FlickrSetModel');
  23. goog.require('goog.ui.media.Media');
  24. var flickr;
  25. var control;
  26. var FLICKR_USER = 'ingawalker';
  27. var FLICKR_SET = '72057594102831547';
  28. var FLICKRSET_URL =
  29. 'http://flickr.com/photos/' + FLICKR_USER + '/sets/' + FLICKR_SET;
  30. var parent = goog.dom.createElement(goog.dom.TagName.DIV);
  31. function setUp() {
  32. flickr = new goog.ui.media.FlickrSet();
  33. var set =
  34. new goog.ui.media.FlickrSetModel(FLICKR_USER, FLICKR_SET, 'caption');
  35. control = new goog.ui.media.Media(set, flickr);
  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.FlickrSet.CSS_CLASS, parent);
  44. assertEquals(1, el.length);
  45. assertEquals(FLICKRSET_URL, control.getDataModel().getUrl());
  46. }
  47. function testParsingUrl() {
  48. assertExtractsCorrectly(FLICKR_USER, FLICKR_SET, FLICKRSET_URL);
  49. // user id with @ sign
  50. assertExtractsCorrectly(
  51. '30441750@N06', '7215760789302468',
  52. 'http://flickr.com/photos/30441750@N06/sets/7215760789302468/');
  53. // user id with - sign
  54. assertExtractsCorrectly(
  55. '30441750-N06', '7215760789302468',
  56. 'http://flickr.com/photos/30441750-N06/sets/7215760789302468/');
  57. var invalidUrl = 'http://invalidUrl/filename.doc';
  58. var e = assertThrows(
  59. '', function() { goog.ui.media.FlickrSetModel.newInstance(invalidUrl); });
  60. assertEquals('failed to parse flickr url: ' + invalidUrl, e.message);
  61. }
  62. function testBuildingUrl() {
  63. assertEquals(
  64. FLICKRSET_URL, goog.ui.media.FlickrSetModel.buildUrl(
  65. FLICKR_USER, FLICKR_SET, FLICKRSET_URL));
  66. }
  67. function testCreatingModel() {
  68. var model = new goog.ui.media.FlickrSetModel(FLICKR_USER, FLICKR_SET);
  69. assertEquals(FLICKR_USER, model.getUserId());
  70. assertEquals(FLICKR_SET, model.getSetId());
  71. assertEquals(FLICKRSET_URL, model.getUrl());
  72. assertUndefined(model.getCaption());
  73. }
  74. function testSettingWhichFlashUrlToUse() {
  75. goog.ui.media.FlickrSet.setFlashUrl(
  76. goog.html.testing.newTrustedResourceUrlForTest('http://foo'));
  77. assertEquals(
  78. 'http://foo', goog.ui.media.FlickrSet.flashUrl_.getTypedStringValue());
  79. }
  80. function testCreatingDomOnInitialState() {
  81. control.render(parent);
  82. var caption = goog.dom.getElementsByTagNameAndClass(
  83. goog.dom.TagName.DIV, goog.ui.media.FlickrSet.CSS_CLASS + '-caption',
  84. parent);
  85. assertEquals(1, caption.length);
  86. var flash = goog.dom.getElementsByTagNameAndClass(
  87. goog.dom.TagName.DIV, goog.ui.media.FlashObject.CSS_CLASS, parent);
  88. assertEquals(1, flash.length);
  89. }
  90. function assertExtractsCorrectly(expectedUserId, expectedSetId, url) {
  91. var flickr = goog.ui.media.FlickrSetModel.newInstance(url);
  92. assertEquals('userId for ' + url, expectedUserId, flickr.getUserId());
  93. assertEquals('setId for ' + url, expectedSetId, flickr.getSetId());
  94. }