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
|
import QtQuick 2.0
import QtTest 1.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0
import "../common"
Item {
TestWebView {
id: webView
width: 400
height: 300
experimental.preferences.javascriptEnabled: true
experimental.preferences.localStorageEnabled: true
experimental.preferences.pluginsEnabled: true
TestWebView {
id: webView2
width: 400
height: 300
}
SignalSpy {
id: titleSpy
target: webView
signalName: "titleChanged"
}
SignalSpy {
id: standardFontFamilySpy
target: webView.experimental.preferences
signalName: "standardFontFamilyChanged"
}
SignalSpy {
id: fixedFontFamilySpy
target: webView.experimental.preferences
signalName: "fixedFontFamilyChanged"
}
SignalSpy {
id: serifFontFamilySpy
target: webView.experimental.preferences
signalName: "serifFontFamilyChanged"
}
SignalSpy {
id: sansSerifFontFamilySpy
target: webView.experimental.preferences
signalName: "sansSerifFontFamilyChanged"
}
SignalSpy {
id: cursiveFontFamilySpy
target: webView.experimental.preferences
signalName: "cursiveFontFamilyChanged"
}
SignalSpy {
id: fantasyFontFamilySpy
target: webView.experimental.preferences
signalName: "fantasyFontFamilyChanged"
}
SignalSpy {
id: minimumFontSizeSpy
target: webView.experimental.preferences
signalName: "minimumFontSizeChanged"
}
SignalSpy {
id: defaultFontSizeSpy
target: webView.experimental.preferences
signalName: "defaultFontSizeChanged"
}
SignalSpy {
id: defaultFixedFontSizeSpy
target: webView.experimental.preferences
signalName: "defaultFixedFontSizeChanged"
}
TestCase {
name: "WebViewPreferences"
property bool shouldSetupFonts: true
property string defaultStandardFontFamily
property string defaultFixedFontFamily
property string defaultSerifFontFamily
property string defaultSansSerifFontFamily
property string defaultCursiveFontFamily
property string defaultFantasyFontFamily
property int defaultMinimumFontSize
property int defaultFontSize
property int defaultFixedFontSize
function init() {
if (shouldSetupFonts) {
// Setup initial values (may be different per platform).
shouldSetupFonts = false
defaultStandardFontFamily = webView.experimental.preferences.standardFontFamily
defaultFixedFontFamily = webView.experimental.preferences.fixedFontFamily
defaultSerifFontFamily = webView.experimental.preferences.serifFontFamily
defaultSansSerifFontFamily = webView.experimental.preferences.sansSerifFontFamily
defaultCursiveFontFamily = webView.experimental.preferences.cursiveFontFamily
defaultFantasyFontFamily = webView.experimental.preferences.fantasyFontFamily
defaultMinimumFontSize = webView.experimental.preferences.minimumFontSize
defaultFontSize = webView.experimental.preferences.defaultFontSize
defaultFixedFontSize = webView.experimental.preferences.defaultFixedFontSize
}
else {
// Restore default values before starting a new test case.
webView.experimental.preferences.standardFontFamily = defaultStandardFontFamily
webView.experimental.preferences.fixedFontFamily = defaultFixedFontFamily
webView.experimental.preferences.serifFontFamily = defaultSerifFontFamily
webView.experimental.preferences.sansSerifFontFamily = defaultSansSerifFontFamily
webView.experimental.preferences.cursiveFontFamily = defaultCursiveFontFamily
webView.experimental.preferences.fantasyFontFamily = defaultFantasyFontFamily
webView.experimental.preferences.minimumFontSize = defaultMinimumFontSize
webView.experimental.preferences.defaultFontSize = defaultFontSize
webView.experimental.preferences.defaultFixedFontSize = defaultFixedFontSize
if (webView.url != '' && webView.url != 'about:blank') {
webView.url = 'about:blank'
verify(webView.waitForLoadSucceeded())
}
standardFontFamilySpy.clear()
fixedFontFamilySpy.clear()
serifFontFamilySpy.clear()
sansSerifFontFamilySpy.clear()
cursiveFontFamilySpy.clear()
fantasyFontFamilySpy.clear()
minimumFontSizeSpy.clear()
defaultFontSizeSpy.clear()
defaultFixedFontSizeSpy.clear()
}
webView.experimental.preferences.javascriptEnabled = true
webView.experimental.preferences.localStorageEnabled = true
webView.experimental.preferences.pluginsEnabled = true
titleSpy.clear()
}
function test_javascriptEnabled() {
webView.experimental.preferences.javascriptEnabled = true
var testUrl = Qt.resolvedUrl("../common/javascript.html")
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "New Title")
}
function test_javascriptDisabled() {
webView.experimental.preferences.javascriptEnabled = false
var testUrl = Qt.resolvedUrl("../common/javascript.html")
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
}
function test_localStorageDisabled() {
webView.experimental.preferences.localStorageEnabled = false
var testUrl = Qt.resolvedUrl("../common/localStorage.html")
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
}
function test_localStorageEnabled() {
webView.experimental.preferences.localStorageEnabled = true
var testUrl = Qt.resolvedUrl("../common/localStorage.html")
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
compare(webView.title, "New Title")
}
function test_preferencesAffectCurrentViewOnly() {
webView.experimental.preferences.javascriptEnabled = true
webView2.experimental.preferences.javascriptEnabled = true
var testUrl = Qt.resolvedUrl("../common/javascript.html")
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
webView2.url = testUrl
verify(webView2.waitForLoadSucceeded())
compare(webView.title, "New Title")
compare(webView2.title, "New Title")
webView.experimental.preferences.javascriptEnabled = false
webView.url = testUrl
verify(webView.waitForLoadSucceeded())
webView2.url = testUrl
verify(webView2.waitForLoadSucceeded())
compare(webView.title, "Original Title")
compare(webView2.title, "New Title")
}
function unquote(text) {
return text[0] === "'" ? text.slice(1, -1) : text
}
function test_standardFontFamilyChanged() {
var url = Qt.resolvedUrl("../common/font-preferences.html?standard#font-family")
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(unquote(webView.title), defaultStandardFontFamily)
webView.experimental.preferences.standardFontFamily = "foobar"
standardFontFamilySpy.wait()
compare(standardFontFamilySpy.count, 1)
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, "foobar")
}
function test_fontSizeChanged() {
var url = Qt.resolvedUrl("../common/font-preferences.html?standard#font-size")
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, defaultFontSize.toString() + "px")
webView.experimental.preferences.defaultFontSize = defaultFontSize + 1
defaultFontSizeSpy.wait()
compare(defaultFontSizeSpy.count, 1)
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, (defaultFontSize + 1).toString() + "px")
}
function test_fixedFontSizeChanged() {
var url = Qt.resolvedUrl("../common/font-preferences.html?fixed#font-size")
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, defaultFixedFontSize.toString() + "px")
webView.experimental.preferences.defaultFixedFontSize = defaultFixedFontSize + 1
defaultFixedFontSizeSpy.wait()
compare(defaultFixedFontSizeSpy.count, 1)
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, (defaultFixedFontSize + 1).toString() + "px")
webView.url = Qt.resolvedUrl("../common/font-preferences.html?standard#font-size")
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, defaultFontSize.toString() + "px")
}
function test_minimumFontSizeChanged() {
verify(defaultMinimumFontSize < defaultFontSize)
var url = Qt.resolvedUrl("../common/font-preferences.html?minimum#font-size")
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
var smallerFontSize = webView.title
smallerFontSize = smallerFontSize.substring(0, smallerFontSize.length - 2)
smallerFontSize = parseInt(smallerFontSize)
verify(smallerFontSize < defaultFontSize)
webView.experimental.preferences.minimumFontSize = defaultFontSize
minimumFontSizeSpy.wait()
compare(minimumFontSizeSpy.count, 1)
webView.url = url
verify(webView.waitForLoadSucceeded())
compare(webView.title, "Original Title")
titleSpy.clear()
titleSpy.wait()
compare(webView.title, defaultFontSize.toString() + "px")
}
function test_defaultFontsChanged() {
// As there's currently no way to test through JS if a generic font was indeed changed
// we keep this test for really basic coverage.
webView.experimental.preferences.standardFontFamily = "foobar0"
standardFontFamilySpy.wait()
webView.experimental.preferences.fixedFontFamily = "foobar1"
fixedFontFamilySpy.wait()
webView.experimental.preferences.serifFontFamily = "foobar2"
serifFontFamilySpy.wait()
webView.experimental.preferences.sansSerifFontFamily = "foobar3"
sansSerifFontFamilySpy.wait()
webView.experimental.preferences.cursiveFontFamily = "foobar4"
cursiveFontFamilySpy.wait()
webView.experimental.preferences.fantasyFontFamily = "foobar5"
fantasyFontFamilySpy.wait()
compare(standardFontFamilySpy.count, 1)
compare(fixedFontFamilySpy.count, 1)
compare(serifFontFamilySpy.count, 1)
compare(sansSerifFontFamilySpy.count, 1)
compare(cursiveFontFamilySpy.count, 1)
compare(fantasyFontFamilySpy.count, 1)
compare(webView.experimental.preferences.standardFontFamily, "foobar0")
compare(webView.experimental.preferences.fixedFontFamily, "foobar1")
compare(webView.experimental.preferences.serifFontFamily, "foobar2")
compare(webView.experimental.preferences.sansSerifFontFamily, "foobar3")
compare(webView.experimental.preferences.cursiveFontFamily, "foobar4")
compare(webView.experimental.preferences.fantasyFontFamily, "foobar5")
}
}
}
}
|