1 module tests.app;
2 
3 import std;
4 import guino;
5 
6 __gshared WebView wv = WebView.init;
7 bool works = true;
8 
9 void main()
10 {
11 	wv = WebView(true);
12 
13 	// Self-contained
14 	auto html = import("ui.html").replace("test.js", WebView.importAsDataUri!"test.js");
15 
16 	wv.html = html;
17 	wv.title = "Testing";
18 	wv.bindJs!d_function;
19 	wv.bindJs!d_promise_renamed("d_promise");
20 
21 	wv.run();
22 
23 }
24 
25 void d_function(JSONValue[] v) {
26 
27 	assert(v[0].str == "one");
28 	assert(v[1].integer == 2);
29 
30 	auto args = WebView.parseJsArgs!(string, "first", int, "second", string, "third")(v);
31 
32 	assert(args.first == "one");
33 	assert(args.second == 2);
34 	assert(args.third == "three");
35 
36 	wv.eval!eval_callback("document.getElementById('element').innerText");
37 	wv.eval("js_function('test from d')");
38 }
39 
40 
41 void eval_callback(JSONValue v)
42 {
43 	assert(v.str == "something");
44 	wv.byId("dynamic").innerText = "testing opDispatch";
45 
46 	import core.thread;
47 	new Thread({
48 		Thread.sleep(200.msecs);
49 
50 		wv.eval!check_all("document.documentElement.innerHTML");
51 	}).start();
52 }
53 
54 void d_promise_renamed(JSONValue[] v, string sequence)
55 {
56 	with(WebView.parseJsArgs!(int, "first", int, "second")(v))
57 	{
58 		assert(v[0].integer == 1);
59 		assert(v[1].integer == 2);
60 
61 		//with(args)
62 		{
63 			assert(first == 1);
64 			assert(second == 2);
65 
66 			wv.resolve(sequence, JSONValue(first+second));
67 		}
68 	}
69 }
70 
71 void check_all(JSONValue v)
72 {
73 	string data = v.str;
74 	assert(data.canFind(`<div id="dynamic">testing opDispatch</div>`));
75 	assert(data.canFind(`<div id="element">something</div>`));
76 	assert(data.canFind(`<div id="result">3</div>`));
77 	assert(data.canFind(`<div id="from_js">test from d</div>`));
78 
79 	wv.terminate();
80 }