flok 0.0.103 → 0.0.105

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/drivers/chrome/config.yml +2 -0
  3. data/app/drivers/chrome/src/about.js +14 -0
  4. data/app/drivers/chrome/src/guid.js +9 -0
  5. data/app/drivers/chrome/src/net.js +25 -3
  6. data/app/kern/mod/about.js +19 -0
  7. data/app/kern/mod/hook.js +2 -2
  8. data/app/kern/mod/udid.js +9 -0
  9. data/app/kern/services/rest.rb +67 -8
  10. data/bin/flok +14 -0
  11. data/docs/mod/about.md +19 -0
  12. data/docs/mod/net.md +9 -4
  13. data/docs/mod/ui.md +1 -1
  14. data/docs/services/rest.md +24 -2
  15. data/docs/services/vm.md +4 -0
  16. data/docs/user_handbook/hooks.md +61 -5
  17. data/lib/flok/hooks_compiler.rb +6 -0
  18. data/lib/flok/user_compiler.rb +33 -5
  19. data/lib/flok/user_hook_generators/goto.rb +25 -3
  20. data/lib/flok/user_hook_generators/pop.rb +99 -0
  21. data/lib/flok/user_hook_generators/push.rb +119 -0
  22. data/lib/flok/version.rb +1 -1
  23. data/spec/iface/driver/about_spec.rb +14 -0
  24. data/spec/iface/driver/net_spec.rb +91 -2
  25. data/spec/iface/driver/ping_spec.rb +1 -0
  26. data/spec/kern/about_spec.rb +30 -0
  27. data/spec/kern/assets/hook_entry_points/controller0a_push.rb +31 -0
  28. data/spec/kern/assets/hook_entry_points/controller0b.rb +17 -0
  29. data/spec/kern/assets/hook_entry_points/controller0bc.rb +27 -0
  30. data/spec/kern/assets/hook_entry_points/controller_0b_pop.rb +18 -0
  31. data/spec/kern/assets/hook_entry_points/controller_0b_pop2.rb +66 -0
  32. data/spec/kern/assets/hook_entry_points/controller_0b_push.rb +15 -0
  33. data/spec/kern/assets/hook_entry_points/controller_0b_push2.rb +55 -0
  34. data/spec/kern/assets/rest_service/controller1b.rb +47 -0
  35. data/spec/kern/hook_entry_points_and_manifest_spec.rb +174 -0
  36. data/spec/kern/{hook_user_generators_spec.rb → hook_goto_user_generators_spec.rb} +145 -7
  37. data/spec/kern/hook_pop_user_generators_spec.rb +292 -0
  38. data/spec/kern/hook_push_user_generators_spec.rb +305 -0
  39. data/spec/kern/rest_service_spec.rb +97 -1
  40. data/spec/lib/helpers.rb +5 -3
  41. metadata +35 -5
  42. data/lib/flok/user_hook_generators/helpers.rb +0 -46
@@ -13,6 +13,7 @@ RSpec.describe "iface:driver:ping_spec" do
13
13
  arg = SecureRandom.hex
14
14
  @pipe.puts [[0, 1, "ping1", arg]].to_json
15
15
  expect(@pipe).to readline_and_equal_json_x_within_y_seconds([1, "pong1", arg], 6.seconds)
16
+ @pipe.readline
16
17
  end
17
18
 
18
19
  it "supports ping2" do
