summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
blob: f67c2e03d365dcdf9c9d282b621b8fbf977e1bfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*
    Copyright (C) 2008 Holger Hans Peter Freyther

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <QtTest/QtTest>
#include <QAction>

#include <util.h>
#include "qwebenginepage.h"
#include "qwebengineview.h"
#include "qwebenginehistory.h"
#include "qdebug.h"

class tst_QWebEngineHistory : public QObject
{
    Q_OBJECT

public:
    tst_QWebEngineHistory();
    virtual ~tst_QWebEngineHistory();

protected :
    void loadPage(int nr)
    {
        loadFinishedSpy->clear();
        page->load(QUrl("qrc:/resources/page" + QString::number(nr) + ".html"));
        QTRY_COMPARE(loadFinishedSpy->count(), 1);
        loadFinishedSpy->clear();
    }

public Q_SLOTS:
    void initTestCase();
    void init();
    void cleanup();

private Q_SLOTS:
    void title();
    void lastVisited();
    void iconUrl();
    void count();
    void back();
    void forward();
    void itemAt();
    void goToItem();
    void items();
    void backForwardItems();
    void serialize_1(); //QWebEngineHistory countity
    void serialize_2(); //QWebEngineHistory index
    void serialize_3(); //QWebEngineHistoryItem
    // Those tests shouldn't crash
    void saveAndRestore_crash_1();
    void saveAndRestore_crash_2();
    void saveAndRestore_crash_3();
    void saveAndRestore_crash_4();
    void saveAndRestore_InternalPage();

    void popPushState_data();
    void popPushState();
    void clear();
    void historyItemFromDeletedPage();
    void restoreIncompatibleVersion1();


private:
    QWebEnginePage* page;
    QWebEngineHistory* hist;
    QScopedPointer<QSignalSpy> loadFinishedSpy;
    int histsize;
};

tst_QWebEngineHistory::tst_QWebEngineHistory()
{
}

tst_QWebEngineHistory::~tst_QWebEngineHistory()
{
}

void tst_QWebEngineHistory::initTestCase()
{
}

void tst_QWebEngineHistory::init()
{
    page = new QWebEnginePage(this);
    loadFinishedSpy.reset(new QSignalSpy(page, SIGNAL(loadFinished(bool))));

    for (int i = 1;i < 6;i++) {
        loadPage(i);
    }
    hist = page->history();
    histsize = 5;
}

void tst_QWebEngineHistory::cleanup()
{
    loadFinishedSpy.reset();
    delete page;
}

/**
  * Check QWebEngineHistoryItem::title() method
  */
void tst_QWebEngineHistory::title()
{
    QTRY_COMPARE(hist->currentItem().title(), QString("page5"));
}

void tst_QWebEngineHistory::lastVisited()
{
    // Check that the conversion from Chromium's internal time format went well.
    QVERIFY(qAbs(hist->itemAt(0).lastVisited().secsTo(QDateTime::currentDateTime())) < 60);
}

void tst_QWebEngineHistory::iconUrl()
{
    QTRY_COMPARE(hist->currentItem().iconUrl(), QUrl("qrc:/qt-project.org/qmessagebox/images/qtlogo-64.png"));
}

/**
  * Check QWebEngineHistory::count() method
  */
void tst_QWebEngineHistory::count()
{
    QTRY_COMPARE(hist->count(), histsize);
}

/**
  * Check QWebEngineHistory::back() method
  */
void tst_QWebEngineHistory::back()
{
    QSignalSpy titleChangedSpy(page, SIGNAL(titleChanged(const QString&)));

    for (int i = histsize;i > 1;i--) {
        QTRY_COMPARE(toPlainTextSync(page), QString("page") + QString::number(i));
        hist->back();
        QTRY_COMPARE(loadFinishedSpy->count(), histsize-i+1);
        QTRY_COMPARE(titleChangedSpy.count(), histsize-i+1);
    }
    //try one more time (too many). crash test
    hist->back();
    QTRY_COMPARE(toPlainTextSync(page), QString("page1"));
}

/**
  * Check QWebEngineHistory::forward() method
  */
