1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Helper functions for use in tracing tests.
*/
/**
* goog.testing.assertion's assertEquals tweaked to do equality-to-a-constant.
* @param {*} a First value.
* @param {*} b Second value.
*/
function assertAlmostEquals(a, b) {
_validateArguments(2, arguments);
var var1 = nonCommentArg(1, 2, arguments);
var var2 = nonCommentArg(2, 2, arguments);
_assert(commentArg(2, arguments), Math.abs(var1 - var2) < 0.00001,
'Expected ' + _displayStringForValue(var1) + ' but was ' +
_displayStringForValue(var2));
}
cr.define('test_utils', function() {
function getAsync(url, cb) {
var req = new XMLHttpRequest();
req.open('GET', url, true);
req.onreadystatechange = function(aEvt) {
if (req.readyState == 4) {
window.setTimeout(function() {
if (req.status == 200) {
cb(req.responseText);
} else {
console.log('Failed to load ' + url);
}
}, 0);
}
};
req.send(null);
}
return {
getAsync: getAsync
};
});
|