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