QV8DebugService: Add breakaftercompile
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / debugger / qdeclarativedebugjs / tst_qdeclarativedebugjs.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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(QJSValue(), 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 QObject
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(QJSValue(), 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.isValid()) {
366             if (count != 1)
367                 args.setProperty(QLatin1String(STEPCOUNT),QJSValue(count));
368             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
369         }
370     }
371     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
407         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
408     }
409
410     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
427
428     QString arr("[]");
429     QJSValue array = parser.call(QJSValue(), 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.isValid()) {
440         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
441     }
442
443     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
472         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
473     }
474
475     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
492         args.setProperty(QLatin1String(NUMBER),QJSValue(number));
493
494         if (args.isValid()) {
495             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
496         }
497     }
498
499     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
523             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
524         }
525     }
526
527     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
544         args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber));
545
546         if (args.isValid()) {
547             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
548         }
549     }
550
551     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
576     args.setProperty(QLatin1String(TYPES),QJSValue(types));
577
578     if (ids.count()) {
579         QString arr("[]");
580         QJSValue array = parser.call(QJSValue(), 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.isValid()) {
592         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
593     }
594
595     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
625         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
626     }
627
628     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
677             jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
678         }
679
680         QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
711         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
712     }
713
714     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
730
731     args.setProperty(QLatin1String(BREAKPOINT),QJSValue(breakpoint));
732
733     if (args.isValid()) {
734         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
735     }
736
737     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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.isValid()) {
764         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
765     }
766
767     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
783
784     args.setProperty(QLatin1String(FLAGS),QJSValue(flags));
785
786     if (args.isValid()) {
787         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
788     }
789
790     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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(QJSValue(), 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.isValid()) {
826 //        jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
827 //    }
828
829 //    QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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(QJSValue(), QJSValueList() << obj);
858
859     args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(ALL)));
860
861     if (args.isValid()) {
862         jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
863     }
864
865     QJSValue json = stringify.call(QJSValue(), 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(QJSValue(), 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(QJSValue(), 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     t.start();
986     process = 0;
987     client = 0;
988     connection = 0;
989 }
990
991 void tst_QDeclarativeDebugJS::cleanupTestCase()
992 {
993     if (process) {
994         process->stop();
995         delete process;
996     }
997
998     if (client)
999         delete client;
1000
1001     if (connection)
1002         delete connection;
1003
1004 //    qDebug() << "Time Elapsed:" << t.elapsed();
1005 }
1006
1007 bool tst_QDeclarativeDebugJS::init(const QString &qmlFile, bool blockMode)
1008 {
1009     connection = new QDeclarativeDebugConnection();
1010     process = new QDeclarativeDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene");
1011     client = new QJSDebugClient(connection);
1012
1013     QStringList systemEnvironment = QProcess::systemEnvironment();
1014     systemEnvironment << "QML_DISABLE_OPTIMIZER=1";
1015     process->setEnvironment(systemEnvironment);
1016     if (blockMode)
1017         process->start(QStringList() << QLatin1String(BLOCKMODE) << TESTDATA(qmlFile));
1018     else
1019         process->start(QStringList() << QLatin1String(NORMALMODE) << TESTDATA(qmlFile));
1020
1021     if (!process->waitForSessionStart()) {
1022         return false;
1023     }
1024
1025     connection->connectToHost("127.0.0.1", 3771);
1026     if (!connection->waitForConnected())
1027         return false;
1028
1029     return QDeclarativeDebugTest::waitForSignal(client, SIGNAL(enabled()));
1030 }
1031
1032 void tst_QDeclarativeDebugJS::cleanup()
1033 {
1034     if (process) {
1035         process->stop();
1036         delete process;
1037     }
1038
1039     if (client)
1040         delete client;
1041
1042     if (connection)
1043         delete connection;
1044
1045     process = 0;
1046     client = 0;
1047     connection = 0;
1048 }
1049
1050 void tst_QDeclarativeDebugJS::connect()
1051 {
1052     //void connect()
1053
1054     QVERIFY(init());
1055     client->connect();
1056     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(connected())));
1057 }
1058
1059 void tst_QDeclarativeDebugJS::interrupt()
1060 {
1061     //void connect()
1062
1063     QVERIFY(init());
1064     client->connect();
1065
1066     client->interrupt();
1067     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(interruptRequested())));
1068 }
1069
1070 void tst_QDeclarativeDebugJS::breakAfterCompile()
1071 {
1072     //void breakAfterCompile(bool enabled)
1073
1074     QVERIFY(init());
1075     client->breakAfterCompile(true);
1076     client->connect();
1077
1078     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(breakAfterCompileRequested())));
1079     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1080 }
1081
1082 void tst_QDeclarativeDebugJS::getVersion()
1083 {
1084     //void version()
1085
1086     QVERIFY(init());
1087     client->connect();
1088     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(connected())));
1089
1090     client->version();
1091     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1092 }
1093
1094 void tst_QDeclarativeDebugJS::getVersionWhenAttaching()
1095 {
1096     //void version()
1097
1098     QVERIFY(init(QLatin1String(TIMER_QMLFILE), false));
1099     client->connect();
1100
1101     client->version();
1102     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1103 }
1104
1105 void tst_QDeclarativeDebugJS::applyV8Flags()
1106 {
1107     //void v8flags(QString flags)
1108
1109     QVERIFY(init());
1110     client->connect();
1111
1112     client->v8flags(QString());
1113     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1114 }
1115
1116 void tst_QDeclarativeDebugJS::disconnect()
1117 {
1118     //void disconnect()
1119
1120     QVERIFY(init());
1121     client->connect();
1122
1123     client->disconnect();
1124     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1125 }
1126
1127 void tst_QDeclarativeDebugJS::gc()
1128 {
1129     //void gc()
1130
1131     QVERIFY(init());
1132     client->connect();
1133
1134     client->gc();
1135     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1136 }
1137
1138 void tst_QDeclarativeDebugJS::listBreakpoints()
1139 {
1140     //void listBreakpoints()
1141
1142     int sourceLine1 = 47;
1143     int sourceLine2 = 48;
1144     int sourceLine3 = 49;
1145
1146     QVERIFY(init());
1147     client->connect();
1148
1149     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true);
1150     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1151     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true);
1152     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1153     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine3, -1, true);
1154     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1155     client->listBreakpoints();
1156     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1157
1158     QString jsonString(client->response);
1159     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1160
1161     QList<QVariant> breakpoints = value.value("body").toMap().value("breakpoints").toList();
1162
1163     QCOMPARE(breakpoints.count(), 3);
1164 }
1165
1166 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnCompleted()
1167 {
1168     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1169
1170     int sourceLine = 47;
1171     QVERIFY(init(ONCOMPLETED_QMLFILE));
1172
1173     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1174     client->connect();
1175     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1176
1177     QString jsonString(client->response);
1178     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1179
1180     QVariantMap body = value.value("body").toMap();
1181
1182     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1183     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(ONCOMPLETED_QMLFILE));
1184 }
1185
1186 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComponentCreated()
1187 {
1188     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1189
1190     int sourceLine = 47;
1191     QVERIFY(init(CREATECOMPONENT_QMLFILE));
1192
1193     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1194     client->connect();
1195     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1196
1197     QString jsonString(client->response);
1198     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1199
1200     QVariantMap body = value.value("body").toMap();
1201
1202     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1203     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(ONCOMPLETED_QMLFILE));
1204 }
1205
1206 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback()
1207 {
1208     int sourceLine = 48;
1209     QVERIFY(init(TIMER_QMLFILE));
1210
1211     client->connect();
1212
1213     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TIMER_QMLFILE), sourceLine, -1, true);
1214     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1215
1216     QString jsonString(client->response);
1217     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1218
1219     QVariantMap body = value.value("body").toMap();
1220
1221     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1222     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TIMER_QMLFILE));
1223 }
1224
1225 void tst_QDeclarativeDebugJS::setBreakpointInScriptInDifferentFile()
1226 {
1227     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1228
1229     int sourceLine = 43;
1230     QVERIFY(init(LOADJSFILE_QMLFILE));
1231
1232     client->connect();
1233     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_JSFILE), sourceLine, -1, true);
1234     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1235
1236     QString jsonString(client->response);
1237     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1238
1239     QVariantMap body = value.value("body").toMap();
1240
1241     QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
1242     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_JSFILE));
1243 }
1244
1245 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComment()
1246 {
1247     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1248
1249     int sourceLine = 47;
1250     int actualLine = 49;
1251     QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE));
1252
1253     client->connect();
1254     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true);
1255     QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort);
1256     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 1));
1257
1258     QString jsonString(client->response);
1259     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1260
1261     QVariantMap body = value.value("body").toMap();
1262
1263     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1264     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(BREAKPOINTRELOCATION_QMLFILE));
1265 }
1266
1267 void tst_QDeclarativeDebugJS::setBreakpointInScriptOnEmptyLine()
1268 {
1269     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1270
1271     int sourceLine = 48;
1272     int actualLine = 49;
1273     QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE));
1274
1275     client->connect();
1276     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true);
1277     QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort);
1278     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 1));
1279
1280     QString jsonString(client->response);
1281     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1282
1283     QVariantMap body = value.value("body").toMap();
1284
1285     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1286     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(BREAKPOINTRELOCATION_QMLFILE));
1287 }
1288
1289 void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition()
1290 {
1291     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1292
1293     int out = 10;
1294     int sourceLine = 50;
1295     QVERIFY(init(CONDITION_QMLFILE));
1296
1297     client->connect();
1298     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CONDITION_QMLFILE), sourceLine, 1, true, QLatin1String("a > 10"));
1299     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1300
1301     //Get the frame index
1302     QString jsonString = client->response;
1303     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1304
1305     QVariantMap body = value.value("body").toMap();
1306
1307     int frameIndex = body.value("index").toInt();
1308
1309     //Verify the value of 'result'
1310     client->evaluate(QLatin1String("a"),frameIndex);
1311
1312     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1313
1314     jsonString = client->response;
1315     value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1316
1317     body = value.value("body").toMap();
1318
1319     QVERIFY(body.value("value").toInt() > out);
1320 }
1321
1322 void tst_QDeclarativeDebugJS::setBreakpointWhenAttaching()
1323 {
1324     int sourceLine = 49;
1325     QVERIFY(init(QLatin1String(TIMER_QMLFILE), false));
1326
1327     client->connect();
1328     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TIMER_QMLFILE), sourceLine);
1329     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1330 }
1331
1332 //void tst_QDeclarativeDebugJS::setBreakpointInFunction()
1333 //{
1334 //    //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1335
1336 //    int actualLine = 31;
1337
1338 //    client->connect();
1339 //    client->setBreakpoint(QLatin1String(FUNCTION), QLatin1String("doSomethingElse"), -1, -1, true);
1340
1341 //    QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1342
1343 //    QString jsonString(client->response);
1344 //    QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1345
1346 //    QVariantMap body = value.value("body").toMap();
1347
1348 //    QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1349 //    QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE));
1350 //}
1351
1352 void tst_QDeclarativeDebugJS::setBreakpointOnEvent()
1353 {
1354     //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1355
1356     QVERIFY(init(TIMER_QMLFILE));
1357
1358     client->connect();
1359
1360     client->setBreakpoint(QLatin1String(EVENT), QLatin1String("triggered"), -1, -1, true);
1361     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1362
1363     QString jsonString(client->response);
1364     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1365
1366     QVariantMap body = value.value("body").toMap();
1367
1368     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TIMER_QMLFILE));
1369 }
1370
1371
1372 void tst_QDeclarativeDebugJS::changeBreakpoint()
1373 {
1374     //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1375
1376     int sourceLine1 = 50;
1377     int sourceLine2 = 51;
1378     QVERIFY(init(CHANGEBREAKPOINT_QMLFILE));
1379
1380     client->connect();
1381     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true);
1382     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true);
1383
1384     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1385
1386     //Will hit 1st brakpoint, change this breakpoint enable = false
1387     QString jsonString(client->response);
1388     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1389
1390     QVariantMap body = value.value("body").toMap();
1391     QList<QVariant> breakpointsHit = body.value("breakpoints").toList();
1392
1393     int breakpoint = breakpointsHit.at(0).toInt();
1394     client->changeBreakpoint(breakpoint,false);
1395
1396     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1397
1398     //Continue with debugging
1399     client->continueDebugging(QJSDebugClient::Continue);
1400     //Hit 2nd breakpoint
1401     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1402
1403     //Continue with debugging
1404     client->continueDebugging(QJSDebugClient::Continue);
1405     //Should stop at 2nd breakpoint
1406     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1407
1408     jsonString = client->response;
1409     value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1410
1411     body = value.value("body").toMap();
1412
1413     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1414 }
1415
1416 void tst_QDeclarativeDebugJS::changeBreakpointOnCondition()
1417 {
1418     //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1)
1419
1420     int sourceLine1 = 50;
1421     int sourceLine2 = 51;
1422
1423     QVERIFY(init(CHANGEBREAKPOINT_QMLFILE));
1424
1425     client->connect();
1426     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true);
1427     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true);
1428
1429     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1430
1431     //Will hit 1st brakpoint, change this breakpoint enable = false
1432     QString jsonString(client->response);
1433     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1434
1435     QVariantMap body = value.value("body").toMap();
1436     QList<QVariant> breakpointsHit = body.value("breakpoints").toList();
1437
1438     int breakpoint = breakpointsHit.at(0).toInt();
1439     client->changeBreakpoint(breakpoint, false, QLatin1String("d == 0"));
1440
1441     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1442
1443     //Continue with debugging
1444     client->continueDebugging(QJSDebugClient::Continue);
1445     //Hit 2nd breakpoint
1446     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1447
1448     //Continue with debugging
1449     client->continueDebugging(QJSDebugClient::Continue);
1450     //Should stop at 2nd breakpoint
1451     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1452
1453     jsonString = client->response;
1454     value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1455
1456     body = value.value("body").toMap();
1457
1458     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1459
1460 }
1461
1462 void tst_QDeclarativeDebugJS::clearBreakpoint()
1463 {
1464     //void clearBreakpoint(int breakpoint);
1465
1466     int sourceLine1 = 50;
1467     int sourceLine2 = 51;
1468     QVERIFY(init(CHANGEBREAKPOINT_QMLFILE));
1469
1470     client->connect();
1471     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true);
1472     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true);
1473
1474     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1475
1476     //Will hit 1st brakpoint, change this breakpoint enable = false
1477     QString jsonString(client->response);
1478     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1479
1480     QVariantMap body = value.value("body").toMap();
1481     QList<QVariant> breakpointsHit = body.value("breakpoints").toList();
1482
1483     int breakpoint = breakpointsHit.at(0).toInt();
1484     client->clearBreakpoint(breakpoint);
1485
1486     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1487
1488     //Continue with debugging
1489     client->continueDebugging(QJSDebugClient::Continue);
1490     //Hit 2nd breakpoint
1491     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1492
1493     //Continue with debugging
1494     client->continueDebugging(QJSDebugClient::Continue);
1495     //Should stop at 2nd breakpoint
1496     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1497
1498     jsonString = client->response;
1499     value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1500
1501     body = value.value("body").toMap();
1502
1503     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1504 }
1505
1506 void tst_QDeclarativeDebugJS::setExceptionBreak()
1507 {
1508     //void setExceptionBreak(QString type, bool enabled = false);
1509
1510     QVERIFY(init(EXCEPTION_QMLFILE));
1511     client->setExceptionBreak(QJSDebugClient::All,true);
1512     client->connect();
1513     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1514 }
1515
1516 void tst_QDeclarativeDebugJS::stepNext()
1517 {
1518     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1519
1520     int sourceLine = 50;
1521     QVERIFY(init(STEPACTION_QMLFILE));
1522
1523     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true);
1524     client->connect();
1525     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1526
1527     client->continueDebugging(QJSDebugClient::Next);
1528     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1529
1530     QString jsonString(client->response);
1531     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1532
1533     QVariantMap body = value.value("body").toMap();
1534
1535     QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 1);
1536     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1537 }
1538
1539 void tst_QDeclarativeDebugJS::stepNextWithCount()
1540 {
1541     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1542
1543     int sourceLine = 50;
1544     QVERIFY(init(STEPACTION_QMLFILE));
1545
1546     client->connect();
1547     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true);
1548     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1549
1550     client->continueDebugging(QJSDebugClient::Next, 2);
1551     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1552
1553     QString jsonString(client->response);
1554     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1555
1556     QVariantMap body = value.value("body").toMap();
1557
1558     QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 2);
1559     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1560 }
1561
1562 void tst_QDeclarativeDebugJS::stepIn()
1563 {
1564     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1565
1566     int sourceLine = 54;
1567     int actualLine = 50;
1568     QVERIFY(init(STEPACTION_QMLFILE));
1569
1570     client->connect();
1571     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, 1, true);
1572     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1573
1574     client->continueDebugging(QJSDebugClient::In);
1575     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1576
1577     QString jsonString(client->response);
1578     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1579
1580     QVariantMap body = value.value("body").toMap();
1581
1582     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1583     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1584 }
1585
1586 void tst_QDeclarativeDebugJS::stepOut()
1587 {
1588     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1589
1590     int sourceLine = 50;
1591     int actualLine = 54;
1592     QVERIFY(init(STEPACTION_QMLFILE));
1593
1594     client->connect();
1595     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true);
1596     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1597
1598     client->continueDebugging(QJSDebugClient::Out);
1599     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1600
1601     QString jsonString(client->response);
1602     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1603
1604     QVariantMap body = value.value("body").toMap();
1605
1606     QCOMPARE(body.value("sourceLine").toInt(), actualLine);
1607     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1608 }
1609
1610 void tst_QDeclarativeDebugJS::continueDebugging()
1611 {
1612     //void continueDebugging(StepAction stepAction, int stepCount = 1);
1613
1614     int sourceLine1 = 54;
1615     int sourceLine2 = 51;
1616     QVERIFY(init(STEPACTION_QMLFILE));
1617
1618     client->connect();
1619     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine1, -1, true);
1620     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine2, -1, true);
1621     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1622
1623     client->continueDebugging(QJSDebugClient::Continue);
1624     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1625
1626     QString jsonString(client->response);
1627     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1628
1629     QVariantMap body = value.value("body").toMap();
1630
1631     QCOMPARE(body.value("sourceLine").toInt(), sourceLine2);
1632     QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE));
1633 }
1634
1635 void tst_QDeclarativeDebugJS::backtrace()
1636 {
1637     //void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false);
1638
1639     int sourceLine = 47;
1640     QVERIFY(init(ONCOMPLETED_QMLFILE));
1641
1642     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1643     client->connect();
1644     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1645
1646     client->backtrace();
1647     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1648 }
1649
1650 void tst_QDeclarativeDebugJS::getFrameDetails()
1651 {
1652     //void frame(int number = -1);
1653
1654     int sourceLine = 47;
1655     QVERIFY(init(ONCOMPLETED_QMLFILE));
1656
1657     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1658     client->connect();
1659     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1660
1661     client->frame();
1662     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1663 }
1664
1665 void tst_QDeclarativeDebugJS::getScopeDetails()
1666 {
1667     //void scope(int number = -1, int frameNumber = -1);
1668
1669     int sourceLine = 47;
1670     QVERIFY(init(ONCOMPLETED_QMLFILE));
1671
1672     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1673     client->connect();
1674     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1675
1676     client->scope();
1677     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1678 }
1679
1680 void tst_QDeclarativeDebugJS::evaluateInGlobalScope()
1681 {
1682     //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
1683
1684     QVERIFY(init());
1685
1686     client->connect();
1687     client->evaluate(QLatin1String("print('Hello World')"), true);
1688     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1689
1690     //Verify the value of 'print'
1691     QString jsonString(client->response);
1692     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1693
1694     QVariantMap body = value.value("body").toMap();
1695
1696     QCOMPARE(body.value("text").toString(),QLatin1String("undefined"));
1697 }
1698
1699 void tst_QDeclarativeDebugJS::evaluateInLocalScope()
1700 {
1701     //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
1702
1703     int sourceLine = 47;
1704     QVERIFY(init(ONCOMPLETED_QMLFILE));
1705
1706     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1707     client->connect();
1708     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1709
1710     client->frame();
1711     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1712
1713     //Get the frame index
1714     QString jsonString(client->response);
1715     QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1716
1717     QVariantMap body = value.value("body").toMap();
1718
1719     int frameIndex = body.value("index").toInt();
1720
1721     client->evaluate(QLatin1String("root.a"), frameIndex);
1722     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1723
1724     //Verify the value of 'timer.interval'
1725     jsonString = client->response;
1726     value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
1727
1728     body = value.value("body").toMap();
1729
1730     QCOMPARE(body.value("value").toInt(),10);
1731 }
1732
1733 void tst_QDeclarativeDebugJS::getScopes()
1734 {
1735     //void scopes(int frameNumber = -1);
1736
1737     int sourceLine = 47;
1738     QVERIFY(init(ONCOMPLETED_QMLFILE));
1739
1740     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1741     client->connect();
1742     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1743
1744     client->scopes();
1745     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1746 }
1747
1748 void tst_QDeclarativeDebugJS::getScripts()
1749 {
1750     //void scripts(int types = -1, QList<int> ids = QList<int>(), bool includeSource = false, QVariant filter = QVariant());
1751
1752     QVERIFY(init());
1753
1754     client->connect();
1755
1756     client->scripts();
1757     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1758     QString jsonString(client->response);
1759     QVariantMap value = client->parser.call(QJSValue(),
1760                                             QJSValueList()
1761                                             << QJSValue(jsonString)).toVariant().toMap();
1762
1763     QList<QVariant> scripts = value.value("body").toList();
1764
1765     QCOMPARE(scripts.count(), 2);
1766 }
1767
1768 void tst_QDeclarativeDebugJS::getSource()
1769 {
1770     //void source(int frame = -1, int fromLine = -1, int toLine = -1);
1771
1772     int sourceLine = 47;
1773     QVERIFY(init(ONCOMPLETED_QMLFILE));
1774
1775     client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true);
1776     client->connect();
1777     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
1778
1779     client->source();
1780     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result())));
1781 }
1782
1783 QTEST_MAIN(tst_QDeclarativeDebugJS)
1784
1785 #include "tst_qdeclarativedebugjs.moc"
1786