|
1 /* -*- Mode: javascript; js-indent-level: 2; -*- */ |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 var gDebuggee; |
|
6 var gClient; |
|
7 var gThreadClient; |
|
8 |
|
9 // This test ensures that we can create SourceActors and SourceClients properly, |
|
10 // and that they can communicate over the protocol to fetch the source text for |
|
11 // a given script. |
|
12 |
|
13 function run_test() |
|
14 { |
|
15 initTestDebuggerServer(); |
|
16 gDebuggee = addTestGlobal("test-grips"); |
|
17 Cu.evalInSandbox( |
|
18 "" + function stopMe(arg1) { |
|
19 debugger; |
|
20 }, |
|
21 gDebuggee, |
|
22 "1.8", |
|
23 getFileUrl("test_source-01.js") |
|
24 ); |
|
25 |
|
26 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
27 gClient.connect(function() { |
|
28 attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { |
|
29 gThreadClient = aThreadClient; |
|
30 test_source(); |
|
31 }); |
|
32 }); |
|
33 do_test_pending(); |
|
34 } |
|
35 |
|
36 const SOURCE_URL = "http://example.com/foobar.js"; |
|
37 const SOURCE_CONTENT = "stopMe()"; |
|
38 |
|
39 function test_source() |
|
40 { |
|
41 DebuggerServer.LONG_STRING_LENGTH = 200; |
|
42 |
|
43 gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { |
|
44 gThreadClient.getSources(function (aResponse) { |
|
45 do_check_true(!!aResponse); |
|
46 do_check_true(!!aResponse.sources); |
|
47 |
|
48 let source = aResponse.sources.filter(function (s) { |
|
49 return s.url === SOURCE_URL; |
|
50 })[0]; |
|
51 |
|
52 do_check_true(!!source); |
|
53 |
|
54 let sourceClient = gThreadClient.source(source); |
|
55 sourceClient.source(function (aResponse) { |
|
56 do_check_true(!!aResponse); |
|
57 do_check_true(!aResponse.error); |
|
58 do_check_true(!!aResponse.contentType); |
|
59 do_check_true(aResponse.contentType.contains("javascript")); |
|
60 |
|
61 do_check_true(!!aResponse.source); |
|
62 do_check_eq(SOURCE_CONTENT, |
|
63 aResponse.source); |
|
64 |
|
65 gThreadClient.resume(function () { |
|
66 finishClient(gClient); |
|
67 }); |
|
68 }); |
|
69 }); |
|
70 }); |
|
71 |
|
72 Cu.evalInSandbox( |
|
73 SOURCE_CONTENT, |
|
74 gDebuggee, |
|
75 "1.8", |
|
76 SOURCE_URL |
|
77 ); |
|
78 } |