| 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 |
|
| 15 |
goog.provide('goog.style.transitionTest'); |
| 16 |
goog.setTestOnly('goog.style.transitionTest'); |
| 17 |
|
| 18 |
goog.require('goog.style'); |
| 19 |
goog.require('goog.style.transition'); |
| 20 |
goog.require('goog.testing.jsunit'); |
| 21 |
goog.require('goog.userAgent'); |
| 22 |
|
| 23 |
|
| 24 |
/** Fake element. */ |
| 25 |
var element; |
| 26 |
|
| 27 |
|
| 28 |
function setUp() { |
| 29 |
element = {'style': {}}; |
| 30 |
} |
| 31 |
|
| 32 |
function getTransitionStyle(element) { |
| 33 |
return element.style['transition'] || |
| 34 |
goog.style.getStyle(element, 'transition'); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
function testSetWithNoProperty() { |
| 39 |
try { |
| 40 |
goog.style.transition.set(element, []); |
| 41 |
} catch (e) { |
| 42 |
return; |
| 43 |
} |
| 44 |
fail('Should fail when no property is given.'); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
function testSetWithString() { |
| 49 |
goog.style.transition.set(element, 'opacity 1s ease-in 0.125s'); |
| 50 |
assertEquals('opacity 1s ease-in 0.125s', getTransitionStyle(element)); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
function testSetWithSingleProperty() { |
| 55 |
goog.style.transition.set( |
| 56 |
element, |
| 57 |
{property: 'opacity', duration: 1, timing: 'ease-in', delay: 0.125}); |
| 58 |
assertEquals('opacity 1s ease-in 0.125s', getTransitionStyle(element)); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
function testSetWithMultipleStrings() { |
| 63 |
goog.style.transition.set( |
| 64 |
element, ['width 1s ease-in', 'height 0.5s linear 1s']); |
| 65 |
assertEquals( |
| 66 |
'width 1s ease-in,height 0.5s linear 1s', getTransitionStyle(element)); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
function testSetWithMultipleProperty() { |
| 71 |
goog.style.transition.set(element, [ |
| 72 |
{property: 'width', duration: 1, timing: 'ease-in', delay: 0}, |
| 73 |
{property: 'height', duration: 0.5, timing: 'linear', delay: 1} |
| 74 |
]); |
| 75 |
assertEquals( |
| 76 |
'width 1s ease-in 0s,height 0.5s linear 1s', getTransitionStyle(element)); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
function testRemoveAll() { |
| 81 |
goog.style.setStyle(element, 'transition', 'opacity 1s ease-in'); |
| 82 |
goog.style.transition.removeAll(element); |
| 83 |
assertEquals('', getTransitionStyle(element)); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
function testAddAndRemoveOnRealElement() { |
| 88 |
if (!goog.style.transition.isSupported()) { |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
var div = document.getElementById('test'); |
| 93 |
goog.style.transition.set(div, 'opacity 1s ease-in 125ms'); |
| 94 |
assertEquals('opacity 1s ease-in 125ms', getTransitionStyle(div)); |
| 95 |
goog.style.transition.removeAll(div); |
| 96 |
assertEquals('', getTransitionStyle(div)); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
function testSanityDetectionOfCss3Transition() { |
| 101 |
var support = goog.style.transition.isSupported(); |
| 102 |
|
| 103 |
// IE support starts at IE10. |
| 104 |
if (goog.userAgent.IE) { |
| 105 |
assertEquals(goog.userAgent.isVersionOrHigher('10.0'), support); |
| 106 |
} |
| 107 |
|
| 108 |
// FF support start at FF4 (Gecko 2.0) |
| 109 |
if (goog.userAgent.GECKO) { |
| 110 |
assertEquals(goog.userAgent.isVersionOrHigher('2.0'), support); |
| 111 |
} |
| 112 |
|
| 113 |
// Webkit support has existed for a long time, we assume support on |
| 114 |
// most webkit version in used today. |
| 115 |
if (goog.userAgent.WEBKIT) { |
| 116 |
assertTrue(support); |
| 117 |
} |
| 118 |
} |