| 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.PicasaTest'); |
| 16 |
goog.setTestOnly('goog.ui.media.PicasaTest'); |
| 17 |
|
| 18 |
goog.require('goog.dom'); |
| 19 |
goog.require('goog.dom.TagName'); |
| 20 |
goog.require('goog.testing.jsunit'); |
| 21 |
goog.require('goog.ui.media.FlashObject'); |
| 22 |
goog.require('goog.ui.media.Media'); |
| 23 |
goog.require('goog.ui.media.PicasaAlbum'); |
| 24 |
goog.require('goog.ui.media.PicasaAlbumModel'); |
| 25 |
var picasa; |
| 26 |
var control; |
| 27 |
var PICASA_USERNAME = 'username'; |
| 28 |
var PICASA_ALBUM = 'albumname'; |
| 29 |
var PICASA_URL = |
| 30 |
'http://picasaweb.google.com/' + PICASA_USERNAME + '/' + PICASA_ALBUM; |
| 31 |
var parent = goog.dom.createElement(goog.dom.TagName.DIV); |
| 32 |
|
| 33 |
function setUp() { |
| 34 |
picasa = new goog.ui.media.PicasaAlbum(); |
| 35 |
var model = new goog.ui.media.PicasaAlbumModel( |
| 36 |
PICASA_USERNAME, PICASA_ALBUM, null, 'album title'); |
| 37 |
control = new goog.ui.media.Media(model, picasa); |
| 38 |
control.setSelected(true); |
| 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.PicasaAlbum.CSS_CLASS, parent); |
| 49 |
assertEquals(1, el.length); |
| 50 |
assertEquals(PICASA_URL, control.getDataModel().getUrl()); |
| 51 |
} |
| 52 |
|
| 53 |
function testParsingUrl() { |
| 54 |
assertExtractsCorrectly(PICASA_USERNAME, PICASA_ALBUM, null, PICASA_URL); |
| 55 |
assertExtractsCorrectly( |
| 56 |
'foo', 'bar', null, 'https://picasaweb.google.com/foo/bar'); |
| 57 |
assertExtractsCorrectly( |
| 58 |
'foo', 'bar', null, 'https://www.picasaweb.google.com/foo/bar'); |
| 59 |
assertExtractsCorrectly( |
| 60 |
'foo', 'bar', null, 'https://www.picasaweb.com/foo/bar'); |
| 61 |
assertExtractsCorrectly( |
| 62 |
'foo', 'bar', '8Hzg1CUUAZM', |
| 63 |
'https://www.picasaweb.com/foo/bar?authkey=8Hzg1CUUAZM#'); |
| 64 |
assertExtractsCorrectly( |
| 65 |
'foo', 'bar', '8Hzg1CUUAZM', |
| 66 |
'https://www.picasaweb.com/foo/bar?foo=bar&authkey=8Hzg1CUUAZM#'); |
| 67 |
assertExtractsCorrectly( |
| 68 |
'foo', 'bar', '8Hzg1CUUAZM', |
| 69 |
'https://www.picasaweb.com/foo/bar?foo=bar&authkey=8Hzg1CUUAZM&' + |
| 70 |
'hello=world#'); |
| 71 |
|
| 72 |
var invalidUrl = 'http://invalidUrl/watch?v=dMH0bHeiRNg'; |
| 73 |
var e = assertThrows('parser expects a well formed URL', function() { |
| 74 |
goog.ui.media.PicasaAlbumModel.newInstance(invalidUrl); |
| 75 |
}); |
| 76 |
assertEquals( |
| 77 |
'failed to parse user and album from picasa url: ' + invalidUrl, |
| 78 |
e.message); |
| 79 |
} |
| 80 |
|
| 81 |
function testBuildingUrl() { |
| 82 |
assertEquals( |
| 83 |
PICASA_URL, |
| 84 |
goog.ui.media.PicasaAlbumModel.buildUrl(PICASA_USERNAME, PICASA_ALBUM)); |
| 85 |
} |
| 86 |
|
| 87 |
function testCreatingModel() { |
| 88 |
var model = new goog.ui.media.PicasaAlbumModel(PICASA_USERNAME, PICASA_ALBUM); |
| 89 |
assertEquals(PICASA_USERNAME, model.getUserId()); |
| 90 |
assertEquals(PICASA_ALBUM, model.getAlbumId()); |
| 91 |
assertEquals(PICASA_URL, model.getUrl()); |
| 92 |
assertUndefined(model.getCaption()); |
| 93 |
} |
| 94 |
|
| 95 |
function testCreatingDomOnInitialState() { |
| 96 |
control.render(parent); |
| 97 |
var caption = goog.dom.getElementsByTagNameAndClass( |
| 98 |
goog.dom.TagName.DIV, goog.ui.media.PicasaAlbum.CSS_CLASS + '-caption', |
| 99 |
parent); |
| 100 |
assertEquals(1, caption.length); |
| 101 |
|
| 102 |
var flash = goog.dom.getElementsByTagNameAndClass( |
| 103 |
goog.dom.TagName.DIV, goog.ui.media.FlashObject.CSS_CLASS, parent); |
| 104 |
assertEquals(1, flash.length); |
| 105 |
} |
| 106 |
|
| 107 |
function assertExtractsCorrectly( |
| 108 |
expectedUserId, expectedAlbumId, expectedAuthKey, url) { |
| 109 |
var model = goog.ui.media.PicasaAlbumModel.newInstance(url); |
| 110 |
assertEquals('User for ' + url, expectedUserId, model.getUserId()); |
| 111 |
assertEquals('Album for ' + url, expectedAlbumId, model.getAlbumId()); |
| 112 |
assertEquals('AuthKey for ' + url, expectedAuthKey, model.getAuthKey()); |
| 113 |
} |