~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/jsunit-2.2/tests/jsUnitVersionCheckTests.html

  • Committer: V. Keith Hughitt
  • Date: 2009-04-01 21:08:05 UTC
  • Revision ID: hughitt1@kore-20090401210805-372f7dgih07vxk42
nightly build 04-01-2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
 
 
3
<html>
 
4
<head>
 
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">
 
11
 
 
12
var versionLatestCalled;
 
13
var versionNotLatestCalled;
 
14
var versionCheckErrorCalled;
 
15
var latestVersion;
 
16
 
 
17
MockXmlHttpRequest = function() {
 
18
}
 
19
 
 
20
MockXmlHttpRequest.prototype.open = function (method, url, isAsync, userName, password) {
 
21
    this.method = method;
 
22
    this.url = url;
 
23
    this.isAsync = isAsync;
 
24
    this.userName = userName;
 
25
    this.password = password;
 
26
}
 
27
 
 
28
MockXmlHttpRequest.prototype.send = function (data) {
 
29
    this.sendCalled = true;
 
30
    this.data = data;
 
31
}
 
32
 
 
33
function setUp() {
 
34
    versionRequest = new MockXmlHttpRequest();
 
35
    versionLatestCalled = false;
 
36
    versionNotLatestCalled = false;
 
37
    versionCheckErrorCalled = false;
 
38
    latestVersion = null;
 
39
}
 
40
 
 
41
function createXmlHttpRequest() {
 
42
    return versionRequest;
 
43
}
 
44
 
 
45
function versionNotLatest(aVersion) {
 
46
    versionNotLatestCalled = true;
 
47
    latestVersion = aVersion;
 
48
}
 
49
 
 
50
function versionLatest() {
 
51
    versionLatestCalled = true;
 
52
}
 
53
 
 
54
function versionCheckError() {
 
55
    versionCheckErrorCalled = true;
 
56
}
 
57
 
 
58
function testIsOutOfDate() {
 
59
    assertTrue(isOutOfDate("" + (JSUNIT_VERSION + 1)));
 
60
    assertFalse(isOutOfDate("" + JSUNIT_VERSION));
 
61
    assertFalse(isOutOfDate("" + (JSUNIT_VERSION - 1)));
 
62
}
 
63
 
 
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);
 
71
 
 
72
    assertTrue(versionRequest.sendCalled);
 
73
    assertNull(versionRequest.data);
 
74
 
 
75
    assertEquals(requestStateChanged, versionRequest.onreadystatechange);
 
76
}
 
77
 
 
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);
 
85
 
 
86
    versionRequest.status = 200;
 
87
    requestStateChanged();
 
88
    assertFalse("readyState bad", versionNotLatestCalled);
 
89
    assertFalse("readyState bad", versionLatestCalled);
 
90
    assertFalse(versionCheckErrorCalled);
 
91
 
 
92
    versionRequest.readyState = 4;
 
93
    versionRequest.status = 404;
 
94
    requestStateChanged();
 
95
    assertFalse("status bad", versionNotLatestCalled);
 
96
    assertFalse("status bad", versionLatestCalled);
 
97
    assertTrue(versionCheckErrorCalled);
 
98
}
 
99
 
 
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);
 
108
}
 
109
 
 
110
function testReceiveSameLatestVersion() {
 
111
    versionRequest.readyState = 4;
 
112
    versionRequest.status = 200;
 
113
    versionRequest.responseText = "" + JSUNIT_VERSION;
 
114
    requestStateChanged();
 
115
    assertFalse(versionNotLatestCalled);
 
116
    assertTrue(versionLatestCalled);
 
117
}
 
118
 
 
119
function enablePrivileges() {
 
120
}
 
121
 
 
122
</script>
 
123
</head>
 
124
 
 
125
<body>
 
126
<h1>JsUnit Version Check Tests</h1>
 
127
 
 
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>
 
130
</body>
 
131
</html>