-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
570 lines (510 loc) · 19.5 KB
/
test.html
File metadata and controls
570 lines (510 loc) · 19.5 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
<!DOCTYPE html>
<!-- saved from url=(0013)about:internet -->
<!-- The above comment makes IE treat this as a web page -->
<html>
<head>
<title>atl 8.0 test page for object fbcontrol</title>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/base/jquery-ui.css" rel="Stylesheet" />
<style>
body
{
padding: 0;
margin: 0;
}
.header
{
text-align: center;
border: 1px solid black;
width: 900px;
}
#pluginContainer
{
width: 300px;
height: 300px;
border: 5px dotted gray;
text-align: center;
margin: 0 auto;
float: left;
}
#pluginContainer2
{
width: 300px;
height: 300px;
border: 5px dotted gray;
text-align: center;
margin: 0 auto;
float: left;
}
#pluginContainer3
{
width: 300px;
height: 300px;
border: 5px dotted gray;
text-align: center;
margin: 0 auto;
float: left;
}
#testResults
{
border: 1px dashed gray;
width: 600px;
height: 300px;
float: left;
overflow:auto;
}
#testResults ul
{
border-bottom: 1px solid black;
margin: 0;
padding: 0;
list-style: none;
}
#testResults ul li
{
padding-left: 1em;
color: Gray;
}
#testResults ul li.passed
{
color: Green;
}
#testResults ul li.failed
{
color: Red;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
<script type="text/javascript" language="Javascript">
var mimeType = "application/x-zig";
var pluginCB = null;
function plugin() {
return document.getElementById("testPlugin");
}
function injectPlugin(dest, callback) {
pluginCB = callback;
var html = '<object id="testPlugin" type="' + mimeType + '" width="100%" height="100%" onload="alert(\'The plugin has loaded 1!\');">';
html += '<param name="onload" value="pluginCB" />';
html += '</object>';
dest[0].innerHTML = html;
}
function dangerousInjection(dest, callback) {
pluginCB = callback;
var paramNode = document.createElement("param");
paramNode.setAttribute("name", "onload");
paramNode.setAttribute("value", "pluginCB");
var pluginObjectNode = document.createElement("object");
pluginObjectNode.appendChild(paramNode);
pluginObjectNode.setAttribute("type", mimeType);
dest.appendChild(pluginObjectNode);
}
function addTest(id, text) {
$("#testResults ul")
.append("<li id='" + id + "'>" + text + "...</li>")
$("#" + id).attr("text", text);
}
function markPassed(id) {
var el = $("#" + id);
el.html(el.attr("text") + " passed!").addClass("passed").removeClass("failed");
}
function markFailed(id) {
var el = $("#" + id);
el.html(el.attr("text") + " failed!").addClass("failed").removeClass("passed");
}
function onWaveGesture(x,y,z)
{
//alert("Wave Gesture!");
document.getElementById("log").innerHTML += "WaveGesture" + x.toString() + ' ' + y.toString() + ' '+ z.toString();
}
function onHandCreate(uid, x,y,z, t)
{
document.getElementById("log").innerHTML += "HandCreate"+uid+' '+x.toString()+' '+y.toString()+' '+z.toString()+' '+t.toString();
document.getElementById("handpos").innerHTML = x.toString()+' '+y.toString()+' '+z.toString();
}
function onHandUpdate(uid,x,y,z,y){
document.getElementById("handpos").innerHTML = x.toString()+' '+y.toString()+' '+z.toString();
}
function onHandDestroy(uid, t)
{
document.getElementById("log").innerHTML += "HandDestroy"+uid+' '+t.toString();
document.getElementById("handpos").innerHTML = '';
}
function pageLoaded() {
document.getElementById("log").innerHTML = "adding events"
injectPlugin($("#pluginContainer"), pluginLoaded);
}
function pluginLoaded() {
markPassed("loaded");
$("#pluginContainer").css("border", "1px solid black");
//setTimeout(pluginRunTests, 500);
plugin().addEventListener("WaveGesture", onWaveGesture, false);
plugin().addEventListener("HandCreate", onHandCreate, false);
plugin().addEventListener("HandUpdate", onHandUpdate, false);
plugin().addEventListener("HandDestroy", onHandDestroy, false);
document.getElementById("log").innerHTML += "events added"
}
function pluginLoaded2() {
markPassed("loaded2");
$("#pluginContainer2").css("border", "1px solid black");
//setTimeout(pluginRunTests, 500);
}
function pluginLoaded3() {
markPassed("loaded3");
$("#pluginContainer3").css("border", "1px solid black");
setTimeout(pluginRunTests, 500);
}
function pluginRunTests() {
var plugin = window.plugin();
if (plugin.valid)
markPassed("valid");
else
markFailed("valid");
var mathplugin2 = window.plugin2();
if (mathplugin2.valid)
markPassed("valid2");
else
markFailed("valid2");
// note: no valid property!
var mathplugin3 = window.plugin3();
try {
var path = plugin.pluginPath;
if (path.length < 1)
throw (new Error("path.length < 1"));
$("#pluginPath").text(path);
markPassed("getPluginPath");
} catch (e) {
markFailed("getPluginPath");
}
try {
if (plugin.echo("Hello!") == "Hello!"
&& plugin.echo(1234) == 1234
&& plugin.echo(12.445) == 12.445
&& plugin.echo(true) == true) {
markPassed("echo");
} else {
markFailed("echo");
}
}catch (e){alert(e)};
var tmp = Array();
for (var i = 0; i < 15; i++) {
tmp.push(i);
}
var tmp2 = plugin.reverseArray(tmp);
var success = true;
for (var i = 0; i < 15; i++) {
if (tmp2[i] != 14 - i) {
success = false;
break;
}
}
if (success)
markPassed("reverse");
else
markFailed("reverse");
var check = plugin.getUserData();
if (check.Name != "Richard Bateman"
|| typeof(check.Kids) != "object"
|| check.Kids[0] != "Caleb"
|| typeof (check.inner) != "object"
|| check.inner.test3 != 12.4
|| check.inner.test != 12
|| check.Kids[3].test4 != "asdf")
markFailed("getMap");
else
markPassed("getMap");
if (plugin.getPageLocation() != window.location.href)
markFailed("location");
else
markPassed("location");
// Use math object in plugin, call math methods.
var math = plugin.simpleMath;
if (math.add(34, 43) != 77
|| math.sub(10, 5) != 5) {
markFailed("mathAPI");
} else {
markPassed("mathAPI");
}
// Main object creates new math object, call math methods.
var math2 = plugin.createSimpleMath();
if (math2.add(34, 43) != 77
|| math2.sub(10, 5) != 5) {
markFailed("mathAPI2");
} else {
markPassed("mathAPI2");
}
// HTML OBJECT tag creates math object, call math methods.
if (mathplugin2.add(34, 43) != 77
|| mathplugin2.sub(10, 5) != 5) {
markFailed("mathAPI3");
} else {
markPassed("mathAPI3");
}
// HTML OBJECT tag creates math object, call math methods on self.
var mathplugin2_self = mathplugin2.self;
if (mathplugin2_self.add(34, 43) != 77
|| mathplugin2_self.sub(10, 5) != 5) {
markFailed("mathAPI4");
} else {
markPassed("mathAPI4");
}
// HTML OBJECT tag creates math object, call math methods.
if (mathplugin3.add(34, 43) != 77
|| mathplugin3.sub(10, 5) != 5) {
markFailed("mathAPI3B");
} else {
markPassed("mathAPI3B");
}
// HTML OBJECT tag creates math object, call math methods on self.
var mathplugin3_self = mathplugin3.self;
if (mathplugin3_self.add(34, 43) != 77
|| mathplugin3_self.sub(10, 5) != 5) {
markFailed("mathAPI4B");
} else {
markPassed("mathAPI4B");
}
// Use math object in plugin as method argument
try {
if (plugin.addWithSimpleMath(plugin.simpleMath, 23, 532) != 555)
markFailed("mathApiAdd");
else
markPassed("mathApiAdd");
} catch (e) {
markFailed("mathApiAdd");
}
// Use new math object created by main plugin as method argument
try {
// Main object creates helper, can call main object with helper as an argument
var mathapiadd2 = plugin.createSimpleMath();
if (plugin.addWithSimpleMath(mathapiadd2, 23, 532) != 555)
markFailed("mathApiAdd2");
else
markPassed("mathApiAdd2");
} catch (e) {
markFailed("mathApiAdd2");
}
// Use math object (SELF) created by HTML OBJECT tag as method argument
try {
// HTML OBJECT tag creates helper, can call main object with helper as an argument
var mathplugin2_self = mathplugin2.self;
// Same as mathplugin2.self:
// var mathplugin2_self = mathplugin2.GetSelf();
if (plugin.addWithSimpleMath(mathplugin2_self, 23, 532) != 555)
markFailed("mathApiAdd3");
else
markPassed("mathApiAdd3");
} catch (e) {
markFailed("mathApiAdd3");
}
// Use math object created by HTML OBJECT tag as method argument (SHOULD FAIL!!!)
try {
// HTML OBJECT tag creates helper, can call main object with helper as an argument
var mathplugin2_var = mathplugin2;
if (plugin.addWithSimpleMath(mathplugin2_var, 23, 532) != 555)
markFailed("mathApiAdd4");
else
markPassed("mathApiAdd4");
} catch (e) {
markFailed("mathApiAdd4");
}
// Use math object (SELF) created by HTML OBJECT tag as method argument
try {
// HTML OBJECT tag creates helper, can call main object with helper as an argument
var mathplugin3_self = mathplugin3.self;
// Same as mathplugin3.self:
// var mathplugin3_self = mathplugin3.GetSelf();
if (plugin.addWithSimpleMath(mathplugin3_self, 23, 532) != 555)
markFailed("mathApiAdd3B");
else
markPassed("mathApiAdd3B");
} catch (e) {
markFailed("mathApiAdd3B");
}
// Use math object created by HTML OBJECT tag as method argument (SHOULD FAIL!!!)
try {
// HTML OBJECT tag creates helper, can call main object with helper as an argument
var mathplugin3_var = mathplugin3;
if (plugin.addWithSimpleMath(mathplugin3_var, 23, 532) != 555)
markFailed("mathApiAdd4B");
else
markPassed("mathApiAdd4B");
} catch (e) {
markFailed("mathApiAdd4B");
}
var sm = plugin.simpleMath;
var c = plugin.countArrayLength(sm);
if (c!=4) {
markFailed("countArray");
alert(c);
}
else
markPassed("countArray");
plugin.onfired = function (str) {
if (str == "some string") {
markPassed("simpleFireEvent");
} else {
markFailed("simpleFireEvent");
}
};
var tmpFired = function (str) {
if (str == "some string") {
markPassed("attachedFireEvent");
} else {
markFailed("attachedFireEvent");
}
}
if (plugin.attachEvent) {
plugin.attachEvent("onfired", tmpFired);
} else {
plugin.addEventListener("fired", tmpFired, false);
}
plugin.testEvent("some string");
// now remove the async callback delegate,
// and trigger a callback
for (var i in window) {
if (0 == i.indexOf("__FB_CALL_")) {
try {
delete window[i];
// if this fails, it will cause other things to appear to have failed as well
plugin.testEvent("some string");
} catch (e) {
// ie8, at least, is unhappy doing the delete,
// but then, activex doesn't have this problem
}
break;
}
}
try {
thread = plugin.createThreadRunner();
thread.addMethod(function(){
return PasswordDlg("Message text", function()
{
// alert("Dialog closed");
markPassed("dialog");
});});
}
catch (e) {
alert (e);
}
var sUrl = "http://code.google.com/p/firebreath/issues/list";
var getUrlCallback = function(success, outheaders, data)
{
if (success) {
markPassed("getURL");
} else {
markFailed("getURL");
}
//alert("getUrlCallback: " + success + "\r\nHeaders: " + outheaders + "\r\nDataLen: " + data.lenght);
}
plugin.getURL(sUrl, getUrlCallback);
var sUrl = "http://code.google.com/p/firebreath/issues/list";
var sPostData = "can=1&q=&colspec=ID+Type+Status+Priority+Milestone+Owner+Summary+Stars&cells=tiles";
var postUrlCallback = function(success, outheaders, data)
{
if (success) {
markPassed("postURL");
} else {
markFailed("postURL");
}
//alert("postUrlCallback: " + success + "\r\nHeaders: " + outheaders + "\r\nDataLen: " + data.lenght);
}
plugin.postURL(sUrl, sPostData, postUrlCallback);
//testDiv = document.getElementById("test");
//var testcb = function(nplug) {
//if (nplug.valid) {
//markPassed("dangerousInject");
//} else {
//markFailed("dangerousInject");
//}
//testDiv.innerHTML = "";
//}
//dangerousInjection(testDiv, testcb);
if (plugin.add.apply(window, [1, 2]) == 3) {
markPassed("applytest");
} else {
markFailed("applytest");
}
if (plugin.add.call(window, 1, 2) == 3) {
markPassed("calltest");
} else {
markFailed("calltest");
}
}
function PasswordDlg(message, onComplete)
{
//console.log("PasswordDlg: " +message);
var $template= $('<div id="PasswordDlg">\
<span class="ui-icon ui-icon-key" style="float:left; margin:0 7px 20px 0;"></span>\
<label>'+ message +'</label><input type="password"/></div>');
var dialog_finished = false;
var res= '';
$template.dialog({
title: "Enter some text",
modal: true,
//autoOpen: true,
open: function(event, ui) {
//console.log("PasswordDlg show dialog" + dialog_finished);
$(this).find("input:password").keypress(function (e) {
if (e.keyCode =='13') {
//console.log("Enter pressed ");$template.dialog("close");
}
else {
//console.log("keyCode: " + e.keyCode);
}
});
},
close: function(e, ui) {
dialog_finished = true;
//console.log("PasswordDlg show close" + dialog_finished);
//console.log($(this).find("input:password").val());
res = $(this).find("input:password").val();
$(this).dialog('destroy').remove();
},
buttons: {
'ok' : function() {
$(this).dialog("close");
},
'cancel': function() {
res = '';
$(this).dialog("close");
}
}
});
var fn = function () {
//console.log("PasswordDlg internal fn: " +message);
//console.log("PasswordDlg internal fn: " + dialog_finished);
if (dialog_finished) {
dialog_finished = false;
onComplete();
return res;
}
return fn;
}
return fn;
}
$(document).ready(pageLoaded);
</script>
</head>
<body>
<div class="header">
<h1>FBTestPlugin - Test page</h1>
<small>Plugin path: <span id="pluginPath">?</span></small>
</div>
<div id="pluginContainer">
<br /><br /><br />Plugin will go here!
</div>
<div id="pluginContainer2">
<br /><br /><br />Plugin2 will go here!
</div>
<div id="pluginContainer3">
<br /><br /><br />Plugin3 will go here!
</div>
<div id="testResults">
<ul>
</ul>
</div>
<div id="test"></div>
<br><br><div id="handpos">Hand Position</div>
<br><br>
<div id="log">Log</div>
</body>
</html>