~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

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