2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
30 test('hasStyleClass', 11, function() {
31 var element = document.createElement('div');
33 ok(!element.hasStyleClass('foo'));
34 ok(!element.hasStyleClass('bar'));
36 element.className = 'foo';
37 ok(element.hasStyleClass('foo'))
38 ok(!element.hasStyleClass('bar'));
40 element.className = 'foo foo';
41 ok(element.hasStyleClass('foo'))
42 ok(!element.hasStyleClass('bar'));
44 element.className = 'foo bar';
45 ok(element.hasStyleClass('foo'))
46 ok(element.hasStyleClass('bar'));
47 ok(!element.hasStyleClass('baz'));
49 element.className = 'food';
50 ok(!element.hasStyleClass('foo'));
51 ok(element.hasStyleClass('food'));
54 test('addStyleClass', 4, function() {
55 var element = document.createElement('div');
57 element.addStyleClass('foo');
58 equal(element.className, ' foo');
60 element.addStyleClass('foo');
61 equal(element.className, ' foo');
63 element.addStyleClass('bar');
64 equal(element.className, ' foo bar');
66 element.addStyleClass('foo');
67 equal(element.className, ' foo bar');
70 test('removeStyleClass', 8, function() {
71 var element = document.createElement('div');
73 element.removeStyleClass('foo');
74 equal(element.className, '');
76 element.className = 'foo';
77 element.removeStyleClass('foo');
78 equal(element.className, '');
80 element.className = ' foo';
81 element.removeStyleClass('foo');
82 equal(element.className, ' ');
84 element.className = 'foo foo';
85 element.removeStyleClass('foo');
86 equal(element.className, ' ');
88 element.className = 'foo bar';
89 element.removeStyleClass('foo');
90 equal(element.className, ' bar');
92 element.className = 'foo bar foo bar';
93 element.removeStyleClass('bar');
94 equal(element.className, 'foo foo ');
96 element.className = 'food';
97 element.removeStyleClass('foo');
98 equal(element.className, 'food');
100 element.className = 'foo';
101 element.removeStyleClass('food');
102 equal(element.className, 'foo');
105 test('toggleStyleClass', 5, function() {
106 var element = document.createElement('div');
108 element.toggleStyleClass('foo');
109 equal(element.className, ' foo');
111 element.toggleStyleClass('foo');
112 equal(element.className, ' ');
114 element.className = 'bar';
115 element.toggleStyleClass('foo');
116 equal(element.className, 'bar foo');
118 element.className = 'food';
119 element.toggleStyleClass('foo');
120 equal(element.className, 'food foo');
122 element.className = 'foo';
123 element.toggleStyleClass('food');
124 equal(element.className, 'foo food');