Changeset 561 for trunk/src/3rdparty/webkit/WebKit/qt/tests/qwebpage
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/qwebpage.pro
r2 r561 3 3 include(../../../../WebKit.pri) 4 4 SOURCES += tst_qwebpage.cpp 5 5 6 QT += testlib network 6 7 QMAKE_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 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 3 4 4 5 This library is free software; you can redistribute it and/or … … 21 22 #include <QtTest/QtTest> 22 23 24 25 26 27 23 28 #include <qwebpage.h> 24 29 #include <qwidget.h> 30 25 31 #include <qwebview.h> 26 32 #include <qwebframe.h> … … 33 39 #include <qwebdatabase.h> 34 40 #include <QPushButton> 41 42 43 44 45 35 46 36 47 // Will try to wait for the condition while allowing event processing … … 60 71 * \p false on timeout 61 72 */ 62 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)73 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0) 63 74 { 64 75 QEventLoop loop; … … 75 86 } 76 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 77 104 class tst_QWebPage : public QObject 78 105 { … … 93 120 94 121 void acceptNavigationRequest(); 122 95 123 void loadFinished(); 96 124 void acceptNavigationRequestWithNewWindow(); … … 100 128 void database(); 101 129 void createPlugin(); 130 102 131 void destroyPlugin(); 132 103 133 void createViewlessPlugin(); 104 134 void multiplePageGroupsAndLocalStorage(); … … 106 136 void textSelection(); 107 137 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(); 111 157 112 158 private: … … 190 236 } 191 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 192 258 193 259 void tst_QWebPage::loadFinished() 194 260 { 261 262 195 263 QSignalSpy spyLoadStarted(m_view, SIGNAL(loadStarted())); 196 264 QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool))); … … 212 280 QTRY_COMPARE(spyLoadFinished.count(), 1); 213 281 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 214 307 } 215 308 … … 278 371 279 372 QList<QUrl> requestedUrls; 373 280 374 281 375 protected: 282 376 virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest &request, QIODevice* outgoingData) { 377 283 378 requestedUrls.append(request.url()); 284 379 return QNetworkAccessManager::createRequest(op, request, outgoingData); … … 292 387 networkManager->requestedUrls.clear(); 293 388 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())); 295 391 m_view->setHtml("<p>hello world</p>"); 296 392 QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); 297 393 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")); 301 396 } 302 397 … … 354 449 QVERIFY(m_page->history()->count() == 2); 355 450 m_page->mainFrame()->setUrl(QUrl("data:text/html,<body>This is fifth page")); 356 QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*, 451 QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)))); 357 452 } 358 453 … … 381 476 QVERIFY(QWebSettings::offlineStorageDefaultQuota() == 1024 * 1024); 382 477 478 479 480 383 481 QString dbFileName = path + "Databases.db"; 384 482 … … 387 485 388 486 qRegisterMetaType<QWebFrame*>("QWebFrame*"); 389 QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame *,QString)));487 QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrameQString))); 390 488 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")); 391 489 QTRY_COMPARE(spy.count(), 1); … … 408 506 QTest::qWait(200); 409 507 508 410 509 QWebSecurityOrigin origin = m_page->mainFrame()->securityOrigin(); 411 510 QList<QWebDatabase> dbs = origin.databases(); 412 if (dbs.count() > 0) {413 QString fileName = dbs[ 0].fileName();511 ) { 512 QString fileName = dbs[].fileName(); 414 513 QVERIFY(QFile::exists(fileName)); 415 QWebDatabase::removeDatabase(dbs[ 0]);514 QWebDatabase::removeDatabase(dbs[]); 416 515 QVERIFY(!QFile::exists(fileName)); 417 516 } 517 518 519 520 418 521 QTest::qWait(1000); 419 522 } … … 554 657 } 555 658 556 class PluginTrackedPage : public QWebPage 557 { 659 660 // Standard base class for template PluginTracerPage. In tests it is used as interface. 661 class PluginCounterPage : public QWebPage { 558 662 public: 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 { 564 672 settings()->setAttribute(QWebSettings::PluginsEnabled, true); 565 673 } 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(); 572 678 } 573 679 }; 574 680 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 575 734 void tst_QWebPage::destroyPlugin() 576 735 { 577 PluginTrackedPage* page = new PluginTrackedPage(m_view); 736 QFETCH(int, type); 737 PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type, m_view); 578 738 m_view->setPage(page); 579 739 … … 581 741 QString content("<html><body><object type=\"application/x-qt-plugin\" classid=\"QProgressBar\"></object></body></html>"); 582 742 m_view->setHtml(content); 583 QVERIFY(page-> widget != 0);584 QCOMPARE(page-> count, 1);743 QVERIFY(page->); 744 QCOMPARE(page->count, 1); 585 745 586 746 // navigate away, the plugin widget should be destructed 587 747 m_view->setHtml("<html><body>Hi</body></html>"); 588 748 QTestEventLoop::instance().enterLoop(1); 589 QVERIFY(page->widget == 0); 749 QVERIFY(!page->m_widget); 750 } 751 752 void tst_QWebPage::createViewlessPlugin_data() 753 { 754 PluginFactory::prepareTestData(); 590 755 } 591 756 592 757 void tst_QWebPage::createViewlessPlugin() 593 758 { 594 PluginTrackedPage* page = new PluginTrackedPage; 759 QFETCH(int, type); 760 PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type); 595 761 QString content("<html><body><object type=\"application/x-qt-plugin\" classid=\"QProgressBar\"></object></body></html>"); 596 762 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); 599 767 delete page; 768 600 769 } 601 770 … … 603 772 void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName); 604 773 QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page); 605 void QWEBKIT_EXPORT qt_websettings_setLocalStorageDatabasePath(QWebSettings* settings, const QString& path);606 774 607 775 void tst_QWebPage::multiplePageGroupsAndLocalStorage() … … 614 782 QWebView view2; 615 783 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")); 617 786 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")); 619 789 qt_webpage_setGroupName(view2.page(), "group2"); 620 790 QCOMPARE(qt_webpage_groupName(view1.page()), QString("group1")); … … 833 1003 page->triggerAction(QWebPage::MoveToStartOfBlock); 834 1004 QVERIFY(page->isSelectionCollapsed()); 835 QCOMPARE(page->selectionStartOffset(), 2);1005 QCOMPARE(page->selectionStartOffset(), ); 836 1006 837 1007 // cursor will be after the word "you!" … … 870 1040 "<p>May the source<br/>be with you!</p></body></html>"); 871 1041 page->mainFrame()->setHtml(content); 872 873 // this will select the first paragraph874 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"));880 1042 881 1043 // these actions must exist … … 894 1056 QVERIFY(page->action(QWebPage::SelectEndOfDocument) != 0); 895 1057 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 897 1060 QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), false); 898 1061 QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), false); … … 911 1074 QCOMPARE(page->action(QWebPage::SelectAll)->isEnabled(), true); 912 1075 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 918 1085 QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), true); 919 1086 QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), true); … … 929 1096 QCOMPARE(page->action(QWebPage::SelectEndOfDocument)->isEnabled(), true); 930 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 931 1120 delete page; 932 1121 } … … 940 1129 page->mainFrame()->setHtml(content); 941 1130 942 // this will select the first paragraph943 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 950 1131 // these actions must exist 1132 1133 1134 951 1135 QVERIFY(page->action(QWebPage::DeleteStartOfWord) != 0); 952 1136 QVERIFY(page->action(QWebPage::DeleteEndOfWord) != 0); … … 959 1143 QVERIFY(page->action(QWebPage::InsertParagraphSeparator) != 0); 960 1144 QVERIFY(page->action(QWebPage::InsertLineSeparator) != 0); 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 961 1158 962 1159 // right now they are disabled because contentEditable is false 1160 1161 963 1162 QCOMPARE(page->action(QWebPage::DeleteStartOfWord)->isEnabled(), false); 964 1163 QCOMPARE(page->action(QWebPage::DeleteEndOfWord)->isEnabled(), false); … … 971 1170 QCOMPARE(page->action(QWebPage::InsertParagraphSeparator)->isEnabled(), false); 972 1171 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 973 1191 974 1192 // make it editable before navigating the cursor 975 1193 page->setContentEditable(true); 976 1194 1195 1196 1197 1198 1199 1200 1201 1202 977 1203 // here the actions are enabled after contentEditable is true 1204 978 1205 QCOMPARE(page->action(QWebPage::DeleteStartOfWord)->isEnabled(), true); 979 1206 QCOMPARE(page->action(QWebPage::DeleteEndOfWord)->isEnabled(), true); … … 986 1213 QCOMPARE(page->action(QWebPage::InsertParagraphSeparator)->isEnabled(), true); 987 1214 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 988 1238 989 1239 delete page; 990 1240 } 991 1241 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 992 1783 993 1784 QTEST_MAIN(tst_QWebPage)
Note:
See TracChangeset
for help on using the changeset viewer.