void tst_QWebEngineHistory::forward()
{
    //rewind history :-)
    int histBackCount = 0;
    while (hist->canGoBack()) {
        hist->back();
        histBackCount++;
        QTRY_COMPARE(loadFinishedSpy->count(), histBackCount);
    }

    QSignalSpy titleChangedSpy(page, SIGNAL(titleChanged(const QString&)));
    for (int i = 1;i < histsize;i++) {
        QTRY_COMPARE(toPlainTextSync(page), QString("page") + QString::number(i));
        hist->forward();
        QTRY_COMPARE(loadFinishedSpy->count(), i+histBackCount);
        QTRY_COMPARE(titleChangedSpy.count(), i);
    }
    //try one more time (too many). crash test
    hist->forward();
    QTRY_COMPARE(toPlainTextSync(page), QString("page") + QString::number(histsize));
}

/**
  * Check QWebEngineHistory::itemAt() method
  */
void tst_QWebEngineHistory::itemAt()
{
    for (int i = 1;i < histsize;i++) {
        QTRY_COMPARE(hist->itemAt(i - 1).title(), QString("page") + QString::number(i));
        QVERIFY(hist->itemAt(i - 1).isValid());
    }
    //check out of range values
    QVERIFY(!hist->itemAt(-1).isValid());
    QVERIFY(!hist->itemAt(histsize).isValid());
}

/**
  * Check QWebEngineHistory::goToItem() method
  */
void tst_QWebEngineHistory::goToItem()
{
    QWebEngineHistoryItem current = hist->currentItem();

    hist->back();
    QTRY_COMPARE(loadFinishedSpy->count(), 1);

    hist->back();
    QTRY_COMPARE(loadFinishedSpy->count(), 2);

    QVERIFY(hist->currentItem().title() != current.title());

    hist->goToItem(current);
    QTRY_COMPARE(loadFinishedSpy->count(), 2);

    QTRY_COMPARE(hist->currentItem().title(), current.title());
}

/**
  * Check QWebEngineHistory::items() method
  */
void tst_QWebEngineHistory::items()
{
    QList<QWebEngineHistoryItem> items = hist->items();
    //check count
    QTRY_COMPARE(histsize, items.count());

    //check order
    for (int i = 1;i <= histsize;i++) {
        QTRY_COMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
    }
}

void tst_QWebEngineHistory::backForwardItems()
{
    hist->back();
    QTRY_COMPARE(loadFinishedSpy->count(), 1);

    hist->back();
    QTRY_COMPARE(loadFinishedSpy->count(), 2);

    QTRY_COMPARE(hist->items().size(), 5);
    QTRY_COMPARE(hist->backItems(100).size(), 2);
    QTRY_COMPARE(hist->backItems(1).size(), 1);
    QTRY_COMPARE(hist->forwardItems(100).size(), 2);
    QTRY_COMPARE(hist->forwardItems(1).size(), 1);
}

/**
  * Check history state after serialization (pickle, persistent..) method
  * Checks history size, history order
  */
void tst_QWebEngineHistory::serialize_1()
{
    QByteArray tmp;  //buffer
    QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved
    QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded

    save << *hist;
    QVERIFY(save.status() == QDataStream::Ok);
    QTRY_COMPARE(hist->count(), histsize);

    //check size of history
    //load next page to find differences
    loadPage(6);
    QTRY_COMPARE(hist->count(), histsize + 1);
    load >> *hist;
    QVERIFY(load.status() == QDataStream::Ok);
    QTRY_COMPARE(hist->count(), histsize);

    //check order of historyItems
    QList<QWebEngineHistoryItem> items = hist->items();
    for (int i = 1;i <= histsize;i++) {
        QTRY_COMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
    }
}

/**
  * Check history state after serialization (pickle, persistent..) method
  * Checks history currentIndex value
  */
