Commit ac121e1c0858ef6a290732c2d13284cb33c63e25
- Diff rendering mode:
- inline
- side by side
autotests/webpage/tst_webpage.cpp
(40 / 28)
|   | |||
| 287 | 287 | ||
| 288 | 288 | void tst_WebPage::linkedResources() | |
| 289 | 289 | { | |
| 290 | QLatin1String html("<html>" | ||
| 291 | " <head>" | ||
| 292 | " <link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\"/>" | ||
| 293 | " <link rel=\"alternate\" type=\"application/rss+xml\" href=\"rss1.xml\"/>" | ||
| 294 | " <link rel=\"alternate\" type=\"application/rss+xml\" href=\"rss2.xml\" title=\"Lorem Ipsum\"/>" | ||
| 295 | " <link rel=\"alternate\" type=\"application/atom+xml\" href=\"atom1.xml\"/>" | ||
| 296 | " </head>" | ||
| 297 | " <body>" | ||
| 298 | " <link rel=\"alternate\" type=\"application/atom+xml\" href=\"atom2.xml\"/>" | ||
| 299 | " </body>" | ||
| 300 | "</html>"); | ||
| 301 | |||
| 302 | 290 | SubWebPage page; | |
| 303 | page.mainFrame()->setHtml(QString(html)); | ||
| 304 | 291 | ||
| 305 | QList<WebPageLinkedResource> linkedResources = page.linkedResources(); | ||
| 306 | QCOMPARE(linkedResources.count(), 4); | ||
| 292 | QString html = "<html>" | ||
| 293 | "<head>" | ||
| 294 | "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/common.css\" />" | ||
| 295 | "<link rel=\"alternate\" type=\"application/rss+xml\" href=\"./rss.xml\" />" | ||
| 296 | "<link rel=\"alternate\" type=\"application/atom+xml\" href=\"../atom.xml\" title=\"Feed\" />" | ||
| 297 | "<link rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"http://external.foo/search.xml\" />" | ||
| 298 | "</head>" | ||
| 299 | "<body>" | ||
| 300 | "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/ie.css\" />" | ||
| 301 | "</body>" | ||
| 302 | "</html>"; | ||
| 307 | 303 | ||
| 308 | QCOMPARE(linkedResources.at(0).rel, QLatin1String("stylesheet")); | ||
| 309 | QCOMPARE(linkedResources.at(0).type, QLatin1String("text/css")); | ||
| 310 | QCOMPARE(linkedResources.at(0).href, QLatin1String("styles.css")); | ||
| 311 | QCOMPARE(linkedResources.at(0).title, QString()); | ||
| 304 | page.mainFrame()->setHtml(html, QUrl("http://foobar.baz/foo/")); | ||
| 312 | 305 | ||
| 313 | QCOMPARE(linkedResources.at(1).rel, QLatin1String("alternate")); | ||
| 314 | QCOMPARE(linkedResources.at(1).type, QLatin1String("application/rss+xml")); | ||
| 315 | QCOMPARE(linkedResources.at(1).href, QLatin1String("rss1.xml")); | ||
| 306 | QList<WebPageLinkedResource> resources = page.linkedResources(); | ||
| 307 | QCOMPARE(resources.count(), 4); | ||
| 316 | 308 | ||
| 317 | QCOMPARE(linkedResources.at(2).title, QLatin1String("Lorem Ipsum")); | ||
| 309 | QCOMPARE(resources.at(0).rel, QString("stylesheet")); | ||
| 310 | QCOMPARE(resources.at(0).type, QString("text/css")); | ||
| 311 | QCOMPARE(resources.at(0).href, QUrl("http://foobar.baz/foo/styles/common.css")); | ||
| 312 | QCOMPARE(resources.at(0).title, QString()); | ||
| 318 | 313 | ||
| 319 | QCOMPARE(linkedResources.at(3).type, QLatin1String("application/atom+xml")); | ||
| 314 | QCOMPARE(resources.at(1).rel, QString("alternate")); | ||
| 315 | QCOMPARE(resources.at(1).type, QString("application/rss+xml")); | ||
| 316 | QCOMPARE(resources.at(1).href, QUrl("http://foobar.baz/foo/rss.xml")); | ||
| 320 | 317 | ||
| 321 | QList<WebPageLinkedResource> linkedFeeds = page.linkedResources(QLatin1String("alternate")); | ||
| 322 | QCOMPARE(linkedFeeds.count(), 3); | ||
| 318 | QCOMPARE(resources.at(2).href, QUrl("http://foobar.baz/atom.xml")); | ||
| 319 | QCOMPARE(resources.at(2).title, QString("Feed")); | ||
| 323 | 320 | ||
| 324 | QCOMPARE(linkedFeeds.at(2).rel, QLatin1String("alternate")); | ||
| 325 | QCOMPARE(linkedFeeds.at(2).href, QLatin1String("atom1.xml")); | ||
| 321 | QCOMPARE(resources.at(3).rel, QString("search")); | ||
| 322 | QCOMPARE(resources.at(3).type, QString("application/opensearchdescription+xml")); | ||
| 323 | QCOMPARE(resources.at(3).href, QUrl("http://external.foo/search.xml")); | ||
| 324 | |||
| 325 | QString js = "var base = document.createElement('base');" | ||
| 326 | "base.setAttribute('href', 'http://barbaz.foo/bar/');" | ||
| 327 | "document.getElementsByTagName('head')[0].appendChild(base);"; | ||
| 328 | |||
| 329 | page.mainFrame()->evaluateJavaScript(js); | ||
| 330 | |||
| 331 | resources = page.linkedResources(); | ||
| 332 | QCOMPARE(resources.count(), 4); | ||
| 333 | |||
| 334 | QCOMPARE(resources.at(0).href, QUrl("http://barbaz.foo/bar/styles/common.css")); | ||
| 335 | QCOMPARE(resources.at(1).href, QUrl("http://barbaz.foo/bar/rss.xml")); | ||
| 336 | QCOMPARE(resources.at(2).href, QUrl("http://barbaz.foo/atom.xml")); | ||
| 337 | QCOMPARE(resources.at(3).href, QUrl("http://external.foo/search.xml")); | ||
| 326 | 338 | } | |
| 327 | 339 | ||
| 328 | 340 | QTEST_MAIN(tst_WebPage) |
src/toolbarsearch.cpp
(1 / 4)
|   | |||
| 307 | 307 | for (int i = 0; i < engines.count(); ++i) { | |
| 308 | 308 | WebPageLinkedResource engine = engines.at(i); | |
| 309 | 309 | ||
| 310 | QUrl url = QUrl(engine.href); | ||
| 310 | QUrl url = engine.href; | ||
| 311 | 311 | QString title = engine.title; | |
| 312 | 312 | QString mimetype = engine.type; | |
| 313 | 313 | ||
| … | … | ||
| 315 | 315 | continue; | |
| 316 | 316 | if (url.isEmpty()) | |
| 317 | 317 | continue; | |
| 318 | |||
| 319 | if (url.isRelative()) | ||
| 320 | url = webView->url().resolved(url); | ||
| 321 | 318 | ||
| 322 | 319 | if (title.isEmpty()) | |
| 323 | 320 | title = webView->title().isEmpty() ? url.host() : webView->title(); |
src/webpage.cpp
(7 / 2)
|   | |||
| 81 | 81 | QList<WebPageLinkedResource> resources; | |
| 82 | 82 | ||
| 83 | 83 | #if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK) | |
| 84 | QUrl baseUrl = mainFrame()->baseUrl(); | ||
| 85 | |||
| 84 | 86 | QList<QWebElement> linkElements = mainFrame()->findAllElements(QLatin1String("html > head > link")); | |
| 85 | 87 | ||
| 86 | 88 | foreach (const QWebElement &linkElement, linkElements) { | |
| … | … | ||
| 99 | 99 | WebPageLinkedResource resource; | |
| 100 | 100 | resource.rel = rel; | |
| 101 | 101 | resource.type = type; | |
| 102 | resource.href = href; | ||
| 102 | resource.href = baseUrl.resolved(QUrl::fromEncoded(href.toUtf8())); | ||
| 103 | 103 | resource.title = title; | |
| 104 | 104 | ||
| 105 | 105 | resources.append(resource); | |
| 106 | 106 | } | |
| 107 | 107 | #else | |
| 108 | QString baseUrlString = mainFrame()->evaluateJavaScript(QLatin1String("document.baseURI")).toString(); | ||
| 109 | QUrl baseUrl = QUrl::fromEncoded(baseUrlString.toUtf8()); | ||
| 110 | |||
| 108 | 111 | QFile file(QLatin1String(":fetchLinks.js")); | |
| 109 | 112 | if (!file.open(QFile::ReadOnly)) | |
| 110 | 113 | return resources; | |
| … | … | ||
| 129 | 129 | WebPageLinkedResource resource; | |
| 130 | 130 | resource.rel = rel; | |
| 131 | 131 | resource.type = type; | |
| 132 | resource.href = href; | ||
| 132 | resource.href = baseUrl.resolved(QUrl::fromEncoded(href.toUtf8())); | ||
| 133 | 133 | resource.title = title; | |
| 134 | 134 | ||
| 135 | 135 | resources.append(resource); |
src/webpage.h
(1 / 1)
|   | |||
| 30 | 30 | public: | |
| 31 | 31 | QString rel; | |
| 32 | 32 | QString type; | |
| 33 | QString href; | ||
| 33 | QUrl href; | ||
| 34 | 34 | QString title; | |
| 35 | 35 | }; | |
| 36 | 36 |