@@ -0,0 +1,30 @@
1
+ Dir.chdir File.join File.dirname(__FILE__), '../../'
2
+ require './spec/env/kern.rb'
3
+ require './spec/lib/helpers.rb'
4
+ require './spec/lib/io_extensions.rb'
5
+ require './spec/lib/rspec_extensions.rb'
6
+
7
+ RSpec.describe "kern:rtc_spec" do
8
+ include_context "kern"
9
+
10
+ it "Does set the global information when receiving the int_about_poll_cb message" do
11
+ #Compile the controller
12
+ ctx = flok_new_user File.read('./spec/kern/assets/blank.rb')
13
+
14
+ @driver.int("int_about_poll_cb", [{
15
+ "platform" => "test",
16
+ "language" => "en-us",
17
+ "udid" => "foo-bar"
18
+ }])
19
+
20
+ dump = ctx.evald %{
21
+ dump.platform = get_platform();
22
+ dump.language = get_language();
23
+ dump.udid = get_udid();
24
+ }
25
+
26
+ expect(dump["platform"]).to eq("test")
27
+ expect(dump["language"]).to eq("en-us")
28
+ expect(dump["udid"]).to eq("foo-bar")
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ controller :my_controller do
2
+ spots "hello", "world"
3
+
4
+ macro :my_macro do
5
+ on "foo", %{
6
+ }
7
+
8
+ end
9
+
10
+ action :index do
11
+ on_entry %{
12
+ on_entry_base_pointer = __base__;
13
+ }
14
+
15
+ on "hello", %{
16
+ var x = 3;
17
+ }
18
+
19
+ my_macro
20
+ end
21
+
22
+ action :other do
23
+ on "test", %{
24
+ Push("index");
25
+ }
26
+
27
+ on "holah", %{
28
+ Pop();
29
+ }
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ controller :my_controller do
2
+ action :index do
3
+ on_entry %{
4
+ my_controller_base = __base__;
5
+ }
6
+
7
+ on "next_clicked", %{
8
+ Goto("other");
9
+ }
10
+ end
11
+
12
+ action :other do
13
+ on_entry %{
14
+ other_entered = true;
15
+ }
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ controller :my_controller do
2
+ action :index do
3
+ on_entry %{
4
+ my_controller_base = __base__;
5
+ }
6
+
7
+ on "next_clicked", %{
8
+ Goto("other");
9
+ }
10
+ end
11
+
12
+ action :other do
13
+ on_entry %{
14
+ other_entered = true;
15
+ }
16
+
17
+ on "next_clicked", %{
18
+ Goto("other2");
19
+ }
20
+
21
+ end
22
+
23
+ action :other2 do
24
+ on_entry %{
25
+ }
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ controller :my_controller do
2
+ action :index do
3
+ on_entry %{
4
+ on_entry_base_pointer = __base__;
5
+ }
6
+
7
+ on "next_clicked", %{
8
+ Push("other")
9
+ }
10
+
11
+ end
12
+
13
+ action :other do
14
+ on "back_clicked", %{
15
+ Pop();
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,66 @@
1
+ controller :my_controller do
2
+ spots "content"
3
+
4
+ action :index do
5
+ on_entry %{
6
+ on_entry_base_pointer = __base__;
7
+ Embed("my_controller2", "content", {});
8
+ }
9
+
10
+ on "next_clicked", %{
11
+ Push("other")
12
+ }
13
+
14
+ end
15
+
16
+ action :other do
17
+ on_entry %{
18
+ Embed("my_controller3", "content", {});
19
+ }
20
+
21
+ on "back_clicked", %{
22
+ Pop();
23
+ }
24
+ end
25
+ end
26
+
27
+ controller :my_controller2 do
28
+ action :index do
29
+ on_entry %{
30
+ on_entry_base_pointer2 = __base__;
31
+ }
32
+
33
+ on "next_clicked", %{
34
+ Push("other2")
35
+ }
36
+
37
+ on "olah", %{
38
+ }
39
+
40
+ end
41
+
42
+ action :other2 do
43
+ on "test", %{
44
+ }
45
+
46
+ on "next_clicked", %{
47
+ Push("index")
48
+ }
49
+
50
+ on "back_clicked", %{
51
+ Pop();
52
+ }
53
+
54
+ on "olah2", %{
55
+ }
56
+ end
57
+ end
58
+
59
+
60
+ controller :my_controller3 do
61
+ action :index do
62
+ on_entry %{
63
+ my_controller3_base = __base__;
64
+ }
65
+ end
66
+ end
@@ -0,0 +1,15 @@
1
+ controller :my_controller do
2
+ action :index do
3
+ on_entry %{
4
+ on_entry_base_pointer = __base__;
5
+ }
6
+
7
+ on "next_clicked", %{
8
+ Push("other")
9
+ }
10
+
11
+ end
12
+
13
+ action :other do
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ controller :my_controller do
2
+ spots "content"
3
+
4
+ action :index do
5
+ on_entry %{
6
+ on_entry_base_pointer = __base__;
7
+ Embed("my_controller2", "content", {});
8
+ }
9
+
10
+ on "next_clicked", %{
11
+ Push("other")
12
+ }
13
+
14
+ end
15
+
16
+ action :other do
17
+ on_entry %{
18
+ Embed("my_controller3", "content", {});
19
+ }
20
+ end
21
+ end
22
+
23
+ controller :my_controller2 do
24
+ action :index do
25
+ on_entry %{
26
+ on_entry_base_pointer2 = __base__;
27
+ }
28
+
29
+ on "next_clicked", %{
30
+ Push("other2")
31
+ }
32
+
33
+ on "olah", %{
34
+ }
35
+
36
+ end
37
+
38
+ action :other2 do
39
+ on "test", %{
40
+ }
41
+
42
+ on "next_clicked", %{
43
+ Push("index")
44
+ }
45
+ end
46
+ end
47
+
48
+
49
+ controller :my_controller3 do
50
+ action :index do
51
+ on_entry %{
52
+ my_controller3_base = __base__;
53
+ }
54
+ end
55
+ end
@@ -0,0 +1,47 @@
1
+ controller :my_controller do
2
+ services :rest
3
+
4
+ action :my_action do
5
+ on_entry %{
6
+ var info = {
7
+ path: "test",
8
+ params: {"hello": "world"}
9
+ }
10
+ Request("rest", "get", info);
11
+ }
12
+
13
+ on "rest_res", %{
14
+ rest_res_params = params;
15
+ }
16
+ end
17
+ end
18
+
19
+ controller :my_controller2 do
20
+ action :my_action do
21
+ end
22
+ end
23
+
24
+
25
+ controller :root_controller do
26
+ spots "content"
27
+
28
+ on_entry %{
29
+ root_base = __base__;
30
+ }
31
+
32
+ action :action_a do
33
+ on_entry %{
34
+ Embed("my_controller", "content", {});
35
+ }
36
+
37
+ on "next_clicked", %{
38
+ Goto("action_b")
39
+ }
40
+ end
41
+
42
+ action :action_b do
43
+ on_entry %{
44
+ Embed("my_controller2", "content", {});
45
+ }
46
+ end
47
+ end
@@ -112,6 +112,9 @@ eof
112
112
  #actions_responds_to looks like {"action1" => ["event_a", ..."], "action2" => }...
113
113
  #where each action list contains all the events this action responds to
114
114
  expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test"]})
115
+ if hook_info["from_action"] == "other"
116
+ expect(hook_info["handling_event_named"]).to eq("test")
117
+ end
115
118
 
116
119
  #Variables included
117
120
  next %{
@@ -172,6 +175,10 @@ eof
172
175
  #where each action list contains all the events this action responds to
173
176
  expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test"]})
174
177
 
178
+ if hook_info["from_action"] == "other"
179
+ expect(hook_info["handling_event_named"]).to eq("test")
180
+ end
181
+
175
182
  #Variables included
176
183
  next %{
177
184
  entry_params = {
@@ -212,4 +219,171 @@ eof
212
219
  expect(dump["entry_params"]["new_action"]).to eq("index")
213
220
  end
214
221
 
222
+ it "Can hook the controller_will_push event with the correct hook entry information mentioned in the docs" do
223
+ info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0a_push.rb')
224
+ src = info[:src]
225
+ ctx = info[:ctx]
226
+
227
+ manifest = Flok::HooksManifest.new
228
+ will_pushs_found = 0
229
+ from_to_action_pairs_found = []
230
+ entry = Flok::HooksManifestEntry.new("controller_will_push") do |hook_info|
231
+ will_pushs_found += 1
232
+ #Static parameters
233
+ expect(hook_info["controller_name"]).to eq("my_controller")
234
+ expect(hook_info["might_respond_to"].to_set).to eq(["foo", "hello", "test", "holah"].to_set)
235
+ from_to_action_pairs_found << {hook_info["from_action"] => hook_info["to_action"]}
236
+
237
+ #actions_responds_to looks like {"action1" => ["event_a", ..."], "action2" => }...
238
+ #where each action list contains all the events this action responds to
239
+ expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test", "holah"]})
240
+ expect(hook_info["handling_event_named"]).to eq("test")
241
+ end
242
+ manifest << entry
243
+
244
+ #Recompile source (We do this manually as we supplied no `config/hooks.rb` file)
245
+ src = Flok::HooksCompiler.compile src, manifest
246
+
247
+ #Expect to have found one will_push entries given that there is one push request
248
+ expect(will_pushs_found).to eq(1)
249
+
250
+ #Expect to have gotten all the push to/from action pairs
251
+ expect(from_to_action_pairs_found.to_set).to eq([{"other" => "index"}].to_set)
252
+
253
+ #Re-evaluate the v8 instance
254
+ ctx = v8_flok
255
+ ctx.eval src
256
+
257
+ #Now load the controller
258
+ dump = ctx.evald %{
259
+ base = _embed("my_controller", 0, {}, null);
260
+
261
+ //Drain queue
262
+ int_dispatch([]);
263
+ }
264
+ end
265
+
266
+ it "Can hook the controller_did_push event with the correct hook entry information mentioned in the docs" do
267
+ info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0a_push.rb')
268
+ src = info[:src]
269
+ ctx = info[:ctx]
270
+
271
+ manifest = Flok::HooksManifest.new
272
+ did_pushs_found = 0
273
+ from_to_action_pairs_found = []
274
+ entry = Flok::HooksManifestEntry.new("controller_did_push") do |hook_info|
275
+ did_pushs_found += 1
276
+ #Static parameters
277
+ expect(hook_info["controller_name"]).to eq("my_controller")
278
+ expect(hook_info["might_respond_to"].to_set).to eq(["foo", "hello", "test", "holah"].to_set)
279
+ from_to_action_pairs_found << {hook_info["from_action"] => hook_info["to_action"]}
280
+
281
+ #actions_responds_to looks like {"action1" => ["event_a", ..."], "action2" => }...
282
+ #where each action list contains all the events this action responds to
283
+ expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test", "holah"]})
284
+ expect(hook_info["handling_event_named"]).to eq("test")
285
+ end
286
+ manifest << entry
287
+
288
+ #Recompile source (We do this manually as we supplied no `config/hooks.rb` file)
289
+ src = Flok::HooksCompiler.compile src, manifest
290
+
291
+ #Expect to have found one did_push entries given that there is one push request
292
+ expect(did_pushs_found).to eq(1)
293
+
294
+ #Expect to have gotten all the push to/from action pairs
295
+ expect(from_to_action_pairs_found.to_set).to eq([{"other" => "index"}].to_set)
296
+
297
+ #Re-evaluate the v8 instance
298
+ ctx = v8_flok
299
+ ctx.eval src
300
+
301
+ #Now load the controller
302
+ dump = ctx.evald %{
303
+ base = _embed("my_controller", 0, {}, null);
304
+
305
+ //Drain queue
306
+ int_dispatch([]);
307
+ }
308
+ end
309
+
310
+ it "Can hook the controller_will_pop event with the correct hook entry information mentioned in the docs" do
311
+ info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0a_push.rb')
312
+ src = info[:src]
313
+ ctx = info[:ctx]
314
+
315
+ manifest = Flok::HooksManifest.new
316
+ will_pops_found = 0
317
+ entry = Flok::HooksManifestEntry.new("controller_will_pop") do |hook_info|
318
+ will_pops_found += 1
319
+ #Static parameters
320
+ expect(hook_info["controller_name"]).to eq("my_controller")
321
+ expect(hook_info["might_respond_to"].to_set).to eq(["foo", "hello", "test", "holah"].to_set)
322
+
323
+ #actions_responds_to looks like {"action1" => ["event_a", ..."], "action2" => }...
324
+ #where each action list contains all the events this action responds to
325
+ expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test", "holah"]})
326
+ expect(hook_info["handling_event_named"]).to eq("holah")
327
+ end
328
+ manifest << entry
329
+
330
+ #Recompile source (We do this manually as we supplied no `config/hooks.rb` file)
331
+ src = Flok::HooksCompiler.compile src, manifest
332
+
333
+ #Expect to have found one will_pop entries given that there is one pop request
334
+ expect(will_pops_found).to eq(1)
335
+
336
+ #Re-evaluate the v8 instance
337
+ ctx = v8_flok
338
+ ctx.eval src
339
+
340
+ #Now load the controller
341
+ dump = ctx.evald %{
342
+ base = _embed("my_controller", 0, {}, null);
343
+
344
+ //Drain queue
345
+ int_dispatch([]);
346
+ }
347
+ end
348
+
349
+ it "Can hook the controller_did_pop event with the correct hook entry information mentioned in the docs" do
350
+ info = flok_new_user_with_src File.read('./spec/kern/assets/hook_entry_points/controller0a_push.rb')
351
+ src = info[:src]
352
+ ctx = info[:ctx]
353
+
354
+ manifest = Flok::HooksManifest.new
355
+ did_pops_found = 0
356
+ entry = Flok::HooksManifestEntry.new("controller_did_pop") do |hook_info|
357
+ did_pops_found += 1
358
+ #Static parameters
359
+ expect(hook_info["controller_name"]).to eq("my_controller")
360
+ expect(hook_info["might_respond_to"].to_set).to eq(["foo", "hello", "test", "holah"].to_set)
361
+
362
+ #actions_responds_to looks like {"action1" => ["event_a", ..."], "action2" => }...
363
+ #where each action list contains all the events this action responds to
364
+ expect(hook_info["actions_responds_to"]).to eq({"index" => ["hello", "foo"], "other" => ["test", "holah"]})
365
+ expect(hook_info["handling_event_named"]).to eq("holah")
366
+ end
367
+ manifest << entry
368
+
369
+ #Recompile source (We do this manually as we supplied no `config/hooks.rb` file)
370
+ src = Flok::HooksCompiler.compile src, manifest
371
+
372
+ #Expect to have found one did_pop entries given that there is one pop request
373
+ expect(did_pops_found).to eq(1)
374
+
375
+ #Re-evaluate the v8 instance
376
+ ctx = v8_flok
377
+ ctx.eval src
378
+
379
+ #Now load the controller
380
+ dump = ctx.evald %{
381
+ base = _embed("my_controller", 0, {}, null);
382
+
383
+ //Drain queue
384
+ int_dispatch([]);
385
+ }
386
+ end
387
+
388
+
215
389
  end