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
|
import QtQuick 2.0
import QtTest 1.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0
import Test 1.0
import "../common"
TestWebView {
id: webView
width: 400
height: 300
experimental {
urlSchemeDelegates: [
UrlSchemeDelegate {
scheme: "applicationScheme"
onReceivedRequest: {
reply.data = "<html><head><title>Test Application Scheme</title></head><body>A test page.</body></html>"
reply.send()
}
},
UrlSchemeDelegate {
scheme: "scheme1"
onReceivedRequest: {
reply.data = "<html><head><title>Scheme1 Reply</title></head><body>A test page.</body></html>"
reply.send()
}
},
UrlSchemeDelegate {
scheme: "scheme2"
onReceivedRequest: {
reply.data = "<html><head><title>Scheme2 Reply</title></head><body>A test page.</body></html>"
reply.send()
}
},
UrlSchemeDelegate {
scheme: "scheme3"
onReceivedRequest: {
if (request.url == "scheme3://url1")
reply.data = "<html><head><title>Scheme3 Reply1</title></head><body>A test page.</body></html>"
else if (request.url == "scheme3://url2")
reply.data = "<html><head><title>Scheme3 Reply2</title></head><body>A test page.</body></html>"
else
reply.data = "<html><head><title>Should not happen</title></head><body>A test page.</body></html>"
reply.send()
}
},
UrlSchemeDelegate {
scheme: "schemeCharset"
onReceivedRequest: {
if (request.url == "schemecharset://latin1") {
reply.data = byteArrayHelper.latin1Data
reply.contentType = "text/html; charset=iso-8859-1"
} else if (request.url == "schemecharset://utf-8") {
reply.data = byteArrayHelper.utf8Data
reply.contentType = "text/html; charset=utf-8"
}
reply.send()
}
}
]
}
ByteArrayTestData {
id: byteArrayHelper
}
TestCase {
name: "WebViewApplicationSchemes"
function test_applicationScheme() {
var testUrl = "applicationScheme://something"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Test Application Scheme")
}
function test_multipleSchemes() {
// Test if we receive the right reply when defining multiple schemes.
var testUrl = "scheme2://some-url-string"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Scheme2 Reply")
testUrl = "scheme1://some-url-string"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Scheme1 Reply")
}
function test_multipleUrlsForScheme() {
var testUrl = "scheme3://url1"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Scheme3 Reply1")
testUrl = "scheme3://url2"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Scheme3 Reply2")
}
function test_charsets() {
var testUrl = "schemeCharset://latin1"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "title with copyright ©")
testUrl = "schemeCharset://utf-8"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "title with copyright ©")
}
function test_qrcScheme() {
var testUrl = "qrc:///common/qrctest.html"
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Loaded from qrc.")
}
}
}
|