OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function debug(message) | |
6 { | |
7 document.getElementById('status').innerHTML += '<br/>' + message; | |
8 } | |
9 | |
10 function done(message) | |
11 { | |
12 if (document.location.hash == '#fail') | |
13 return; | |
14 if (message) | |
15 debug('PASS: ' + message); | |
16 else | |
17 debug('PASS'); | |
18 document.location.hash = '#pass'; | |
19 } | |
20 | |
21 function fail(message) | |
22 { | |
23 debug('FAILED: ' + message); | |
24 document.location.hash = '#fail'; | |
25 } | |
26 | |
27 function getLog() | |
28 { | |
29 return "" + document.getElementById('status').innerHTML; | |
30 } | |
31 | |
32 function fileErrorToString(e) { | |
33 switch (e.code) { | |
34 case FileError.QUOTA_EXCEEDED_ERR: | |
35 msg = 'QUOTA_EXCEEDED_ERR'; | |
36 break; | |
37 case FileError.NOT_FOUND_ERR: | |
38 msg = 'NOT_FOUND_ERR'; | |
39 break; | |
40 case FileError.SECURITY_ERR: | |
41 msg = 'SECURITY_ERR'; | |
42 break; | |
43 case FileError.INVALID_MODIFICATION_ERR: | |
44 msg = 'INVALID_MODIFICATION_ERR'; | |
45 break; | |
46 case FileError.INVALID_STATE_ERR: | |
47 msg = 'INVALID_STATE_ERR'; | |
48 break; | |
49 default: | |
50 msg = 'Unknown Error'; | |
51 break; | |
52 }; | |
53 return msg; | |
54 } | |
55 | |
56 function unexpectedAbortCallback() | |
57 { | |
58 fail('unexpectedAbortCallback'); | |
59 } | |
60 | |
61 function unexpectedSuccessCallback() | |
62 { | |
63 fail('unexpectedSuccessCallback'); | |
64 } | |
65 | |
66 function unexpectedCompleteCallback() | |
67 { | |
68 fail('unexpectedCompleteCallback'); | |
69 } | |
kinuko
2011/08/29 08:55:01
These unexpected{Abort,Success,Complete}Callbacks
Dai Mikurube (NOT FULLTIME)
2011/08/30 08:07:55
Thanks. I forgot to remove them. I was using cod
| |
70 | |
71 function unexpectedErrorCallback(e) | |
72 { | |
73 fail('unexpectedErrorCallback:' + fileErrorToString(e)); | |
74 } | |
75 | |
76 function deleteAllObjectStores(db) | |
kinuko
2011/08/29 08:55:01
Not for fileapi?
Dai Mikurube (NOT FULLTIME)
2011/08/30 08:07:55
Done.
| |
77 { | |
78 objectStoreNames = db.objectStoreNames; | |
79 for (var i = 0; i < objectStoreNames.length; ++i) | |
80 db.deleteObjectStore(objectStoreNames[i]); | |
81 } | |
82 | |
83 // The following functions are based on | |
kinuko
2011/08/29 08:55:01
I think in the new fileapi tests we're not using t
Dai Mikurube (NOT FULLTIME)
2011/08/30 08:07:55
Done.
| |
84 // WebKit/LayoutTests/fast/js/resources/js-test-pre.js | |
85 // so that the tests will look similar to the existing layout tests. | |
86 function stringify(v) | |
87 { | |
88 if (v === 0 && 1/v < 0) | |
89 return "-0"; | |
90 else return "" + v; | |
91 } | |
92 | |
93 function isResultCorrect(_actual, _expected) | |
94 { | |
95 if (_expected === 0) | |
96 return _actual === _expected && (1/_actual) === (1/_expected); | |
97 if (_actual === _expected) | |
98 return true; | |
99 if (typeof(_expected) == "number" && isNaN(_expected)) | |
100 return typeof(_actual) == "number" && isNaN(_actual); | |
101 if (Object.prototype.toString.call(_expected) == | |
102 Object.prototype.toString.call([])) | |
103 return areArraysEqual(_actual, _expected); | |
104 return false; | |
105 } | |
106 | |
107 function shouldBe(_a, _b) | |
108 { | |
109 if (typeof _a != "string" || typeof _b != "string") | |
110 debug("WARN: shouldBe() expects string arguments"); | |
111 var exception; | |
112 var _av; | |
113 try { | |
114 _av = eval(_a); | |
115 } catch (e) { | |
116 exception = e; | |
117 } | |
118 var _bv = eval(_b); | |
119 | |
120 if (exception) | |
121 fail(_a + " should be " + _bv + ". Threw exception " + exception); | |
122 else if (isResultCorrect(_av, _bv)) | |
123 debug(_a + " is " + _b); | |
124 else if (typeof(_av) == typeof(_bv)) | |
125 fail(_a + " should be " + _bv + ". Was " + stringify(_av) + "."); | |
126 else | |
127 fail(_a + " should be " + _bv + " (of type " + typeof _bv + "). " + | |
128 "Was " + _av + " (of type " + typeof _av + ")."); | |
129 } | |
130 | |
131 function shouldBeTrue(_a) { shouldBe(_a, "true"); } | |
132 function shouldBeFalse(_a) { shouldBe(_a, "false"); } | |
133 function shouldBeNaN(_a) { shouldBe(_a, "NaN"); } | |
134 function shouldBeNull(_a) { shouldBe(_a, "null"); } | |
135 function shouldBeEqualToString(a, b) | |
136 { | |
137 var unevaledString = '"' + b.replace(/\\/g, "\\\\").replace(/"/g, "\"") + '"'; | |
138 shouldBe(a, unevaledString); | |
139 } | |
OLD | NEW |