|
1 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; js-indent-level: 2; -*- */ |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 function run_test() |
|
6 { |
|
7 Cu.import("resource://gre/modules/jsdebugger.jsm"); |
|
8 addDebuggerToGlobal(this); |
|
9 let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] |
|
10 .getService(Components.interfaces.mozIJSSubScriptLoader); |
|
11 loader.loadSubScript("resource://gre/modules/devtools/server/actors/script.js"); |
|
12 |
|
13 test_LSA_disconnect(); |
|
14 test_LSA_grip(); |
|
15 test_LSA_onSubstring(); |
|
16 } |
|
17 |
|
18 const TEST_STRING = "This is a very long string!"; |
|
19 |
|
20 function makeMockLongStringActor() |
|
21 { |
|
22 let string = TEST_STRING; |
|
23 let actor = new LongStringActor(string); |
|
24 actor.actorID = "longString1"; |
|
25 actor.registeredPool = { |
|
26 longStringActors: { |
|
27 longString1: actor |
|
28 } |
|
29 }; |
|
30 return actor; |
|
31 } |
|
32 |
|
33 function test_LSA_disconnect() |
|
34 { |
|
35 let actor = makeMockLongStringActor(); |
|
36 do_check_eq(actor.registeredPool.longStringActors[actor.actorID], actor); |
|
37 |
|
38 actor.disconnect(); |
|
39 do_check_eq(actor.registeredPool.longStringActors[actor.actorID], void 0); |
|
40 } |
|
41 |
|
42 function test_LSA_substring() |
|
43 { |
|
44 let actor = makeMockLongStringActor(); |
|
45 do_check_eq(actor._substring(0, 4), TEST_STRING.substring(0, 4)); |
|
46 do_check_eq(actor._substring(6, 9), TEST_STRING.substring(6, 9)); |
|
47 do_check_eq(actor._substring(0, TEST_STRING.length), TEST_STRING); |
|
48 } |
|
49 |
|
50 function test_LSA_grip() |
|
51 { |
|
52 let actor = makeMockLongStringActor(); |
|
53 |
|
54 let grip = actor.grip(); |
|
55 do_check_eq(grip.type, "longString"); |
|
56 do_check_eq(grip.initial, TEST_STRING.substring(0, DebuggerServer.LONG_STRING_INITIAL_LENGTH)); |
|
57 do_check_eq(grip.length, TEST_STRING.length); |
|
58 do_check_eq(grip.actor, actor.actorID); |
|
59 } |
|
60 |
|
61 function test_LSA_onSubstring() |
|
62 { |
|
63 let actor = makeMockLongStringActor(); |
|
64 let response; |
|
65 |
|
66 // From the start |
|
67 response = actor.onSubstring({ |
|
68 start: 0, |
|
69 end: 4 |
|
70 }); |
|
71 do_check_eq(response.from, actor.actorID); |
|
72 do_check_eq(response.substring, TEST_STRING.substring(0, 4)); |
|
73 |
|
74 // In the middle |
|
75 response = actor.onSubstring({ |
|
76 start: 5, |
|
77 end: 8 |
|
78 }); |
|
79 do_check_eq(response.from, actor.actorID); |
|
80 do_check_eq(response.substring, TEST_STRING.substring(5, 8)); |
|
81 |
|
82 // Whole string |
|
83 response = actor.onSubstring({ |
|
84 start: 0, |
|
85 end: TEST_STRING.length |
|
86 }); |
|
87 do_check_eq(response.from, actor.actorID); |
|
88 do_check_eq(response.substring, TEST_STRING); |
|
89 |
|
90 // Negative index |
|
91 response = actor.onSubstring({ |
|
92 start: -5, |
|
93 end: TEST_STRING.length |
|
94 }); |
|
95 do_check_eq(response.from, actor.actorID); |
|
96 do_check_eq(response.substring, |
|
97 TEST_STRING.substring(-5, TEST_STRING.length)); |
|
98 |
|
99 // Past the end |
|
100 response = actor.onSubstring({ |
|
101 start: TEST_STRING.length - 5, |
|
102 end: 100 |
|
103 }); |
|
104 do_check_eq(response.from, actor.actorID); |
|
105 do_check_eq(response.substring, |
|
106 TEST_STRING.substring(TEST_STRING.length - 5, 100)); |
|
107 } |