This repository was archived by the owner on Aug 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
163 lines (143 loc) · 3.75 KB
/
test.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
load("demlocator.js");
function TestNavigator(success) {
this.geolocation = {
getCurrentPosition : function(success_callback, error_callback) {
if (success) {
var result = {
"coords" : {
"latitude" : "35.40",
"longitude" : "-97.60"
}
};
success_callback(result);
} else {
error_callback("HTML5 geolocation error");
}
}
}
}
function THEGOOGLE(present) {
if (present) {
this.loader = {
"ClientLocation" : {
"address" : {
"country" : "USA",
"region" : "Colorado"
}
}
}
} else {
this.loader = {};
}
}
function GLatLng(lat,lng) {
this.lat = function() {
return lat;
};
this.lng = function() {
return lng;
};
}
var geocode_result = "good";
function GClientGeocoder() {
this.getLocations = function(latlng, success_callback, error_callback) {
var response = {
"Status" : {},
"Placemark" : []
};
if (geocode_result == "good") {
response.Status.code = 200;
response.Placemark[0] = {
"AddressDetails" : {
"Country" : {
"CountryNameCode" : "US",
"AdministrativeArea" : {
"AdministrativeAreaName" : "Oklahoma",
"SubAdministrativeArea" : {
"Locality" : {
"PostalCode" : {
"PostalCodeNumber" : "73120"
}
}
}
}
}
}
};
success_callback(response);
} else if (geocode_result == "fair") {
response.Status.code = 404;
success_callback(response);
} else if (geocode_result == "bad") {
error_callback("Geocoder error");
}
}
}
function TestConsole() {
this.log = function(msg) {
print(msg);
}
}
function handle_demlocator_success(result) {
if (result.country && result.country == 'US') {
console.log("You might be in " + result.state + ", USA!");
}
}
function handle_demlocator_error(error) {
console.log("DemLocator error: " + error);
}
var locator;
var navigator;
var google;
var console;
function test_reset() {
locator = new DemLocator();
locator.setDebug(true);
navigator = new TestNavigator(true);
google = new THEGOOGLE(true);
console = new TestConsole();
}
// all good test
test_reset();
print("This test should say we're in Oklahoma, USA:");
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");
// geocode fair test
test_reset();
print("This test should say we're in Colorado, USA:");
geocode_result = "fair";
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");
// geocode bad test
test_reset();
print("This test should say we're in Colorado, USA:");
geocode_result = "bad";
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");
// geocode bad & IP bad test
test_reset();
print("This test should generate an error:");
google = new THEGOOGLE(false);
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");
// html5 bad test
test_reset();
print("This test should say we're in Colorado, USA:");
navigator = new TestNavigator(false);
geocode_result = "good";
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");
// html5 not available test
test_reset();
print("This test should say we're in Colorado, USA:");
navigator.geolocation = null;
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");
// all bad test
test_reset();
print("This test should generate an error:");
var google = new THEGOOGLE(false);
navigator.geolocation = null;
geocode_result = "bad";
locator.getLocation(handle_demlocator_success, handle_demlocator_error);
print("\n");