void tst_QWebEngineHistory::serialize_2()
{
    QByteArray tmp;  //buffer
    QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved
    QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded

    // Force a "same document" navigation.
    page->load(page->url().toString() + QLatin1String("#dummyAnchor"));
    // "same document" navigation doesn't trigger loadFinished signal.
    QTRY_COMPARE(evaluateJavaScriptSync(page, "location.hash").toString(), QStringLiteral("#dummyAnchor"));

    int initialCurrentIndex = hist->currentItemIndex();

    hist->back();
    QTRY_VERIFY(evaluateJavaScriptSync(page, "location.hash").toString().isEmpty());
    hist->back();
    QTRY_COMPARE(loadFinishedSpy->count(), 1);
    hist->back();
    QTRY_COMPARE(loadFinishedSpy->count(), 2);
    //check if current index was changed (make sure that it is not last item)
    QVERIFY(hist->currentItemIndex() != initialCurrentIndex);
    //save current index
    int oldCurrentIndex = hist->currentItemIndex();

    save << *hist;
    QVERIFY(save.status() == QDataStream::Ok);
    load >> *hist;
    QVERIFY(load.status() == QDataStream::Ok);
    // Restoring the history will trigger a load.
    QTRY_COMPARE(loadFinishedSpy->count(), 3);

    //check current index
    QTRY_COMPARE(hist->currentItemIndex(), oldCurrentIndex);

    hist->forward();
    QTRY_COMPARE(loadFinishedSpy->count(), 4);
    hist->forward();
    QTRY_COMPARE(loadFinishedSpy->count(), 5);
    hist->forward();
    // In-page navigation, the last url was the page5.html
    QTRY_COMPARE(loadFinishedSpy->count(), 5);
    QTRY_COMPARE(hist->currentItemIndex(), initialCurrentIndex);
}

/**
  * Check history state after serialization (pickle, persistent..) method
  * Checks QWebEngineHistoryItem public property after serialization
  */
void tst_QWebEngineHistory::serialize_3()
{
    QByteArray tmp;  //buffer
    QDataStream save(&tmp, QIODevice::WriteOnly); //here data will be saved
    QDataStream load(&tmp, QIODevice::ReadOnly); //from here data will be loaded

    //prepare two different history items
    QWebEngineHistoryItem a = hist->currentItem();

    //check properties BEFORE serialization
    QString title(a.title());
    QDateTime lastVisited(a.lastVisited());
    QUrl originalUrl(a.originalUrl());
    QUrl url(a.url());
    QUrl iconUrl(a.iconUrl());

    save << *hist;
    QVERIFY(save.status() == QDataStream::Ok);
    QVERIFY(!load.atEnd());
    hist->clear();
    QVERIFY(hist->count() == 1);
    load >> *hist;
    QVERIFY(load.status() == QDataStream::Ok);
    QWebEngineHistoryItem b = hist->currentItem();

    //check properties AFTER serialization
    QTRY_COMPARE(b.title(), title);
    QTRY_COMPARE(b.lastVisited(), lastVisited);
    QTRY_COMPARE(b.originalUrl(), originalUrl);
    QTRY_COMPARE(b.url(), url);
    QTRY_COMPARE(b.iconUrl(), iconUrl);

    //Check if all data was read
    QVERIFY(load.atEnd());
}

static void saveHistory(QWebEngineHistory* history, QByteArray* in)
{
    in->clear();
    QDataStream save(in, QIODevice::WriteOnly);
    save << *history;
}

static void restoreHistory(QWebEngineHistory* history, QByteArray* out)
{
    QDataStream load(out, QIODevice::ReadOnly);
    load >> *history;
}

void tst_QWebEngineHistory::saveAndRestore_crash_1()
{
    QByteArray buffer;
    saveHistory(hist, &buffer);
    for (unsigned i = 0; i < 5; i++) {
        restoreHistory(hist, &buffer);
        saveHistory(hist, &buffer);
    }
}

void tst_QWebEngineHistory::saveAndRestore_crash_2()
{
    QByteArray buffer;
    saveHistory(hist, &buffer);
    QWebEnginePage page2(this);
    QWebEngineHistory* hist2 = page2.history();
    for (unsigned i = 0; i < 5; i++) {
        restoreHistory(hist2, &buffer);
        saveHistory(hist2, &buffer);
    }
}

