Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: Tools/GardeningServer/scripts/base_unittests.js

Issue 400423002: Remove base.* methods. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Tools/GardeningServer/scripts/base.js ('k') | Tools/GardeningServer/scripts/config.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26 (function () {
27
28 module("base");
29
30 test("joinPath", 1, function() {
31 var value = base.joinPath("path/to", "test.html");
32 equals(value, "path/to/test.html");
33 });
34
35 test("endsWith", 9, function() {
36 ok(base.endsWith("xyz", ""));
37 ok(base.endsWith("xyz", "z"));
38 ok(base.endsWith("xyz", "yz"));
39 ok(base.endsWith("xyz", "xyz"));
40 ok(!base.endsWith("xyz", "wxyz"));
41 ok(!base.endsWith("xyz", "gwxyz"));
42 ok(base.endsWith("", ""));
43 ok(!base.endsWith("", "z"));
44 ok(!base.endsWith("xyxy", "yx"));
45 });
46
47 test("trimExtension", 6, function() {
48 equals(base.trimExtension("xyz"), "xyz");
49 equals(base.trimExtension("xy.z"), "xy");
50 equals(base.trimExtension("x.yz"), "x");
51 equals(base.trimExtension("x.y.z"), "x.y");
52 equals(base.trimExtension(".xyz"), "");
53 equals(base.trimExtension(""), "");
54 });
55
56 test("joinPath with empty parent", 1, function() {
57 var value = base.joinPath("", "test.html");
58 equals(value, "test.html");
59 });
60
61 test("uniquifyArray", 5, function() {
62 deepEqual(base.uniquifyArray([]), []);
63 deepEqual(base.uniquifyArray(["a"]), ["a"]);
64 deepEqual(base.uniquifyArray(["a", "b"]), ["a", "b"]);
65 deepEqual(base.uniquifyArray(["a", "b", "b"]), ["a", "b"]);
66 deepEqual(base.uniquifyArray(["a", "b", "b", "a"]), ["a", "b"]);
67 });
68
69 test("filterTree", 2, function() {
70 var tree = {
71 'path': {
72 'to': {
73 'test.html': {
74 'actual': 'PASS',
75 'expected': 'FAIL'
76 }
77 },
78 'another.html': {
79 'actual': 'TEXT',
80 'expected': 'PASS'
81 }
82 }
83 }
84
85 function isLeaf(node)
86 {
87 return !!node.actual;
88 }
89
90 function actualIsText(node)
91 {
92 return node.actual == 'TEXT';
93 }
94
95 var all = base.filterTree(tree, isLeaf, function() { return true });
96 deepEqual(all, {
97 'path/to/test.html': {
98 'actual': 'PASS',
99 'expected': 'FAIL'
100 },
101 'path/another.html': {
102 'actual': 'TEXT',
103 'expected': 'PASS'
104 }
105 });
106
107 var text = base.filterTree(tree, isLeaf, actualIsText);
108 deepEqual(text, {
109 'path/another.html': {
110 'actual': 'TEXT',
111 'expected': 'PASS'
112 }
113 });
114 });
115
116 test("extends", 14, function() {
117
118 var LikeDiv = base.extends("div", {
119 init: function() {
120 this.textContent = "awesome";
121 },
122 method: function(msg) {
123 return 42;
124 }
125 });
126
127 var LikeLikeDiv = base.extends(LikeDiv, {
128 init: function() {
129 this.className = "like";
130 }
131 });
132
133 var LikeP = base.extends("p", {
134 init: function(content) {
135 this.textContent = content
136 }
137 });
138
139 var LikeProgress = base.extends("progress", {
140 init: function() {
141 this.max = 100;
142 this.value = 10;
143 }
144 });
145
146 var LikeLikeProgress = base.extends(LikeProgress, {
147 completed: function() {
148 this.value = 100;
149 }
150 });
151
152 document.body.appendChild(new LikeDiv());
153 equals(document.body.lastChild.tagName, "DIV");
154 equals(document.body.lastChild.innerHTML, "awesome");
155 equals(document.body.lastChild.method(), 42);
156 document.body.removeChild(document.body.lastChild);
157
158 document.body.appendChild(new LikeLikeDiv());
159 equals(document.body.lastChild.tagName, "DIV");
160 equals(document.body.lastChild.innerHTML, "awesome");
161 equals(document.body.lastChild.method(), 42);
162 equals(document.body.lastChild.className, "like");
163 document.body.removeChild(document.body.lastChild);
164
165 document.body.appendChild(new LikeP("super"));
166 equals(document.body.lastChild.tagName, "P");
167 equals(document.body.lastChild.innerHTML, "super");
168 raises(function() {
169 document.body.lastChild.method();
170 });
171 document.body.removeChild(document.body.lastChild);
172
173 document.body.appendChild(new LikeProgress());
174 equals(document.body.lastChild.tagName, "PROGRESS");
175 // Safari 5.1 lacks the <progress> element.
176 // equals(document.body.lastChild.position, 0.1);
177 equals(document.body.lastChild.innerHTML, "");
178 raises(function() {
179 document.body.lastChild.method();
180 });
181 document.body.removeChild(document.body.lastChild);
182
183 document.body.appendChild(new LikeLikeProgress());
184 equals(document.body.lastChild.tagName, "PROGRESS");
185 // Safari 5.1 lacks the <progress> element.
186 // equals(document.body.lastChild.position, 0.1);
187 document.body.lastChild.completed();
188 // Safari 5.1 lacks the <progress> element.
189 // equals(document.body.lastChild.position, 1);
190 document.body.removeChild(document.body.lastChild);
191 });
192
193 test("parseJSONP", 6, function() {
194 deepEqual(base.parseJSONP(""), {});
195 deepEqual(base.parseJSONP('p({"key": "value"})'), {"key": "value"});
196 deepEqual(base.parseJSONP('ADD_RESULTS({"dummy":"data"});'), {"dummy":"data" });
197 deepEqual(base.parseJSONP('{"dummy":"data"}'), {"dummy":"data"});
198 deepEqual(base.parseJSONP('ADD_RESULTS({"builder(1)":"data"});'), {"builder( 1)":"data"});
199 deepEqual(base.parseJSONP('{"builder(1)":"data"}'), {"builder(1)":"data"});
200 });
201
202 test("base.queryParam", 2, function() {
203 equal(base.queryParam({}), '');
204 equal(base.queryParam({
205 'foo bar': 'bar baz',
206 '1 2': '3 4',
207 }), 'foo+bar=bar+baz&1+2=3+4');
208 });
209
210 })();
OLDNEW
« no previous file with comments | « Tools/GardeningServer/scripts/base.js ('k') | Tools/GardeningServer/scripts/config.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698