1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6
<title>JsUnit Version Check Tests</title>
7
<link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
8
<script language="JavaScript" type="text/javascript" src="../app/jsUnitCore.js"></script>
9
<script language="JavaScript" type="text/javascript" src="../app/jsUnitVersionCheck.js"></script>
10
<script language="JavaScript" type="text/javascript">
12
var versionLatestCalled;
13
var versionNotLatestCalled;
14
var versionCheckErrorCalled;
17
MockXmlHttpRequest = function() {
20
MockXmlHttpRequest.prototype.open = function (method, url, isAsync, userName, password) {
23
this.isAsync = isAsync;
24
this.userName = userName;
25
this.password = password;
28
MockXmlHttpRequest.prototype.send = function (data) {
29
this.sendCalled = true;
34
versionRequest = new MockXmlHttpRequest();
35
versionLatestCalled = false;
36
versionNotLatestCalled = false;
37
versionCheckErrorCalled = false;
41
function createXmlHttpRequest() {
42
return versionRequest;
45
function versionNotLatest(aVersion) {
46
versionNotLatestCalled = true;
47
latestVersion = aVersion;
50
function versionLatest() {
51
versionLatestCalled = true;
54
function versionCheckError() {
55
versionCheckErrorCalled = true;
58
function testIsOutOfDate() {
59
assertTrue(isOutOfDate("" + (JSUNIT_VERSION + 1)));
60
assertFalse(isOutOfDate("" + JSUNIT_VERSION));
61
assertFalse(isOutOfDate("" + (JSUNIT_VERSION - 1)));
64
function testSendRequestForLatestVersion() {
65
sendRequestForLatestVersion("http://www.example.com/foo/bar/version.txt");
66
assertEquals("GET", versionRequest.method);
67
assertEquals("http://www.example.com/foo/bar/version.txt", versionRequest.url);
68
assertTrue(versionRequest.isAsync);
69
assertUndefined(versionRequest.userName);
70
assertUndefined(versionRequest.password);
72
assertTrue(versionRequest.sendCalled);
73
assertNull(versionRequest.data);
75
assertEquals(requestStateChanged, versionRequest.onreadystatechange);
78
function testBadResponse() {
79
versionRequest.readyState = 999;
80
versionRequest.status = 404;
81
requestStateChanged();
82
assertFalse("both bad", versionNotLatestCalled);
83
assertFalse("both bad", versionLatestCalled);
84
assertFalse(versionCheckErrorCalled);
86
versionRequest.status = 200;
87
requestStateChanged();
88
assertFalse("readyState bad", versionNotLatestCalled);
89
assertFalse("readyState bad", versionLatestCalled);
90
assertFalse(versionCheckErrorCalled);
92
versionRequest.readyState = 4;
93
versionRequest.status = 404;
94
requestStateChanged();
95
assertFalse("status bad", versionNotLatestCalled);
96
assertFalse("status bad", versionLatestCalled);
97
assertTrue(versionCheckErrorCalled);
100
function testReceiveNewerLatestVersion() {
101
versionRequest.readyState = 4;
102
versionRequest.status = 200;
103
versionRequest.responseText = "" + (JSUNIT_VERSION + 1);
104
requestStateChanged();
105
assertTrue(versionNotLatestCalled);
106
assertFalse(versionLatestCalled);
107
assertEquals("" + (JSUNIT_VERSION + 1), latestVersion);
110
function testReceiveSameLatestVersion() {
111
versionRequest.readyState = 4;
112
versionRequest.status = 200;
113
versionRequest.responseText = "" + JSUNIT_VERSION;
114
requestStateChanged();
115
assertFalse(versionNotLatestCalled);
116
assertTrue(versionLatestCalled);
119
function enablePrivileges() {
126
<h1>JsUnit Version Check Tests</h1>
128
<p>This page contains tests for the version checking code in JsUnit that looks to see whether a newer version of JsUnit
129
is available. To see them, take a look at the source.</p>