Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / debugger / qdeclarativedebugjs / tst_qdeclarativedebugjs.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QtCore/QProcess>
44 #include <QtCore/QTimer>
45 #include <QtCore/QFileInfo>
46 #include <QtCore/QDir>
47 #include <QtCore/QMutex>
48 #include <QtCore/QLibraryInfo>
49 #include <QtDeclarative/private/qdeclarativedebugclient_p.h>
50 #include <QtDeclarative/QJSEngine>
51
52 //QDeclarativeDebugTest
53 #include "../shared/debugutil_p.h"
54 #include "../../../shared/util.h"
55
56 const char *V8REQUEST = "v8request";
57 const char *V8MESSAGE = "v8message";
58 const char *SEQ = "seq";
59 const char *TYPE = "type";
60 const char *COMMAND = "command";
61 const char *ARGUMENTS = "arguments";
62 const char *STEPACTION = "stepaction";
63 const char *STEPCOUNT = "stepcount";
64 const char *EXPRESSION = "expression";
65 const char *FRAME = "frame";
66 const char *GLOBAL = "global";
67 const char *DISABLEBREAK = "disable_break";
68 const char *HANDLES = "handles";
69 const char *INCLUDESOURCE = "includeSource";
70 const char *FROMFRAME = "fromFrame";
71 const char *TOFRAME = "toFrame";
72 const char *BOTTOM = "bottom";
73 const char *NUMBER = "number";
74 const char *FRAMENUMBER = "frameNumber";
75 const char *TYPES = "types";
76 const char *IDS = "ids";
77 const char *FILTER = "filter";
78 const char *FROMLINE = "fromLine";
79 const char *TOLINE = "toLine";
80 const char *TARGET = "target";
81 const char *LINE = "line";
82 const char *COLUMN = "column";
83 const char *ENABLED = "enabled";
84 const char *CONDITION = "condition";
85 const char *IGNORECOUNT = "ignoreCount";
86 const char *BREAKPOINT = "breakpoint";
87 const char *FLAGS = "flags";
88
89 const char *CONTINEDEBUGGING = "continue";
90 const char *EVALUATE = "evaluate";
91 const char *LOOKUP = "lookup";
92 const char *BACKTRACE = "backtrace";
93 const char *SCOPE = "scope";
94 const char *SCOPES = "scopes";
95 const char *SCRIPTS = "scripts";
96 const char *SOURCE = "source";
97 const char *SETBREAKPOINT = "setbreakpoint";
98 const char *CHANGEBREAKPOINT = "changebreakpoint";
99 const char *CLEARBREAKPOINT = "clearbreakpoint";
100 const char *SETEXCEPTIONBREAK = "setexceptionbreak";
101 const char *V8FLAGS = "v8flags";
102 const char *VERSION = "version";
103 const char *DISCONNECT = "disconnect";
104 const char *LISTBREAKPOINTS = "listbreakpoints";
105 const char *GARBAGECOLLECTOR = "gc";
106 //const char *PROFILE = "profile";
107
108 const char *CONNECT = "connect";
109 const char *INTERRUPT = "interrupt";
110 const char *BREAKAFTERCOMPILE = "breakaftercompile";
111
112 const char *REQUEST = "request";
113 const char *IN = "in";
114 const char *NEXT = "next";
115 const char *OUT = "out";
116
117 const char *FUNCTION = "function";
118 const char *SCRIPT = "script";
119 const char *SCRIPTREGEXP = "scriptRegExp";
120 const char *EVENT = "event";
121
122 const char *ALL = "all";
123 const char *UNCAUGHT = "uncaught";
124
125 //const char *PAUSE = "pause";
126 //const char *RESUME = "resume";
127
128 const char *BLOCKMODE = "-qmljsdebugger=port:3771,block";
129 const char *NORMALMODE = "-qmljsdebugger=port:3771";
130 const char *TEST_QMLFILE = "test.qml";
131 const char *TEST_JSFILE = "test.js";
132 const char *TIMER_QMLFILE = "timer.qml";
133 const char *LOADJSFILE_QMLFILE = "loadjsfile.qml";
134 const char *EXCEPTION_QMLFILE = "exception.qml";
135 const char *ONCOMPLETED_QMLFILE = "oncompleted.qml";
136 const char *CREATECOMPONENT_QMLFILE = "createComponent.qml";
137 const char *CONDITION_QMLFILE = "condition.qml";
138 const char *CHANGEBREAKPOINT_QMLFILE = "changeBreakpoint.qml";
139 const char *STEPACTION_QMLFILE = "stepAction.qml";
140 const char *BREAKPOINTRELOCATION_QMLFILE = "breakpointRelocation.qml";
141
142 #define VARIANTMAPINIT \
143     QString obj("{}"); \
144     QJSValue jsonVal = parser.call(QJSValueList() << obj); \
145     jsonVal.setProperty(SEQ,QJSValue(seq++)); \
146     jsonVal.setProperty(TYPE,REQUEST);
147
148
149 #undef QVERIFY
150 #define QVERIFY(statement) \
151 do {\
152     if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) {\
153         if (QTest::currentTestFailed()) \
154           qDebug().nospace() << "\nDEBUGGEE OUTPUT:\n" << process->output();\
155         return;\
156     }\
157 } while (0)
158
159
160 class QJSDebugClient;
161
162 class tst_QDeclarativeDebugJS : public QDeclarativeDataTest
163 {
164     Q_OBJECT
165
166     bool init(const QString &qmlFile = QString(TEST_QMLFILE), bool blockMode = true);
167
168 private slots:
169     void initTestCase();
170     void cleanupTestCase();
171
172     void cleanup();
173
174     void connect();
175     void interrupt();
176     void breakAfterCompile();
177     void getVersion();
178     void getVersionWhenAttaching();
179
180     void applyV8Flags();
181
182     void disconnect();
183
184     void gc();
185
186     void listBreakpoints();
187
188     void setBreakpointInScriptOnCompleted();
189     void setBreakpointInScriptOnComponentCreated();
190     void setBreakpointInScriptOnTimerCallback();
191     void setBreakpointInScriptInDifferentFile();
192     void setBreakpointInScriptOnComment();
193     void setBreakpointInScriptOnEmptyLine();
194     void setBreakpointInScriptWithCondition();
195     //void setBreakpointInFunction(); //NOT SUPPORTED
196     void setBreakpointOnEvent();
197     void setBreakpointWhenAttaching();
198
199     void changeBreakpoint();
200     void changeBreakpointOnCondition();
201
202     void clearBreakpoint();
203
204     void setExceptionBreak();
205
206     void stepNext();
207     void stepNextWithCount();
208     void stepIn();
209     void stepOut();
210     void continueDebugging();
211
212     void backtrace();
213
214     void getFrameDetails();
215
216     void getScopeDetails();
217
218     void evaluateInGlobalScope();
219     void evaluateInLocalScope();
220
221     void getScopes();
222
223     void getScripts();
224
225     void getSource();
226
227     //    void profile(); //NOT SUPPORTED
228
229     //    void verifyQMLOptimizerDisabled();
230
231 private:
232     QDeclarativeDebugProcess *process;
233     QJSDebugClient *client;
234     QDeclarativeDebugConnection *connection;
235     QTime t;
236 };
237
238 class QJSDebugClient : public QDeclarativeDebugClient
239 {
240     Q_OBJECT
241 public:
242     enum StepAction
243     {
244         Continue,
245         In,
246         Out,
247         Next
248     };
249
250     enum Exception
251     {
252         All,
253         Uncaught
254     };
255
256 //    enum ProfileCommand
257 //    {
258 //        Pause,
259 //        Resume
260 //    };
261
262     QJSDebugClient(QDeclarativeDebugConnection *connection)
263         : QDeclarativeDebugClient(QLatin1String("V8Debugger"), connection),
264           seq(0)
265     {
266         parser = jsEngine.evaluate(QLatin1String("JSON.parse"));
267         stringify = jsEngine.evaluate(QLatin1String("JSON.stringify"));
268     }
269
270     void connect();
271     void interrupt();
272     void breakAfterCompile(bool enabled);
273
274     void continueDebugging(StepAction stepAction, int stepCount = 1);
275     void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
276     void lookup(QList<int> handles, bool includeSource = false);
277     void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false);
278     void frame(int number = -1);
279     void scope(int number = -1, int frameNumber = -1);
280     void scopes(int frameNumber = -1);
281     void scripts(int types = 4, QList<int> ids = QList<int>(), bool includeSource = false, QVariant filter = QVariant());
282     void source(int frame = -1, int fromLine = -1, int toLine = -1);
283     void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = true, QString condition = QString(), int ignoreCount = -1);
284     void changeBreakpoint(int breakpoint, bool enabled = true, QString condition = QString(), int ignoreCount = -1);
285     void clearBreakpoint(int breakpoint);
286     void setExceptionBreak(Exception type, bool enabled = false);
287     void v8flags(QString flags);
288     void version();
289     //void profile(ProfileCommand command); //NOT SUPPORTED
290     void disconnect();
291     void gc();
292     void listBreakpoints();
293
294 protected:
295     //inherited from QDeclarativeDebugClient
296     void statusChanged(Status status);
297     void messageReceived(const QByteArray &data);
298
299 signals:
300     void enabled();
301     void connected();
302     void interruptRequested();
303     void breakAfterCompileRequested();
304     void result();
305     void stopped();
306
307 private:
308     void sendMessage(const QByteArray &);
309     void flushSendBuffer();
310     QByteArray packMessage(const QByteArray &type, const QByteArray &message = QByteArray());
311
312 private:
313     QJSEngine jsEngine;
314     int seq;
315
316     QList<QByteArray> sendBuffer;
317 public:
318     QJSValue parser;
319     QJSValue stringify;
320     QByteArray response;
321
322 };
323
324 void QJSDebugClient::connect()
325 {
326     sendMessage(packMessage(CONNECT));
327 }
328
329 void QJSDebugClient::interrupt()
330 {
331     sendMessage(packMessage(INTERRUPT));
332 }
333
334 void QJSDebugClient::breakAfterCompile(bool enabled)
335 {
336     QByteArray request;
337     QDataStream rs(&request, QIODevice::WriteOnly);
338     rs << enabled;
339     sendMessage(packMessage(BREAKAFTERCOMPILE, request));
340 }
341
342 void QJSDebugClient::continueDebugging(StepAction action, int count)
343 {
344     //    { "seq"       : <number>,
345     //      "type"      : "request",
346     //      "command"   : "continue",
347     //      "arguments" : { "stepaction" : <"in", "next" or "out">,
348     //                      "stepcount"  : <number of steps (default 1)>
349     //                    }
350     //    }
351     VARIANTMAPINIT;
352     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CONTINEDEBUGGING)));
353
354     if (action != Continue) {
355         QJSValue args = parser.call(QJSValueList() << obj);
356         switch (action) {
357         case In: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(IN)));
358             break;
359         case Out: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(OUT)));
360             break;
361         case Next: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(NEXT)));
362             break;
363         default:break;
364         }
365         if (!args.isUndefined()) {
366             if (count != 1)
367                 args.setProperty(QLatin1String(STEPCOUNT),QJSValue(count));
368             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
369         }
370     }
371     QJSValue json = stringify.call(QJSValueList() << jsonVal);
372     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
373 }
374
375 void QJSDebugClient::evaluate(QString expr, bool global, bool disableBreak, int frame, const QVariantMap &/*addContext*/)
376 {
377     //    { "seq"       : <number>,
378     //      "type"      : "request",
379     //      "command"   : "evaluate",
380     //      "arguments" : { "expression"    : <expression to evaluate>,
381     //                      "frame"         : <number>,
382     //                      "global"        : <boolean>,
383     //                      "disable_break" : <boolean>,
384     //                      "additional_context" : [
385     //                           { "name" : <name1>, "handle" : <handle1> },
386     //                           { "name" : <name2>, "handle" : <handle2> },
387     //                           ...
388     //                      ]
389     //                    }
390     //    }
391     VARIANTMAPINIT;
392     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(EVALUATE)));
393
394     QJSValue args = parser.call(QJSValueList() << obj);
395     args.setProperty(QLatin1String(EXPRESSION),QJSValue(expr));
396
397     if (frame != -1)
398         args.setProperty(QLatin1String(FRAME),QJSValue(frame));
399
400     if (global)
401         args.setProperty(QLatin1String(GLOBAL),QJSValue(global));
402
403     if (disableBreak)
404         args.setProperty(QLatin1String(DISABLEBREAK),QJSValue(disableBreak));
405
406     if (!args.isUndefined()) {
407         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
408     }
409
410     QJSValue json = stringify.call(QJSValueList() << jsonVal);
411     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
412 }
413
414 void QJSDebugClient::lookup(QList<int> handles, bool includeSource)
415 {
416     //    { "seq"       : <number>,
417     //      "type"      : "request",
418     //      "command"   : "lookup",
419     //      "arguments" : { "handles"       : <array of handles>,
420     //                      "includeSource" : <boolean indicating whether the source will be included when script objects are returned>,
421     //                    }
422     //    }
423     VARIANTMAPINIT;
424     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LOOKUP)));
425
426     QJSValue args = parser.call(QJSValueList() << obj);
427
428     QString arr("[]");
429     QJSValue array = parser.call(QJSValueList() << arr);
430     int index = 0;
431     foreach (int handle, handles) {
432         array.setProperty(index++,QJSValue(handle));
433     }
434     args.setProperty(QLatin1String(HANDLES),array);
435
436     if (includeSource)
437         args.setProperty(QLatin1String(INCLUDESOURCE),QJSValue(includeSource));
438
439     if (!args.isUndefined()) {
440         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
441     }
442
443     QJSValue json = stringify.call(QJSValueList() << jsonVal);
444     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
445 }
446
447 void QJSDebugClient::backtrace(int fromFrame, int toFrame, bool bottom)
448 {
449     //    { "seq"       : <number>,
450     //      "type"      : "request",
451     //      "command"   : "backtrace",
452     //      "arguments" : { "fromFrame" : <number>
453     //                      "toFrame" : <number>
454     //                      "bottom" : <boolean, set to true if the bottom of the stack is requested>
455     //                    }
456     //    }
457     VARIANTMAPINIT;
458     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(BACKTRACE)));
459
460     QJSValue args = parser.call(QJSValueList() << obj);
461
462     if (fromFrame != -1)
463         args.setProperty(QLatin1String(FROMFRAME),QJSValue(fromFrame));
464
465     if (toFrame != -1)
466         args.setProperty(QLatin1String(TOFRAME),QJSValue(toFrame));
467
468     if (bottom)
469         args.setProperty(QLatin1String(BOTTOM),QJSValue(bottom));
470
471     if (!args.isUndefined()) {
472         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
473     }
474
475     QJSValue json = stringify.call(QJSValueList() << jsonVal);
476     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
477 }
478
479 void QJSDebugClient::frame(int number)
480 {
481     //    { "seq"       : <number>,
482     //      "type"      : "request",
483     //      "command"   : "frame",
484     //      "arguments" : { "number" : <frame number>
485     //                    }
486     //    }
487     VARIANTMAPINIT;
488     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(FRAME)));
489
490     if (number != -1) {
491         QJSValue args = parser.call(QJSValueList() << obj);
492         args.setProperty(QLatin1String(NUMBER),QJSValue(number));
493
494         if (!args.isUndefined()) {
495             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
496         }
497     }
498
499     QJSValue json = stringify.call(QJSValueList() << jsonVal);
500     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
501 }
502
503 void QJSDebugClient::scope(int number, int frameNumber)
504 {
505     //    { "seq"       : <number>,
506     //      "type"      : "request",
507     //      "command"   : "scope",
508     //      "arguments" : { "number" : <scope number>
509     //                      "frameNumber" : <frame number, optional uses selected frame if missing>
510     //                    }
511     //    }
512     VARIANTMAPINIT;
513     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCOPE)));
514
515     if (number != -1) {
516         QJSValue args = parser.call(QJSValueList() << obj);
517         args.setProperty(QLatin1String(NUMBER),QJSValue(number));
518
519         if (frameNumber != -1)
520             args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber));
521
522         if (!args.isUndefined()) {
523             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
524         }
525     }
526
527     QJSValue json = stringify.call(QJSValueList() << jsonVal);
528     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
529 }
530
531 void QJSDebugClient::scopes(int frameNumber)
532 {
533     //    { "seq"       : <number>,
534     //      "type"      : "request",
535     //      "command"   : "scopes",
536     //      "arguments" : { "frameNumber" : <frame number, optional uses selected frame if missing>
537     //                    }
538     //    }
539     VARIANTMAPINIT;
540     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCOPES)));
541
542     if (frameNumber != -1) {
543         QJSValue args = parser.call(QJSValueList() << obj);
544         args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber));
545
546         if (!args.isUndefined()) {
547             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
548         }
549     }
550
551     QJSValue json = stringify.call(QJSValueList() << jsonVal);
552     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
553 }
554
555 void QJSDebugClient::scripts(int types, QList<int> ids, bool includeSource, QVariant /*filter*/)
556 {
557     //    { "seq"       : <number>,
558     //      "type"      : "request",
559     //      "command"   : "scripts",
560     //      "arguments" : { "types"         : <types of scripts to retrieve
561     //                                           set bit 0 for native scripts
562     //                                           set bit 1 for extension scripts
563     //                                           set bit 2 for normal scripts
564     //                                         (default is 4 for normal scripts)>
565     //                      "ids"           : <array of id's of scripts to return. If this is not specified all scripts are requrned>
566     //                      "includeSource" : <boolean indicating whether the source code should be included for the scripts returned>
567     //                      "filter"        : <string or number: filter string or script id.
568     //                                         If a number is specified, then only the script with the same number as its script id will be retrieved.
569     //                                         If a string is specified, then only scripts whose names contain the filter string will be retrieved.>
570     //                    }
571     //    }
572     VARIANTMAPINIT;
573     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCRIPTS)));
574
575     QJSValue args = parser.call(QJSValueList() << obj);
576     args.setProperty(QLatin1String(TYPES),QJSValue(types));
577
578     if (ids.count()) {
579         QString arr("[]");
580         QJSValue array = parser.call(QJSValueList() << arr);
581         int index = 0;
582         foreach (int id, ids) {
583             array.setProperty(index++,QJSValue(id));
584         }
585         args.setProperty(QLatin1String(IDS),array);
586     }
587
588     if (includeSource)
589         args.setProperty(QLatin1String(INCLUDESOURCE),QJSValue(includeSource));
590
591     if (!args.isUndefined()) {
592         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
593     }
594
595     QJSValue json = stringify.call(QJSValueList() << jsonVal);
596     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
597 }
598
599 void QJSDebugClient::source(int frame, int fromLine, int toLine)
600 {
601     //    { "seq"       : <number>,
602     //      "type"      : "request",
603     //      "command"   : "source",
604     //      "arguments" : { "frame"    : <frame number (default selected frame)>
605     //                      "fromLine" : <from line within the source default is line 0>
606     //                      "toLine"   : <to line within the source this line is not included in
607     //                                    the result default is the number of lines in the script>
608     //                    }
609     //    }
610     VARIANTMAPINIT;
611     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SOURCE)));
612
613     QJSValue args = parser.call(QJSValueList() << obj);
614
615     if (frame != -1)
616         args.setProperty(QLatin1String(FRAME),QJSValue(frame));
617
618     if (fromLine != -1)
619         args.setProperty(QLatin1String(FROMLINE),QJSValue(fromLine));
620
621     if (toLine != -1)
622         args.setProperty(QLatin1String(TOLINE),QJSValue(toLine));
623
624     if (!args.isUndefined()) {
625         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
626     }
627
628     QJSValue json = stringify.call(QJSValueList() << jsonVal);
629     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
630 }
631
632 void QJSDebugClient::setBreakpoint(QString type, QString target, int line, int column, bool enabled, QString condition, int ignoreCount)
633 {
634     //    { "seq"       : <number>,
635     //      "type"      : "request",
636     //      "command"   : "setbreakpoint",
637     //      "arguments" : { "type"        : <"function" or "script" or "scriptId" or "scriptRegExp">
638     //                      "target"      : <function expression or script identification>
639     //                      "line"        : <line in script or function>
640     //                      "column"      : <character position within the line>
641     //                      "enabled"     : <initial enabled state. True or false, default is true>
642     //                      "condition"   : <string with break point condition>
643     //                      "ignoreCount" : <number specifying the number of break point hits to ignore, default value is 0>
644     //                    }
645     //    }
646
647     if (type == QLatin1String(EVENT)) {
648         QByteArray reply;
649         QDataStream rs(&reply, QIODevice::WriteOnly);
650         rs <<  target.toUtf8() << enabled;
651         sendMessage(packMessage(QByteArray("breakonsignal"), reply));
652
653     } else {
654         VARIANTMAPINIT;
655         jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETBREAKPOINT)));
656
657         QJSValue args = parser.call(QJSValueList() << obj);
658
659         args.setProperty(QLatin1String(TYPE),QJSValue(type));
660         args.setProperty(QLatin1String(TARGET),QJSValue(target));
661
662         if (line != -1)
663             args.setProperty(QLatin1String(LINE),QJSValue(line));
664
665         if (column != -1)
666             args.setProperty(QLatin1String(COLUMN),QJSValue(column));
667
668         args.setProperty(QLatin1String(ENABLED),QJSValue(enabled));
669
670         if (!condition.isEmpty())
671             args.setProperty(QLatin1String(CONDITION),QJSValue(condition));
672
673         if (ignoreCount != -1)
674             args.setProperty(QLatin1String(IGNORECOUNT),QJSValue(ignoreCount));
675
676         if (!args.isUndefined()) {
677             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
678         }
679
680         QJSValue json = stringify.call(QJSValueList() << jsonVal);
681         sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
682     }
683 }
684
685 void QJSDebugClient::changeBreakpoint(int breakpoint, bool enabled, QString condition, int ignoreCount)
686 {
687     //    { "seq"       : <number>,
688     //      "type"      : "request",
689     //      "command"   : "changebreakpoint",
690     //      "arguments" : { "breakpoint"  : <number of the break point to clear>
691     //                      "enabled"     : <initial enabled state. True or false, default is true>
692     //                      "condition"   : <string with break point condition>
693     //                      "ignoreCount" : <number specifying the number of break point hits            }
694     //    }
695     VARIANTMAPINIT;
696     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CHANGEBREAKPOINT)));
697
698     QJSValue args = parser.call(QJSValueList() << obj);
699
700     args.setProperty(QLatin1String(BREAKPOINT),QJSValue(breakpoint));
701
702     args.setProperty(QLatin1String(ENABLED),QJSValue(enabled));
703
704     if (!condition.isEmpty())
705         args.setProperty(QLatin1String(CONDITION),QJSValue(condition));
706
707     if (ignoreCount != -1)
708         args.setProperty(QLatin1String(IGNORECOUNT),QJSValue(ignoreCount));
709
710     if (!args.isUndefined()) {
711         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
712     }
713
714     QJSValue json = stringify.call(QJSValueList() << jsonVal);
715     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
716 }
717
718 void QJSDebugClient::clearBreakpoint(int breakpoint)
719 {
720     //    { "seq"       : <number>,
721     //      "type"      : "request",
722     //      "command"   : "clearbreakpoint",
723     //      "arguments" : { "breakpoint" : <number of the break point to clear>
724     //                    }
725     //    }
726     VARIANTMAPINIT;
727     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CLEARBREAKPOINT)));
728
729     QJSValue args = parser.call(QJSValueList() << obj);
730
731     args.setProperty(QLatin1String(BREAKPOINT),QJSValue(breakpoint));
732
733     if (!args.isUndefined()) {
734         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
735     }
736
737     QJSValue json = stringify.call(QJSValueList() << jsonVal);
738     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
739 }
740
741 void QJSDebugClient::setExceptionBreak(Exception type, bool enabled)
742 {
743     //    { "seq"       : <number>,
744     //      "type"      : "request",
745     //      "command"   : "setexceptionbreak",
746     //      "arguments" : { "type"    : <string: "all", or "uncaught">,
747     //                      "enabled" : <optional bool: enables the break type if true>
748     //                    }
749     //    }
750     VARIANTMAPINIT;
751     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETEXCEPTIONBREAK)));
752
753     QJSValue args = parser.call(QJSValueList() << obj);
754
755     if (type == All)
756         args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(ALL)));
757     else if (type == Uncaught)
758         args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(UNCAUGHT)));
759
760     if (enabled)
761         args.setProperty(QLatin1String(ENABLED),QJSValue(enabled));
762
763     if (!args.isUndefined()) {
764         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
765     }
766
767     QJSValue json = stringify.call(QJSValueList() << jsonVal);
768     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
769 }
770
771 void QJSDebugClient::v8flags(QString flags)
772 {
773     //    { "seq"       : <number>,
774     //      "type"      : "request",
775     //      "command"   : "v8flags",
776     //      "arguments" : { "flags" : <string: a sequence of v8 flags just like those used on the command line>
777     //                    }
778     //    }
779     VARIANTMAPINIT;
780     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(V8FLAGS)));
781
782     QJSValue args = parser.call(QJSValueList() << obj);
783
784     args.setProperty(QLatin1String(FLAGS),QJSValue(flags));
785
786     if (!args.isUndefined()) {
787         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
788     }
789
790     QJSValue json = stringify.call(QJSValueList() << jsonVal);
791     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
792 }
793
794 void QJSDebugClient::version()
795 {
796     //    { "seq"       : <number>,
797     //      "type"      : "request",
798     //      "command"   : "version",
799     //    }
800     VARIANTMAPINIT;
801     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(VERSION)));
802
803     QJSValue json = stringify.call(QJSValueList() << jsonVal);
804     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
805 }
806
807 //void QJSDebugClient::profile(ProfileCommand command)
808 //{
809 ////    { "seq"       : <number>,
810 ////      "type"      : "request",
811 ////      "command"   : "profile",
812 ////      "arguments" : { "command"  : "resume" or "pause" }
813 ////    }
814 //    VARIANTMAPINIT;
815 //    jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(PROFILE)));
816
817 //    QJSValue args = parser.call(QJSValueList() << obj);
818
819 //    if (command == Resume)
820 //        args.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(RESUME)));
821 //    else
822 //        args.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(PAUSE)));
823
824 //    args.setProperty(QLatin1String("modules"),QJSValue(1));
825 //    if (!args.isUndefined()) {
826 //        jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
827 //    }
828
829 //    QJSValue json = stringify.call(QJSValueList() << jsonVal);
830 //    sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
831 //}
832
833 void QJSDebugClient::disconnect()
834 {
835     //    { "seq"     : <number>,
836     //      "type"    : "request",
837     //      "command" : "disconnect",
838     //    }
839     VARIANTMAPINIT;
840     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(DISCONNECT)));
841
842     QJSValue json = stringify.call(QJSValueList() << jsonVal);
843     sendMessage(packMessage(DISCONNECT, json.toString().toUtf8()));
844 }
845
846 void QJSDebugClient::gc()
847 {
848     //    { "seq"       : <number>,
849     //      "type"      : "request",
850     //      "command"   : "gc",
851     //      "arguments" : { "type" : <string: "all">,
852     //                    }
853     //    }
854     VARIANTMAPINIT;
855     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(GARBAGECOLLECTOR)));
856
857     QJSValue args = parser.call(QJSValueList() << obj);
858
859     args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(ALL)));
860
861     if (!args.isUndefined()) {
862         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
863     }
864
865     QJSValue json = stringify.call(QJSValueList() << jsonVal);
866     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
867 }
868
869 void QJSDebugClient::listBreakpoints()
870 {
871     //    { "seq"       : <number>,
872     //      "type"      : "request",
873     //      "command"   : "listbreakpoints",
874     //    }
875     VARIANTMAPINIT;
876     jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LISTBREAKPOINTS)));
877
878     QJSValue json = stringify.call(QJSValueList() << jsonVal);
879     sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
880 }
881
882 void QJSDebugClient::statusChanged(Status status)
883 {
884     if (status == Enabled) {
885         flushSendBuffer();
886         emit enabled();
887     }
888 }
889
890 void QJSDebugClient::messageReceived(const QByteArray &data)
891 {
892     QDataStream ds(data);
893     QByteArray command;
894     ds >> command;
895
896     if (command == "V8DEBUG") {
897         QByteArray type;
898         ds >> type >> response;
899
900         if (type == CONNECT) {
901             emit connected();
902
903         } else if (type == INTERRUPT) {
904             emit interruptRequested();
905
906         } else if (type == V8MESSAGE) {
907             QString jsonString(response);
908             QVariantMap value = parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
909             QString type = value.value("type").toString();
910
911             if (type == "response") {
912
913                 if (!value.value("success").toBool()) {
914 //                    qDebug() << "Error: The test case will fail since no signal is emitted";
915                     return;
916                 }
917
918                 QString debugCommand(value.value("command").toString());
919                 if (debugCommand == "backtrace" ||
920                         debugCommand == "lookup" ||
921                         debugCommand == "setbreakpoint" ||
922                         debugCommand == "evaluate" ||
923                         debugCommand == "listbreakpoints" ||
924                         debugCommand == "version" ||
925                         debugCommand == "v8flags" ||
926                         debugCommand == "disconnect" ||
927                         debugCommand == "gc" ||
928                         debugCommand == "changebreakpoint" ||
929                         debugCommand == "clearbreakpoint" ||
930                         debugCommand == "frame" ||
931                         debugCommand == "scope" ||
932                         debugCommand == "scopes" ||
933                         debugCommand == "scripts" ||
934                         debugCommand == "source" ||
935                         debugCommand == "setexceptionbreak" /*||
936                         debugCommand == "profile"*/) {
937                     emit result();
938
939                 } else {
940                     // DO NOTHING
941                 }
942
943             } else if (type == QLatin1String(EVENT)) {
944                 QString event(value.value(QLatin1String(EVENT)).toString());
945
946                 if (event == "break" ||
947                         event == "exception")
948                     emit stopped();
949                 }
950
951         } else if (type == BREAKAFTERCOMPILE) {
952             emit breakAfterCompileRequested();
953
954         }
955     }
956 }
957
958 void QJSDebugClient::sendMessage(const QByteArray &msg)
959 {
960     if (status() == Enabled) {
961         QDeclarativeDebugClient::sendMessage(msg);
962     } else {
963         sendBuffer.append(msg);
964     }
965 }
966
967 void QJSDebugClient::flushSendBuffer()
968 {
969     foreach (const QByteArray &msg, sendBuffer)
970         QDeclarativeDebugClient::sendMessage(msg);
971     sendBuffer.clear();
972 }
973
974 QByteArray QJSDebugClient::packMessage(const QByteArray &type, const QByteArray &message)
975 {
976     QByteArray reply;
977     QDataStream rs(&reply, QIODevice::WriteOnly);
978     QByteArray cmd = "V8DEBUG";
979     rs << cmd << type << message;
980     return reply;
981 }
982
983 void tst_QDeclarativeDebugJS::initTestCase()
984 {
985     QDeclarativeDataTest::initTestCase();
986     t.start();
987     process = 0;
988     client = 0;
989     connection = 0;
990 }
991
992 void tst_QDeclarativeDebugJS::cleanupTestCase()
993 {
994     if (process) {
995         process->stop();
996         delete process;
997     }
998
999     if (client)
1000         delete client;
1001
1002     if (connection)
1003         delete connection;
1004
1005 //    qDebug() << "Time Elapsed:" << t.elapsed();
1006 }
1007
1008 bool tst_QDeclarativeDebugJS::init(const QString &qmlFile, bool blockMode)
1009 {
1010     connection = new QDeclarativeDebugConnection();
1011     process = new QDeclarativeDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene");
1012     client = new QJSDebugClient(connection);
1013
1014     QStringList systemEnvironment = QProcess::systemEnvironment();
1015     systemEnvironment << "QML_DISABLE_OPTIMIZER=1";
1016     process->setEnvironment(systemEnvironment);
1017     if (blockMode)
1018         process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(qmlFile));
1019     else
1020         process->start(QStringList() << QLatin1String(NORMALMODE) << testFile(qmlFile));
1021
1022     if (!process->waitForSessionStart()) {
1023         return false;
1024     }
1025
1026     connection->connectToHost("127.0.0.1", 3771);
1027     if (!connection->waitForConnected())
1028         return false;
1029
1030     return QDeclarativeDebugTest::waitForSignal(client, SIGNAL(enabled()));
1031 }
1032
1033 void tst_QDeclarativeDebugJS::cleanup()
1034 {
1035     if (process) {
1036         process->stop();
1037         delete process;
1038     }
1039
1040     if (client)
1041         delete client;
1042
1043     if (connection)
1044         delete connection;
1045
1046     process = 0;
1047     client = 0;
1048     connection = 0;
1049 }
1050
1051 void tst_QDeclarativeDebugJS::connect()
1052 {
1053     //void connect()
1054
1055     QVERIFY(init());
1056     client->connect();
1057     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(connected())));
1058 }
1059
1060 void tst_QDeclarativeDebugJS::interrupt()
1061 {
1062     //void connect()
1063
1064     QVERIFY(init());
1065     client->connect();
1066
1067     client->interrupt();
1068     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(interruptRequested())));
1069 }
1070
1071 void tst_QDeclarativeDebugJS::breakAfterCompile()
1072 {
1073     //void breakAfterCompile(bool enabled)
1074
1075     QVERIFY(init());
1076     client->breakAfterCompile(true);
1077     client->connect();
1078
1079     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(breakAfterCompileRequested())));
1080     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1081 }
1082
1083 void tst_QDeclarativeDebugJS::getVersion()
1084 {
1085     //void version()
1086
1087     QVERIFY(init());
1088     client->connect();
1089     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(connected())));
1090
1091     client->version();
1092     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1093 }
1094
1095 void tst_QDeclarativeDebugJS::getVersionWhenAttaching()
1096 {
1097     //void version()
1098
1099     QVERIFY(init(QLatin1String(TIMER_QMLFILE), false));
1100     client->connect();
1101
1102     client->version();
1103     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1104 }
1105
1106 void tst_QDeclarativeDebugJS::applyV8Flags()
1107 {
1108     //void v8flags(QString flags)
1109
1110     QVERIFY(init());
1111     client->connect();
1112
1113     client->v8flags(QString());
1114     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1115 }
1116
1117 void tst_QDeclarativeDebugJS::disconnect()
1118 {
1119     //void disconnect()
1120
1121     QVERIFY(init());
1122     client->connect();
1123
1124     client->disconnect();
1125     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1126 }
1127
1128 void tst_QDeclarativeDebugJS::gc()
1129 {
1130     //void gc()
1131
1132     QVERIFY(init());
1133     client->connect();
1134
1135     client->gc();
1136     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1137 }
1138
1139 void tst_QDeclarativeDebugJS::listBreakpoints()
1140 {
1141     //void listBreakpoints()
1142
1143     int sourceLine1 = 47;
1144     int sourceLine2 = 48;
1145     int sourceLine3 = 49;
1146
1147     QVERIFY(init());
1148     client->connect();
1149
1150     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true);
1151     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1152     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true);
1153     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1154     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine3, -1, true);
1155     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1156     client->listBreakpoints();
1157     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1158
1159     QString jsonString(client->response);
1160     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1161
1162     QList<QVariant> breakpoints = value.value("body").toMap().value("breakpoints").toList();
1163
1164     QCOMPARE(breakpoints.count(), 3);
1165 }
1166
1167 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnCompleted()
1168 {
1169     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1170
1171     int sourceLine = 47;
1172     QVERIFY(init(ONCOMPLETED_QMLFILE));
1173
1174     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1175     client->connect();
1176     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1177
1178     QString jsonString(client->response);
1179     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1180
1181     QVariantMap body = value.value("body").toMap();
1182
1183     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1184     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(ONCOMPLETED_QMLFILE));
1185 }
1186
1187 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComponentCreated()
1188 {
1189     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1190
1191     int sourceLine = 47;
1192     QVERIFY(init(CREATECOMPONENT_QMLFILE));
1193
1194     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1195     client->connect();
1196     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1197
1198     QString jsonString(client->response);
1199     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1200
1201     QVariantMap body = value.value("body").toMap();
1202
1203     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1204     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(ONCOMPLETED_QMLFILE));
1205 }
1206
1207 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback()
1208 {
1209     int sourceLine = 48;
1210     QVERIFY(init(TIMER_QMLFILE));
1211
1212     client->connect();
1213
1214     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TIMER_QMLFILE), sourceLine, -1, true);
1215     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1216
1217     QString jsonString(client->response);
1218     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1219
1220     QVariantMap body = value.value("body").toMap();
1221
1222     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1223     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TIMER_QMLFILE));
1224 }
1225
1226 void tst_QDeclarativeDebugJS::setBreakpointInScriptInDifferentFile()
1227 {
1228     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1229
1230     int sourceLine = 43;
1231     QVERIFY(init(LOADJSFILE_QMLFILE));
1232
1233     client->connect();
1234     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_JSFILE), sourceLine, -1, true);
1235     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1236
1237     QString jsonString(client->response);
1238     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1239
1240     QVariantMap body = value.value("body").toMap();
1241
1242     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1243     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_JSFILE));
1244 }
1245
1246 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComment()
1247 {
1248     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1249
1250     int sourceLine = 47;
1251     int actualLine = 49;
1252     QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE));
1253
1254     client->connect();
1255     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true);
1256     QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort);
1257     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 1));
1258
1259     QString jsonString(client->response);
1260     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1261
1262     QVariantMap body = value.value("body").toMap();
1263
1264     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1265     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(BREAKPOINTRELOCATION_QMLFILE));
1266 }
1267
1268 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnEmptyLine()
1269 {
1270     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1271
1272     int sourceLine = 48;
1273     int actualLine = 49;
1274     QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE));
1275
1276     client->connect();
1277     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true);
1278     QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort);
1279     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 1));
1280
1281     QString jsonString(client->response);
1282     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1283
1284     QVariantMap body = value.value("body").toMap();
1285
1286     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1287     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(BREAKPOINTRELOCATION_QMLFILE));
1288 }
1289
1290 void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition()
1291 {
1292     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1293
1294     int out = 10;
1295     int sourceLine = 50;
1296     QVERIFY(init(CONDITION_QMLFILE));
1297
1298     client->connect();
1299     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CONDITION_QMLFILE), sourceLine, 1, true, QLatin1String("a > 10"));
1300     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1301
1302     //Get the frame index
1303     QString jsonString = client->response;
1304     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1305
1306     QVariantMap body = value.value("body").toMap();
1307
1308     int frameIndex = body.value("index").toInt();
1309
1310     //Verify the value of 'result'
1311     client->evaluate(QLatin1String("a"),frameIndex);
1312
1313     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1314
1315     jsonString = client->response;
1316     value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1317
1318     body = value.value("body").toMap();
1319
1320     QVERIFY(body.value("value").toInt() > out);
1321 }
1322
1323 void tst_QDeclarativeDebugJS::setBreakpointWhenAttaching()
1324 {
1325     int sourceLine = 49;
1326     QVERIFY(init(QLatin1String(TIMER_QMLFILE), false));
1327
1328     client->connect();
1329     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TIMER_QMLFILE), sourceLine);
1330     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1331 }
1332
1333 //void tst_QDeclarativeDebugJS::setBreakpointInFunction()
1334 //{
1335 //    //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1336
1337 //    int actualLine = 31;
1338
1339 //    client->connect();
1340 //    client->setBreakpoint(QLatin1String(FUNCTION), QLatin1String("doSomethingElse"), -1, -1, true);
1341
1342 //    QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1343
1344 //    QString jsonString(client->response);
1345 //    QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1346
1347 //    QVariantMap body = value.value("body").toMap();
1348
1349 //    QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1350 //    QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE));
1351 //}
1352
1353 void tst_QDeclarativeDebugJS::setBreakpointOnEvent()
1354 {
1355     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1356
1357     QVERIFY(init(TIMER_QMLFILE));
1358
1359     client->connect();
1360
1361     client->setBreakpoint(QLatin1String(EVENT), QLatin1String("triggered"), -1, -1, true);
1362     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1363
1364     QString jsonString(client->response);
1365     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1366
1367     QVariantMap body = value.value("body").toMap();
1368
1369     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TIMER_QMLFILE));
1370 }
1371
1372
1373 void tst_QDeclarativeDebugJS::changeBreakpoint()
1374 {
1375     //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1376
1377     int sourceLine1 = 50;
1378     int sourceLine2 = 51;
1379     QVERIFY(init(CHANGEBREAKPOINT_QMLFILE));
1380
1381     client->connect();
1382     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true);
1383     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true);
1384
1385     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1386
1387     //Will hit 1st brakpoint, change this breakpoint enable = false
1388     QString jsonString(client->response);
1389     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1390
1391     QVariantMap body = value.value("body").toMap();
1392     QList<QVariant> breakpointsHit = body.value("breakpoints").toList();
1393
1394     int breakpoint = breakpointsHit.at(0).toInt();
1395     client->changeBreakpoint(breakpoint,false);
1396
1397     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1398
1399     //Continue with debugging
1400     client->continueDebugging(QJSDebugClient::Continue);
1401     //Hit 2nd breakpoint
1402     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1403
1404     //Continue with debugging
1405     client->continueDebugging(QJSDebugClient::Continue);
1406     //Should stop at 2nd breakpoint
1407     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1408
1409     jsonString = client->response;
1410     value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1411
1412     body = value.value("body").toMap();
1413
1414     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1415 }
1416
1417 void tst_QDeclarativeDebugJS::changeBreakpointOnCondition()
1418 {
1419     //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1420
1421     int sourceLine1 = 50;
1422     int sourceLine2 = 51;
1423
1424     QVERIFY(init(CHANGEBREAKPOINT_QMLFILE));
1425
1426     client->connect();
1427     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true);
1428     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true);
1429
1430     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1431
1432     //Will hit 1st brakpoint, change this breakpoint enable = false
1433     QString jsonString(client->response);
1434     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1435
1436     QVariantMap body = value.value("body").toMap();
1437     QList<QVariant> breakpointsHit = body.value("breakpoints").toList();
1438
1439     int breakpoint = breakpointsHit.at(0).toInt();
1440     client->changeBreakpoint(breakpoint, false, QLatin1String("d == 0"));
1441
1442     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1443
1444     //Continue with debugging
1445     client->continueDebugging(QJSDebugClient::Continue);
1446     //Hit 2nd breakpoint
1447     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1448
1449     //Continue with debugging
1450     client->continueDebugging(QJSDebugClient::Continue);
1451     //Should stop at 2nd breakpoint
1452     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1453
1454     jsonString = client->response;
1455     value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1456
1457     body = value.value("body").toMap();
1458
1459     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1460
1461 }
1462
1463 void tst_QDeclarativeDebugJS::clearBreakpoint()
1464 {
1465     //void clearBreakpoint(int breakpoint);
1466
1467     int sourceLine1 = 50;
1468     int sourceLine2 = 51;
1469     QVERIFY(init(CHANGEBREAKPOINT_QMLFILE));
1470
1471     client->connect();
1472     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true);
1473     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true);
1474
1475     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1476
1477     //Will hit 1st brakpoint, change this breakpoint enable = false
1478     QString jsonString(client->response);
1479     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1480
1481     QVariantMap body = value.value("body").toMap();
1482     QList<QVariant> breakpointsHit = body.value("breakpoints").toList();
1483
1484     int breakpoint = breakpointsHit.at(0).toInt();
1485     client->clearBreakpoint(breakpoint);
1486
1487     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1488
1489     //Continue with debugging
1490     client->continueDebugging(QJSDebugClient::Continue);
1491     //Hit 2nd breakpoint
1492     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1493
1494     //Continue with debugging
1495     client->continueDebugging(QJSDebugClient::Continue);
1496     //Should stop at 2nd breakpoint
1497     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1498
1499     jsonString = client->response;
1500     value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1501
1502     body = value.value("body").toMap();
1503
1504     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1505 }
1506
1507 void tst_QDeclarativeDebugJS::setExceptionBreak()
1508 {
1509     //void setExceptionBreak(QString type, bool enabled = false);
1510
1511     QVERIFY(init(EXCEPTION_QMLFILE));
1512     client->setExceptionBreak(QJSDebugClient::All,true);
1513     client->connect();
1514     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1515 }
1516
1517 void tst_QDeclarativeDebugJS::stepNext()
1518 {
1519     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1520
1521     int sourceLine = 50;
1522     QVERIFY(init(STEPACTION_QMLFILE));
1523
1524     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true);
1525     client->connect();
1526     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1527
1528     client->continueDebugging(QJSDebugClient::Next);
1529     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1530
1531     QString jsonString(client->response);
1532     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1533
1534     QVariantMap body = value.value("body").toMap();
1535
1536     QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 1);
1537     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1538 }
1539
1540 void tst_QDeclarativeDebugJS::stepNextWithCount()
1541 {
1542     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1543
1544     int sourceLine = 50;
1545     QVERIFY(init(STEPACTION_QMLFILE));
1546
1547     client->connect();
1548     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true);
1549     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1550
1551     client->continueDebugging(QJSDebugClient::Next, 2);
1552     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1553
1554     QString jsonString(client->response);
1555     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1556
1557     QVariantMap body = value.value("body").toMap();
1558
1559     QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 2);
1560     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1561 }
1562
1563 void tst_QDeclarativeDebugJS::stepIn()
1564 {
1565     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1566
1567     int sourceLine = 54;
1568     int actualLine = 50;
1569     QVERIFY(init(STEPACTION_QMLFILE));
1570
1571     client->connect();
1572     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, 1, true);
1573     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1574
1575     client->continueDebugging(QJSDebugClient::In);
1576     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1577
1578     QString jsonString(client->response);
1579     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1580
1581     QVariantMap body = value.value("body").toMap();
1582
1583     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1584     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1585 }
1586
1587 void tst_QDeclarativeDebugJS::stepOut()
1588 {
1589     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1590
1591     int sourceLine = 50;
1592     int actualLine = 54;
1593     QVERIFY(init(STEPACTION_QMLFILE));
1594
1595     client->connect();
1596     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true);
1597     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1598
1599     client->continueDebugging(QJSDebugClient::Out);
1600     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1601
1602     QString jsonString(client->response);
1603     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1604
1605     QVariantMap body = value.value("body").toMap();
1606
1607     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1608     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1609 }
1610
1611 void tst_QDeclarativeDebugJS::continueDebugging()
1612 {
1613     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1614
1615     int sourceLine1 = 54;
1616     int sourceLine2 = 51;
1617     QVERIFY(init(STEPACTION_QMLFILE));
1618
1619     client->connect();
1620     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine1, -1, true);
1621     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine2, -1, true);
1622     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1623
1624     client->continueDebugging(QJSDebugClient::Continue);
1625     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1626
1627     QString jsonString(client->response);
1628     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1629
1630     QVariantMap body = value.value("body").toMap();
1631
1632     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1633     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1634 }
1635
1636 void tst_QDeclarativeDebugJS::backtrace()
1637 {
1638     //void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false);
1639
1640     int sourceLine = 47;
1641     QVERIFY(init(ONCOMPLETED_QMLFILE));
1642
1643     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1644     client->connect();
1645     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1646
1647     client->backtrace();
1648     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1649 }
1650
1651 void tst_QDeclarativeDebugJS::getFrameDetails()
1652 {
1653     //void frame(int number = -1);
1654
1655     int sourceLine = 47;
1656     QVERIFY(init(ONCOMPLETED_QMLFILE));
1657
1658     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1659     client->connect();
1660     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1661
1662     client->frame();
1663     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1664 }
1665
1666 void tst_QDeclarativeDebugJS::getScopeDetails()
1667 {
1668     //void scope(int number = -1, int frameNumber = -1);
1669
1670     int sourceLine = 47;
1671     QVERIFY(init(ONCOMPLETED_QMLFILE));
1672
1673     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1674     client->connect();
1675     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1676
1677     client->scope();
1678     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1679 }
1680
1681 void tst_QDeclarativeDebugJS::evaluateInGlobalScope()
1682 {
1683     //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
1684
1685     QVERIFY(init());
1686
1687     client->connect();
1688     client->evaluate(QLatin1String("print('Hello World')"), true);
1689     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1690
1691     //Verify the value of 'print'
1692     QString jsonString(client->response);
1693     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1694
1695     QVariantMap body = value.value("body").toMap();
1696
1697     QCOMPARE(body.value("text").toString(),QLatin1String("undefined"));
1698 }
1699
1700 void tst_QDeclarativeDebugJS::evaluateInLocalScope()
1701 {
1702     //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
1703
1704     int sourceLine = 47;
1705     QVERIFY(init(ONCOMPLETED_QMLFILE));
1706
1707     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1708     client->connect();
1709     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1710
1711     client->frame();
1712     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1713
1714     //Get the frame index
1715     QString jsonString(client->response);
1716     QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1717
1718     QVariantMap body = value.value("body").toMap();
1719
1720     int frameIndex = body.value("index").toInt();
1721
1722     client->evaluate(QLatin1String("root.a"), frameIndex);
1723     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1724
1725     //Verify the value of 'timer.interval'
1726     jsonString = client->response;
1727     value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1728
1729     body = value.value("body").toMap();
1730
1731     QCOMPARE(body.value("value").toInt(),10);
1732 }
1733
1734 void tst_QDeclarativeDebugJS::getScopes()
1735 {
1736     //void scopes(int frameNumber = -1);
1737
1738     int sourceLine = 47;
1739     QVERIFY(init(ONCOMPLETED_QMLFILE));
1740
1741     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1742     client->connect();
1743     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1744
1745     client->scopes();
1746     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1747 }
1748
1749 void tst_QDeclarativeDebugJS::getScripts()
1750 {
1751     //void scripts(int types = -1, QList<int> ids = QList<int>(), bool includeSource = false, QVariant filter = QVariant());
1752
1753 #ifdef Q_OS_MAC
1754     QSKIP("QTBUG-23475 - Unreliable test on Mac OS X");
1755 #endif
1756
1757     QVERIFY(init());
1758
1759     client->connect();
1760
1761     client->scripts();
1762     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1763     QString jsonString(client->response);
1764     QVariantMap value = client->parser.call(QJSValueList()
1765                                             << QJSValue(jsonString)).toVariant().toMap();
1766
1767     QList<QVariant> scripts = value.value("body").toList();
1768
1769     QCOMPARE(scripts.count(), 2);
1770 }
1771
1772 void tst_QDeclarativeDebugJS::getSource()
1773 {
1774     //void source(int frame = -1, int fromLine = -1, int toLine = -1);
1775
1776     int sourceLine = 47;
1777     QVERIFY(init(ONCOMPLETED_QMLFILE));
1778
1779     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1780     client->connect();
1781     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1782
1783     client->source();
1784     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1785 }
1786
1787 QTEST_MAIN(tst_QDeclarativeDebugJS)
1788
1789 #include "tst_qdeclarativedebugjs.moc"
1790