Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
3 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/qwebpage.pro

    r2 r561  
    33include(../../../../WebKit.pri)
    44SOURCES  += tst_qwebpage.cpp
     5
    56QT += testlib network
    67QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
     8
     9
     10
     11
     12
     13
  • trunk/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

    r2 r561  
    11/*
    22    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     3
    34
    45    This library is free software; you can redistribute it and/or
     
    2122#include <QtTest/QtTest>
    2223
     24
     25
     26
     27
    2328#include <qwebpage.h>
    2429#include <qwidget.h>
     30
    2531#include <qwebview.h>
    2632#include <qwebframe.h>
     
    3339#include <qwebdatabase.h>
    3440#include <QPushButton>
     41
     42
     43
     44
     45
    3546
    3647// Will try to wait for the condition while allowing event processing
     
    6071 *         \p false on timeout
    6172 */
    62 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)
     73static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)
    6374{
    6475    QEventLoop loop;
     
    7586}
    7687
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
    77104class tst_QWebPage : public QObject
    78105{
     
    93120
    94121    void acceptNavigationRequest();
     122
    95123    void loadFinished();
    96124    void acceptNavigationRequestWithNewWindow();
     
    100128    void database();
    101129    void createPlugin();
     130
    102131    void destroyPlugin();
     132
    103133    void createViewlessPlugin();
    104134    void multiplePageGroupsAndLocalStorage();
     
    106136    void textSelection();
    107137    void textEditing();
    108 
    109 private:
    110 
     138    void backActionUpdate();
     139    void frameAt();
     140    void requestCache();
     141    void protectBindingsRuntimeObjectsFromCollector();
     142    void localURLSchemes();
     143    void testOptionalJSObjects();
     144    void testEnablePersistentStorage();
     145    void consoleOutput();
     146    void inputMethods_data();
     147    void inputMethods();
     148    void defaultTextEncoding();
     149    void errorPageExtension();
     150
     151    void crashTests_LazyInitializationOfMainFrame();
     152
     153    void screenshot_data();
     154    void screenshot();
     155
     156    void originatingObjectInNetworkRequests();
    111157
    112158private:
     
    190236}
    191237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
    192258
    193259void tst_QWebPage::loadFinished()
    194260{
     261
     262
    195263    QSignalSpy spyLoadStarted(m_view, SIGNAL(loadStarted()));
    196264    QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
     
    212280    QTRY_COMPARE(spyLoadFinished.count(), 1);
    213281    QCOMPARE(spyLoadFinished.count(), 1);
     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
    214307}
    215308
     
    278371
    279372    QList<QUrl> requestedUrls;
     373
    280374
    281375protected:
    282376    virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest &request, QIODevice* outgoingData) {
     377
    283378        requestedUrls.append(request.url());
    284379        return QNetworkAccessManager::createRequest(op, request, outgoingData);
     
    292387    networkManager->requestedUrls.clear();
    293388
    294     m_page->settings()->setUserStyleSheetUrl(QUrl("data:text/css,p { background-image: url('http://does.not/exist.png');}"));
     389    m_page->settings()->setUserStyleSheetUrl(QUrl("data:text/css;charset=utf-8;base64,"
     390            + QByteArray("p { background-image: url('http://does.not/exist.png');}").toBase64()));
    295391    m_view->setHtml("<p>hello world</p>");
    296392    QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
    297393
    298     QVERIFY(networkManager->requestedUrls.count() >= 2);
    299     QCOMPARE(networkManager->requestedUrls.at(0), QUrl("data:text/css,p { background-image: url('http://does.not/exist.png');}"));
    300     QCOMPARE(networkManager->requestedUrls.at(1), QUrl("http://does.not/exist.png"));
     394    QVERIFY(networkManager->requestedUrls.count() >= 1);
     395    QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
    301396}
    302397
     
    354449    QVERIFY(m_page->history()->count() == 2);
    355450    m_page->mainFrame()->setUrl(QUrl("data:text/html,<body>This is fifth page"));
    356     QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*, QWebHistoryItem*))));
     451    QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*))));
    357452}
    358453
     
    381476    QVERIFY(QWebSettings::offlineStorageDefaultQuota() == 1024 * 1024);
    382477
     478
     479
     480
    383481    QString dbFileName = path + "Databases.db";
    384482
     
    387485
    388486    qRegisterMetaType<QWebFrame*>("QWebFrame*");
    389     QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame *, QString)));
     487    QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrameQString)));
    390488    m_view->setHtml(QString("<html><head><script>var db; db=openDatabase('testdb', '1.0', 'test database API', 50000); </script></head><body><div></div></body></html>"), QUrl("http://www.myexample.com"));
    391489    QTRY_COMPARE(spy.count(), 1);
     
    408506    QTest::qWait(200);
    409507
     508
    410509    QWebSecurityOrigin origin = m_page->mainFrame()->securityOrigin();
    411510    QList<QWebDatabase> dbs = origin.databases();
    412     if (dbs.count() > 0) {
    413         QString fileName = dbs[0].fileName();
     511    ) {
     512        QString fileName = dbs[].fileName();
    414513        QVERIFY(QFile::exists(fileName));
    415         QWebDatabase::removeDatabase(dbs[0]);
     514        QWebDatabase::removeDatabase(dbs[]);
    416515        QVERIFY(!QFile::exists(fileName));
    417516    }
     517
     518
     519
     520
    418521    QTest::qWait(1000);
    419522}
     
    554657}
    555658
    556 class PluginTrackedPage : public QWebPage
    557 {
     659
     660// Standard base class for template PluginTracerPage. In tests it is used as interface.
     661class PluginCounterPage : public QWebPage {
    558662public:
    559 
    560     int count;
    561     QPointer<QWidget> widget;
    562 
    563     PluginTrackedPage(QWidget *parent = 0) : QWebPage(parent), count(0) {
     663    int m_count;
     664    QPointer<QObject> m_widget;
     665    QObject* m_pluginParent;
     666    PluginCounterPage(QObject* parent = 0)
     667        : QWebPage(parent)
     668        , m_count(0)
     669        , m_widget(0)
     670        , m_pluginParent(0)
     671    {
    564672       settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    565673    }
    566 
    567     virtual QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&) {
    568        count++;
    569        QWidget *w = new QWidget;
    570        widget = w;
    571        return w;
     674    ~PluginCounterPage()
     675    {
     676        if (m_pluginParent)
     677            m_pluginParent->deleteLater();
    572678    }
    573679};
    574680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
    575734void tst_QWebPage::destroyPlugin()
    576735{
    577     PluginTrackedPage* page = new PluginTrackedPage(m_view);
     736    QFETCH(int, type);
     737    PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type, m_view);
    578738    m_view->setPage(page);
    579739
     
    581741    QString content("<html><body><object type=\"application/x-qt-plugin\" classid=\"QProgressBar\"></object></body></html>");
    582742    m_view->setHtml(content);
    583     QVERIFY(page->widget != 0);
    584     QCOMPARE(page->count, 1);
     743    QVERIFY(page->);
     744    QCOMPARE(page->count, 1);
    585745
    586746    // navigate away, the plugin widget should be destructed
    587747    m_view->setHtml("<html><body>Hi</body></html>");
    588748    QTestEventLoop::instance().enterLoop(1);
    589     QVERIFY(page->widget == 0);
     749    QVERIFY(!page->m_widget);
     750}
     751
     752void tst_QWebPage::createViewlessPlugin_data()
     753{
     754    PluginFactory::prepareTestData();
    590755}
    591756
    592757void tst_QWebPage::createViewlessPlugin()
    593758{
    594     PluginTrackedPage* page = new PluginTrackedPage;
     759    QFETCH(int, type);
     760    PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type);
    595761    QString content("<html><body><object type=\"application/x-qt-plugin\" classid=\"QProgressBar\"></object></body></html>");
    596762    page->mainFrame()->setHtml(content);
    597     QCOMPARE(page->count, 1);
    598     QVERIFY(page->widget != 0);
     763    QCOMPARE(page->m_count, 1);
     764    QVERIFY(page->m_widget);
     765    QVERIFY(page->m_pluginParent);
     766    QVERIFY(page->m_widget->parent() == page->m_pluginParent);
    599767    delete page;
     768
    600769}
    601770
     
    603772void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName);
    604773QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page);
    605 void QWEBKIT_EXPORT qt_websettings_setLocalStorageDatabasePath(QWebSettings* settings, const QString& path);
    606774
    607775void tst_QWebPage::multiplePageGroupsAndLocalStorage()
     
    614782    QWebView view2;
    615783
    616     qt_websettings_setLocalStorageDatabasePath(view1.page()->settings(), QDir::toNativeSeparators(QDir::currentPath() + "/path1"));
     784    view1.page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
     785    view1.page()->settings()->setLocalStoragePath(QDir::toNativeSeparators(QDir::currentPath() + "/path1"));
    617786    qt_webpage_setGroupName(view1.page(), "group1");
    618     qt_websettings_setLocalStorageDatabasePath(view2.page()->settings(), QDir::toNativeSeparators(QDir::currentPath() + "/path2"));
     787    view2.page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);   
     788    view2.page()->settings()->setLocalStoragePath(QDir::toNativeSeparators(QDir::currentPath() + "/path2"));
    619789    qt_webpage_setGroupName(view2.page(), "group2");
    620790    QCOMPARE(qt_webpage_groupName(view1.page()), QString("group1"));
     
    8331003    page->triggerAction(QWebPage::MoveToStartOfBlock);
    8341004    QVERIFY(page->isSelectionCollapsed());
    835     QCOMPARE(page->selectionStartOffset(), 2);
     1005    QCOMPARE(page->selectionStartOffset(), );
    8361006
    8371007    // cursor will be after the word "you!"
     
    8701040        "<p>May the source<br/>be with you!</p></body></html>");
    8711041    page->mainFrame()->setHtml(content);
    872 
    873     // this will select the first paragraph
    874     QString script = "var range = document.createRange(); " \
    875         "var node = document.getElementById(\"one\"); " \
    876         "range.selectNode(node); " \
    877         "getSelection().addRange(range);";
    878     page->mainFrame()->evaluateJavaScript(script);
    879     QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox"));
    8801042
    8811043    // these actions must exist
     
    8941056    QVERIFY(page->action(QWebPage::SelectEndOfDocument) != 0);
    8951057
    896     // right now they are disabled because contentEditable is false
     1058    // right now they are disabled because contentEditable is false and
     1059    // there isn't an existing selection to modify
    8971060    QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), false);
    8981061    QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), false);
     
    9111074    QCOMPARE(page->action(QWebPage::SelectAll)->isEnabled(), true);
    9121075
    913     // make it editable before navigating the cursor
    914     page->setContentEditable(true);
    915 
    916     // here the actions are enabled after contentEditable is true
    917     QCOMPARE(page->action(QWebPage::SelectAll)->isEnabled(), true);
     1076    // this will select the first paragraph
     1077    QString selectScript = "var range = document.createRange(); " \
     1078        "var node = document.getElementById(\"one\"); " \
     1079        "range.selectNode(node); " \
     1080        "getSelection().addRange(range);";
     1081    page->mainFrame()->evaluateJavaScript(selectScript);
     1082    QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox"));
     1083
     1084    // here the actions are enabled after a selection has been created
    9181085    QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), true);
    9191086    QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), true);
     
    9291096    QCOMPARE(page->action(QWebPage::SelectEndOfDocument)->isEnabled(), true);
    9301097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
     1113
     1114
     1115
     1116
     1117
     1118
     1119
    9311120    delete page;
    9321121}
     
    9401129    page->mainFrame()->setHtml(content);
    9411130
    942     // this will select the first paragraph
    943     QString script = "var range = document.createRange(); " \
    944         "var node = document.getElementById(\"one\"); " \
    945         "range.selectNode(node); " \
    946         "getSelection().addRange(range);";
    947     page->mainFrame()->evaluateJavaScript(script);
    948     QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox"));
    949 
    9501131    // these actions must exist
     1132
     1133
     1134
    9511135    QVERIFY(page->action(QWebPage::DeleteStartOfWord) != 0);
    9521136    QVERIFY(page->action(QWebPage::DeleteEndOfWord) != 0);
     
    9591143    QVERIFY(page->action(QWebPage::InsertParagraphSeparator) != 0);
    9601144    QVERIFY(page->action(QWebPage::InsertLineSeparator) != 0);
     1145
     1146
     1147
     1148
     1149
     1150
     1151
     1152
     1153
     1154
     1155
     1156
     1157
    9611158
    9621159    // right now they are disabled because contentEditable is false
     1160
     1161
    9631162    QCOMPARE(page->action(QWebPage::DeleteStartOfWord)->isEnabled(), false);
    9641163    QCOMPARE(page->action(QWebPage::DeleteEndOfWord)->isEnabled(), false);
     
    9711170    QCOMPARE(page->action(QWebPage::InsertParagraphSeparator)->isEnabled(), false);
    9721171    QCOMPARE(page->action(QWebPage::InsertLineSeparator)->isEnabled(), false);
     1172
     1173
     1174
     1175
     1176
     1177
     1178
     1179
     1180
     1181
     1182
     1183
     1184
     1185
     1186
     1187
     1188
     1189
     1190
    9731191
    9741192    // make it editable before navigating the cursor
    9751193    page->setContentEditable(true);
    9761194
     1195
     1196
     1197
     1198
     1199
     1200
     1201
     1202
    9771203    // here the actions are enabled after contentEditable is true
     1204
    9781205    QCOMPARE(page->action(QWebPage::DeleteStartOfWord)->isEnabled(), true);
    9791206    QCOMPARE(page->action(QWebPage::DeleteEndOfWord)->isEnabled(), true);
     
    9861213    QCOMPARE(page->action(QWebPage::InsertParagraphSeparator)->isEnabled(), true);
    9871214    QCOMPARE(page->action(QWebPage::InsertLineSeparator)->isEnabled(), true);
     1215
     1216
     1217
     1218
     1219
     1220
     1221
     1222
     1223
     1224
     1225
     1226
     1227
     1228
     1229
     1230
     1231
     1232
     1233
     1234
     1235
     1236
     1237
    9881238
    9891239    delete page;
    9901240}
    9911241
     1242
     1243
     1244
     1245
     1246
     1247
     1248
     1249
     1250
     1251
     1252
     1253
     1254
     1255
     1256
     1257
     1258
     1259
     1260
     1261
     1262
     1263
     1264
     1265
     1266
     1267
     1268
     1269
     1270
     1271
     1272
     1273
     1274
     1275
     1276
     1277
     1278
     1279
     1280
     1281
     1282
     1283
     1284
     1285
     1286
     1287
     1288
     1289
     1290
     1291
     1292
     1293
     1294
     1295
     1296
     1297
     1298
     1299
     1300
     1301
     1302
     1303
     1304
     1305
     1306
     1307
     1308
     1309
     1310
     1311
     1312
     1313
     1314
     1315
     1316
     1317
     1318
     1319
     1320
     1321
     1322
     1323
     1324
     1325
     1326
     1327
     1328
     1329
     1330
     1331
     1332
     1333
     1334
     1335
     1336
     1337
     1338
     1339
     1340
     1341
     1342
     1343
     1344
     1345
     1346
     1347
     1348
     1349
     1350
     1351
     1352
     1353
     1354
     1355
     1356
     1357
     1358
     1359
     1360
     1361
     1362
     1363
     1364
     1365
     1366
     1367
     1368
     1369
     1370
     1371
     1372
     1373
     1374
     1375
     1376
     1377
     1378
     1379
     1380
     1381
     1382
     1383
     1384
     1385
     1386
     1387
     1388
     1389
     1390
     1391
     1392
     1393
     1394
     1395
     1396
     1397
     1398
     1399
     1400
     1401
     1402
     1403
     1404
     1405
     1406
     1407
     1408
     1409
     1410
     1411
     1412
     1413
     1414
     1415
     1416
     1417
     1418
     1419
     1420
     1421
     1422
     1423
     1424
     1425
     1426
     1427
     1428
     1429
     1430
     1431
     1432
     1433
     1434
     1435
     1436
     1437
     1438
     1439
     1440
     1441
     1442
     1443
     1444
     1445
     1446
     1447
     1448
     1449
     1450
     1451
     1452
     1453
     1454
     1455
     1456
     1457
     1458
     1459
     1460
     1461
     1462
     1463
     1464
     1465
     1466
     1467
     1468
     1469
     1470
     1471
     1472
     1473
     1474
     1475
     1476
     1477
     1478
     1479
     1480
     1481
     1482
     1483
     1484
     1485
     1486
     1487
     1488
     1489
     1490
     1491
     1492
     1493
     1494
     1495
     1496
     1497
     1498
     1499
     1500
     1501
     1502
     1503
     1504
     1505
     1506
     1507
     1508
     1509
     1510
     1511
     1512
     1513
     1514
     1515
     1516
     1517
     1518
     1519
     1520
     1521
     1522
     1523
     1524
     1525
     1526
     1527
     1528
     1529
     1530
     1531
     1532
     1533
     1534
     1535
     1536
     1537
     1538
     1539
     1540
     1541
     1542
     1543
     1544
     1545
     1546
     1547
     1548
     1549
     1550
     1551
     1552
     1553
     1554
     1555
     1556
     1557
     1558
     1559
     1560
     1561
     1562
     1563
     1564
     1565
     1566
     1567
     1568
     1569
     1570
     1571
     1572
     1573
     1574
     1575
     1576
     1577
     1578
     1579
     1580
     1581
     1582
     1583
     1584
     1585
     1586
     1587
     1588
     1589
     1590
     1591
     1592
     1593
     1594
     1595
     1596
     1597
     1598
     1599
     1600
     1601
     1602
     1603
     1604
     1605
     1606
     1607
     1608
     1609
     1610
     1611
     1612
     1613
     1614
     1615
     1616
     1617
     1618
     1619
     1620
     1621
     1622
     1623
     1624
     1625
     1626
     1627
     1628
     1629
     1630
     1631
     1632
     1633
     1634
     1635
     1636
     1637
     1638
     1639
     1640
     1641
     1642
     1643
     1644
     1645
     1646
     1647
     1648
     1649
     1650
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
     1662
     1663
     1664
     1665
     1666
     1667
     1668
     1669
     1670
     1671
     1672
     1673
     1674
     1675
     1676
     1677
     1678
     1679
     1680
     1681
     1682
     1683
     1684
     1685
     1686
     1687
     1688
     1689
     1690
     1691
     1692
     1693
     1694
     1695
     1696
     1697
     1698
     1699
     1700
     1701
     1702
     1703
     1704
     1705
     1706
     1707
     1708
     1709
     1710
     1711
     1712
     1713
     1714
     1715
     1716
     1717
     1718
     1719
     1720
     1721
     1722
     1723
     1724
     1725
     1726
     1727
     1728
     1729
     1730
     1731
     1732
     1733
     1734
     1735
     1736
     1737
     1738
     1739
     1740
     1741
     1742
     1743
     1744
     1745
     1746
     1747
     1748
     1749
     1750
     1751
     1752
     1753
     1754
     1755
     1756
     1757
     1758
     1759
     1760
     1761
     1762
     1763
     1764
     1765
     1766
     1767
     1768
     1769
     1770
     1771
     1772
     1773
     1774
     1775
     1776
     1777
     1778
     1779
     1780
     1781
     1782
    9921783
    9931784QTEST_MAIN(tst_QWebPage)
Note: See TracChangeset for help on using the changeset viewer.