Modified: trunk/Source/WebKit2/ChangeLog (104566 => 104567)
--- trunk/Source/WebKit2/ChangeLog 2012-01-10 15:01:07 UTC (rev 104566)
+++ trunk/Source/WebKit2/ChangeLog 2012-01-10 15:14:05 UTC (rev 104567)
@@ -1,3 +1,13 @@
+2012-01-10 Rafael Brandao <[email protected]>
+
+ [Qt][WK2] Add font-related API tests for QWebPreferences
+ https://bugs.webkit.org/show_bug.cgi?id=75739
+
+ Reviewed by Zoltan Herczeg.
+
+ * UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml:
+ * UIProcess/API/qt/tests/qmltests/common/font-preferences.html: Added.
+
2012-01-10 Simon Hausmann <[email protected]>
[Qt] Fix failing WK2 layout tests after r104557
Modified: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml (104566 => 104567)
--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml 2012-01-10 15:01:07 UTC (rev 104566)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_preferences.qml 2012-01-10 15:14:05 UTC (rev 104567)
@@ -26,6 +26,66 @@
}
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"
+ }
+
+ SignalSpy {
id: otherSpy
target: webView2
signalName: "loadSucceeded"
@@ -34,11 +94,65 @@
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') {
+ spy.clear()
+ webView.load('about:blank')
+ spy.wait()
+ }
+
+ standardFontFamilySpy.clear()
+ fixedFontFamilySpy.clear()
+ serifFontFamilySpy.clear()
+ sansSerifFontFamilySpy.clear()
+ cursiveFontFamilySpy.clear()
+ fantasyFontFamilySpy.clear()
+ minimumFontSizeSpy.clear()
+ defaultFontSizeSpy.clear()
+ defaultFixedFontSizeSpy.clear()
+ }
+
webView.experimental.preferences._javascript_Enabled = true
webView.experimental.preferences.localStorageEnabled = true
webView.experimental.preferences.pluginsEnabled = true
spy.clear()
+ titleSpy.clear()
}
function test_javascriptEnabled() {
@@ -96,6 +210,122 @@
compare(webView.title, "Original Title")
compare(webView2.title, "New Title")
}
+
+ function test_standardFontFamilyChanged() {
+ var url = ""
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, defaultStandardFontFamily)
+
+ webView.experimental.preferences.standardFontFamily = "foobar"
+ standardFontFamilySpy.wait()
+ compare(standardFontFamilySpy.count, 1)
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, "foobar")
+ }
+
+ function test_fontSizeChanged() {
+ var url = ""
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, defaultFontSize.toString() + "px")
+
+ webView.experimental.preferences.defaultFontSize = defaultFontSize + 1
+ defaultFontSizeSpy.wait()
+ compare(defaultFontSizeSpy.count, 1)
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, (defaultFontSize + 1).toString() + "px")
+ }
+
+ function test_fixedFontSizeChanged() {
+ var url = ""
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, defaultFixedFontSize.toString() + "px")
+
+ webView.experimental.preferences.defaultFixedFontSize = defaultFixedFontSize + 1
+ defaultFixedFontSizeSpy.wait()
+ compare(defaultFixedFontSizeSpy.count, 1)
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, (defaultFixedFontSize + 1).toString() + "px")
+
+ webView.load(Qt.resolvedUrl("../common/font-preferences.html?standard#font-size"))
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ titleSpy.wait()
+ compare(webView.title, defaultFontSize.toString() + "px")
+ }
+
+ function test_minimumFontSizeChanged() {
+ verify(defaultMinimumFontSize < defaultFontSize)
+ var url = ""
+ webView.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ 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.load(url)
+ titleSpy.wait()
+ compare(webView.title, "Original Title")
+ 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")
+ }
+
+
}
}
}
Added: trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/font-preferences.html (0 => 104567)
--- trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/font-preferences.html (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/font-preferences.html 2012-01-10 15:14:05 UTC (rev 104567)
@@ -0,0 +1,31 @@
+<html>
+<head>
+<title>Original Title</title>
+</head>
+<script type="text/_javascript_">
+function getTestId() {
+ url = ""
+ var i, j = 0;
+ for (i = url.length - 1; i >= 0; --i) {
+ if (url[i] == '?')
+ break
+ else if (url[i] == '#')
+ j = i - 1
+ }
+ return url.substr(i + 1, j - i)
+}
+
+function getStyleForId(id, styleProp) {
+ return document.defaultView.getComputedStyle(document.getElementById(id), null).getPropertyValue(styleProp);
+}
+
+function changeTitle() {
+ document.title = getStyleForId(getTestId(), window.location.hash.substr(1))
+}
+</script>
+<body _onload_='setTimeout("changeTitle()", 100)'>
+<p id="standard">hello</p>
+<code id="fixed">hello</code>
+<p id="minimum" style="font-size: smaller">hello</p>
+</body>
+</html>