void tst_QWebEngineHistory::saveAndRestore_crash_3()
{
    QByteArray buffer;
    saveHistory(hist, &buffer);
    QWebEnginePage page2(this);
    QWebEngineHistory* hist1 = hist;
    QWebEngineHistory* hist2 = page2.history();
    for (unsigned i = 0; i < 5; i++) {
        restoreHistory(hist1, &buffer);
        restoreHistory(hist2, &buffer);
        QVERIFY(hist1->count() == hist2->count());
        QVERIFY(hist1->count() == histsize);
        hist2->back();
        saveHistory(hist2, &buffer);
        hist2->clear();
    }
}

void tst_QWebEngineHistory::saveAndRestore_crash_4()
{
    QByteArray buffer;
    saveHistory(hist, &buffer);

    QScopedPointer<QWebEnginePage> page2(new QWebEnginePage(this));

    // Load the history in a new page, waiting for the load to finish.
    QSignalSpy loadFinishedSpy2(page2.data(), SIGNAL(loadFinished(bool)));
    QDataStream load(&buffer, QIODevice::ReadOnly);
    load >> *page2->history();
    QTRY_COMPARE(loadFinishedSpy2.count(), 1);
}

void tst_QWebEngineHistory::saveAndRestore_InternalPage()
{
    QWebEngineView view;
    view.show();
    QSignalSpy loadFinishedSpy(&view, &QWebEngineView::loadFinished);
    view.load(QUrl("view-source:http://qt.io"));
    QTRY_LOOP_IMPL((loadFinishedSpy.size() == 1), 30000, 200)
    if (loadFinishedSpy.size() != 1 || !loadFinishedSpy.at(0).at(0).toBool())
         QSKIP("Couldn't load page from network, skipping test.");

    // get history
    QByteArray data;
    QDataStream stream1(&data, QIODevice::WriteOnly);
    stream1 << *view.history();

    // restore history - this should not crash. see QTBUG-57826
    QDataStream stream2(data);
    stream2 >> *view.history();
}

void tst_QWebEngineHistory::popPushState_data()
{
    QTest::addColumn<QString>("script");
    QTest::newRow("pushState") << "history.pushState(123, \"foo\");";
    QTest::newRow("replaceState") << "history.replaceState(\"a\", \"b\");";
    QTest::newRow("back") << "history.back();";
    QTest::newRow("forward") << "history.forward();";
}

/** Crash test, WebKit bug 38840 (https://bugs.webkit.org/show_bug.cgi?id=38840) */
void tst_QWebEngineHistory::popPushState()
{
    QFETCH(QString, script);
    QWebEnginePage page;
    QSignalSpy spyLoadFinished(&page, SIGNAL(loadFinished(bool)));
    page.setHtml("<html><body>long live Qt!</body></html>");
    QTRY_COMPARE(spyLoadFinished.count(), 1);
    evaluateJavaScriptSync(&page, script);
}

/** ::clear */
void tst_QWebEngineHistory::clear()
{
    QByteArray buffer;

    QAction* actionBack = page->action(QWebEnginePage::Back);
    QVERIFY(actionBack->isEnabled());
    saveHistory(hist, &buffer);
    QVERIFY(hist->count() > 1);
    hist->clear();
    QVERIFY(hist->count() == 1);  // Leave current item.
    QVERIFY(!actionBack->isEnabled());

    QWebEnginePage page2(this);
    QWebEngineHistory* hist2 = page2.history();
    QVERIFY(hist2->count() == 0);
    hist2->clear();
    QVERIFY(hist2->count() == 0); // Do not change anything.
}

void tst_QWebEngineHistory::historyItemFromDeletedPage()
{
    const QList<QWebEngineHistoryItem> items = page->history()->items();
    delete page;
    page = 0;

    for (const QWebEngineHistoryItem &item : items) {
        QVERIFY(!item.isValid());
        QTRY_COMPARE(item.originalUrl(), QUrl());
        QTRY_COMPARE(item.url(), QUrl());
        QTRY_COMPARE(item.title(), QString());
        QTRY_COMPARE(item.lastVisited(), QDateTime());
    }
}

// static void dumpCurrentVersion(QWebEngineHistory* history)
// {
//     QByteArray buffer;
//     saveHistory(history, &buffer);
//     printf("    static const char version1Dump[] = {");
//     for (int i = 0; i < buffer.size(); ++i) {
//         bool newLine = !(i % 15);
//         bool last = i == buffer.size() - 1;
//         printf("%s0x%.2x%s", newLine ? "\n        " : "", (unsigned char)buffer[i], last ? "" : ", ");
//     }
//     printf("};\n");
// }

void tst_QWebEngineHistory::restoreIncompatibleVersion1()
{
    // Uncomment this code to generate a dump similar to the one below with the current stream version.
    // dumpCurrentVersion(hist);
    static const unsigned char version1Dump[] = {
        0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
        0x32, 0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72, 0x00, 0x65,
        0x00, 0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00,
        0x2f, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x68,
        0x00, 0x74, 0x00, 0x6d, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x61, 0x00,
        0x67, 0x00, 0x65, 0x00, 0x31, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00,
        0x2f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63,
        0x00, 0x65, 0x00, 0x73, 0x00, 0x2f, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00,
        0x31, 0x00, 0x2e, 0x00, 0x68, 0x00, 0x74, 0x00, 0x6d, 0x00, 0x6c, 0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32,
        0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72, 0x00, 0x65, 0x00,
        0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x2f,
        0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x32, 0x00, 0x2e, 0x00, 0x68, 0x00,
        0x74, 0x00, 0x6d, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67,
        0x00, 0x65, 0x00, 0x32, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f,
        0x00, 0x72, 0x00, 0x65, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00,
        0x65, 0x00, 0x73, 0x00, 0x2f, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x32,
        0x00, 0x2e, 0x00, 0x68, 0x00, 0x74, 0x00, 0x6d, 0x00, 0x6c, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00,
        0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x73,
        0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x2f, 0x00,
        0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x33, 0x00, 0x2e, 0x00, 0x68, 0x00, 0x74,
        0x00, 0x6d, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00,
        0x65, 0x00, 0x33, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x32, 0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00,
        0x72, 0x00, 0x65, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65,
        0x00, 0x73, 0x00, 0x2f, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x33, 0x00,
        0x2e, 0x00, 0x68, 0x00, 0x74, 0x00, 0x6d, 0x00, 0x6c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
        0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x71,
        0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x73, 0x00,
        0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x2f, 0x00, 0x70,
        0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x34, 0x00, 0x2e, 0x00, 0x68, 0x00, 0x74, 0x00,
        0x6d, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65,
        0x00, 0x34, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x32, 0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72,
        0x00, 0x65, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00,
        0x73, 0x00, 0x2f, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x34, 0x00, 0x2e,
        0x00, 0x68, 0x00, 0x74, 0x00, 0x6d, 0x00, 0x6c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x71, 0x00,
        0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x73, 0x00, 0x6f,
        0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x2f, 0x00, 0x70, 0x00,
        0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x35, 0x00, 0x2e, 0x00, 0x68, 0x00, 0x74, 0x00, 0x6d,
        0x00, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00,
        0x35, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x32, 0x00, 0x71, 0x00, 0x72, 0x00, 0x63, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x72, 0x00,
        0x65, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x72, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73,
        0x00, 0x2f, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x35, 0x00, 0x2e, 0x00,
        0x68, 0x00, 0x74, 0x00, 0x6d, 0x00, 0x6c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    QByteArray version1(reinterpret_cast<const char*>(version1Dump), sizeof(version1Dump));
    QDataStream stream(&version1, QIODevice::ReadOnly);

    // This should fail to load, the history should be cleared and the stream should be broken.
    stream >> *hist;
    QEXPECT_FAIL("", "Behavior change: A broken stream won't clear the history in QtWebEngine.", Continue);
    QVERIFY(!hist->canGoBack());
    QVERIFY(!hist->canGoForward());
    QVERIFY(stream.status() == QDataStream::ReadCorruptData);
}

QTEST_MAIN(tst_QWebEngineHistory)
#include "tst_qwebenginehistory.moc"