Diff
Modified: trunk/Source/WebKit2/ChangeLog (148787 => 148788)
--- trunk/Source/WebKit2/ChangeLog 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Source/WebKit2/ChangeLog 2013-04-20 08:23:19 UTC (rev 148788)
@@ -1,3 +1,34 @@
+2013-04-20 Manuel Rego Casasnovas <[email protected]>
+
+ [GTK] Fix unit test webkit2/WebKitFindController/hide
+ https://bugs.webkit.org/show_bug.cgi?id=89810
+
+ Reviewed by Carlos Garcia Campos.
+
+ The test had some hacks in order to compare a page with highlighted
+ results after using the find command with the original page. Now it uses
+ the snapshots API that allows to make the test simpler and more
+ reliable.
+
+ * UIProcess/API/gtk/tests/TestMain.h:
+ (Test::cairoSurfacesEqual): Moved helper function to compare two cairo
+ surfaces from TestWebKitWebView.
+ (Test):
+ * UIProcess/API/gtk/tests/TestWebKitFindController.cpp:
+ (testFindControllerHide): Modify test to use snapshots.
+ * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
+ (testWebViewSnapshot): Move basic snapshop methods to WebViewTest to
+ share them with TestWebKitFindController test.
+ * UIProcess/API/gtk/tests/WebViewTest.cpp:
+ (WebViewTest::WebViewTest): Initialize cairo surface.
+ (WebViewTest::~WebViewTest): Destroy cairo surface.
+ (onSnapshotReady): Callback to set the cairo surface when the snapshot
+ is ready.
+ (WebViewTest::getSnapshotAndWaitUntilReady): Method that takes a
+ snapshot and returns the cairo surface when it is ready.
+ * UIProcess/API/gtk/tests/WebViewTest.h: Add new method headers and
+ attribute for the cairo surface.
+
2013-04-19 Jer Noble <[email protected]>
Unreviewed, revert r148782. It was not reviewed by a WebKit2 owner.
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h (148787 => 148788)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h 2013-04-20 08:23:19 UTC (rev 148788)
@@ -20,6 +20,7 @@
#ifndef TestMain_h
#define TestMain_h
+#include <cairo.h>
#include <glib-object.h>
#include <wtf/HashSet.h>
#include <wtf/gobject/GOwnPtr.h>
@@ -101,6 +102,17 @@
g_log_set_always_fatal(static_cast<GLogLevelFlags>(fatalMask));
}
+ static bool cairoSurfacesEqual(cairo_surface_t* s1, cairo_surface_t* s2)
+ {
+ return (cairo_image_surface_get_format(s1) == cairo_image_surface_get_format(s2)
+ && cairo_image_surface_get_width(s1) == cairo_image_surface_get_width(s2)
+ && cairo_image_surface_get_height(s1) == cairo_image_surface_get_height(s2)
+ && cairo_image_surface_get_stride(s1) == cairo_image_surface_get_stride(s2)
+ && !memcmp(const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s1))),
+ const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s2))),
+ cairo_image_surface_get_height(s1)*cairo_image_surface_get_stride(s1)));
+ }
+
HashSet<GObject*> m_watchedObjects;
};
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp (148787 => 148788)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp 2013-04-20 08:23:19 UTC (rev 148788)
@@ -62,12 +62,6 @@
g_main_loop_run(m_mainLoop);
}
- void waitUntilWebViewDrawSignal()
- {
- g_signal_connect_after(m_webView, "draw", G_CALLBACK(webViewDraw), this);
- g_main_loop_run(m_mainLoop);
- }
-
GRefPtr<WebKitFindController> m_findController;
bool m_textFound;
unsigned m_matchCount;
@@ -75,12 +69,6 @@
private:
bool m_runFindUntilCompletion;
- static void webViewDraw(GtkWidget *widget, cairo_t *cr, FindControllerTest* test)
- {
- g_main_loop_quit(test->m_mainLoop);
- g_signal_handlers_disconnect_matched(widget, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, test);
- }
-
static void foundTextCallback(WebKitFindController*, guint matchCount, FindControllerTest* test)
{
test->m_textFound = true;
@@ -271,67 +259,38 @@
g_assert(test->m_textFound);
}
-static gboolean gdkPixbufEqual(GdkPixbuf* firstPixbuf, GdkPixbuf* secondPixbuf)
-{
- if (gdk_pixbuf_get_bits_per_sample(firstPixbuf) != gdk_pixbuf_get_bits_per_sample(secondPixbuf)
- || gdk_pixbuf_get_has_alpha(firstPixbuf) != gdk_pixbuf_get_has_alpha(secondPixbuf)
- || gdk_pixbuf_get_height(firstPixbuf) != gdk_pixbuf_get_height(secondPixbuf)
- || gdk_pixbuf_get_n_channels(firstPixbuf) != gdk_pixbuf_get_n_channels(secondPixbuf)
- || gdk_pixbuf_get_rowstride(firstPixbuf) != gdk_pixbuf_get_rowstride(secondPixbuf)
- || gdk_pixbuf_get_width(firstPixbuf) != gdk_pixbuf_get_width(secondPixbuf))
- return FALSE;
-
- int pixbufRowstride = gdk_pixbuf_get_rowstride(firstPixbuf);
- int pixbufHeight = gdk_pixbuf_get_height(firstPixbuf);
- int pixbufWidth = gdk_pixbuf_get_width(firstPixbuf);
- int numberOfChannels = gdk_pixbuf_get_n_channels(firstPixbuf);
- int bitsPerSample = gdk_pixbuf_get_bits_per_sample(firstPixbuf);
-
- // Last row can be of different length. Taken from gdk-pixbuf documentation.
- int totalLength = (pixbufHeight - 1) * pixbufRowstride \
- + pixbufWidth * ((numberOfChannels * bitsPerSample + 7) / 8);
-
- guchar* firstPixels = gdk_pixbuf_get_pixels(firstPixbuf);
- guchar* secondPixels = gdk_pixbuf_get_pixels(secondPixbuf);
- for (int i = 0; i < totalLength; i++)
- if (firstPixels[i] != secondPixels[i])
- return FALSE;
-
- return TRUE;
-}
-
static void testFindControllerHide(FindControllerTest* test, gconstpointer)
{
test->loadHtml(testString, 0);
test->waitUntilLoadFinished();
test->showInWindowAndWaitUntilMapped();
- int allocatedHeight = gtk_widget_get_allocated_height(GTK_WIDGET(test->m_webView));
- int allocatedWidth = gtk_widget_get_allocated_width(GTK_WIDGET(test->m_webView));
- GdkWindow* webViewGdkWindow = gtk_widget_get_window(GTK_WIDGET(test->m_webView));
- g_assert(webViewGdkWindow);
- test->waitUntilWebViewDrawSignal();
- GRefPtr<GdkPixbuf> originalPixbuf = adoptGRef(gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth));
- g_assert(originalPixbuf);
+ cairo_surface_t* originalSurface = cairo_surface_reference(
+ test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(originalSurface);
test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1);
test->waitUntilFindFinished();
g_assert(test->m_textFound);
- test->waitUntilWebViewDrawSignal();
- GRefPtr<GdkPixbuf> highlightPixbuf = adoptGRef(gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth));
- g_assert(highlightPixbuf);
- g_assert(!gdkPixbufEqual(originalPixbuf.get(), highlightPixbuf.get()));
+ cairo_surface_t* highlightSurface = cairo_surface_reference(
+ test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(highlightSurface);
+ g_assert(!Test::cairoSurfacesEqual(originalSurface, highlightSurface));
WebKitFindController* findController = webkit_web_view_get_find_controller(test->m_webView);
webkit_find_controller_search_finish(findController);
webkit_web_view_execute_editing_command(test->m_webView, "Unselect");
- test->waitUntilWebViewDrawSignal();
- GRefPtr<GdkPixbuf> unhighlightPixbuf = adoptGRef(gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth));
- g_assert(unhighlightPixbuf);
- g_assert(gdkPixbufEqual(originalPixbuf.get(), unhighlightPixbuf.get()));
+ cairo_surface_t* unhighlightSurface = cairo_surface_reference(
+ test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(unhighlightSurface);
+ g_assert(Test::cairoSurfacesEqual(originalSurface, unhighlightSurface));
+
+ cairo_surface_destroy(originalSurface);
+ cairo_surface_destroy(highlightSurface);
+ cairo_surface_destroy(unhighlightSurface);
}
static void testFindControllerInstance(FindControllerTest* test, gconstpointer)
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp (148787 => 148788)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2013-04-20 08:23:19 UTC (rev 148788)
@@ -1150,34 +1150,6 @@
public:
MAKE_GLIB_TEST_FIXTURE(SnapshotWebViewTest);
- SnapshotWebViewTest()
- : m_surface(0)
- {
- }
-
- ~SnapshotWebViewTest()
- {
- cairo_surface_destroy(m_surface);
- }
-
- static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test)
- {
- GOwnPtr<GError> error;
- test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr());
- g_assert(!test->m_surface || !error.get());
- if (error)
- g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE);
- test->quitMainLoop();
- }
-
- cairo_surface_t* waitForSnapshot(WebKitSnapshotRegion region, WebKitSnapshotOptions options)
- {
- m_surface = 0;
- webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this);
- g_main_loop_run(m_mainLoop);
- return cairo_surface_reference(m_surface);
- }
-
static void onSnapshotCancelledReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test)
{
GOwnPtr<GError> error;
@@ -1189,6 +1161,8 @@
gboolean getSnapshotAndCancel()
{
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
m_surface = 0;
GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new());
webkit_web_view_get_snapshot(m_webView, WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE, cancellable.get(), reinterpret_cast<GAsyncReadyCallback>(onSnapshotCancelledReady), this);
@@ -1198,33 +1172,21 @@
return true;
}
- cairo_surface_t* m_surface;
};
-static gboolean cairoSurfacesEqual(cairo_surface_t* s1, cairo_surface_t* s2)
-{
- return (cairo_image_surface_get_format(s1) == cairo_image_surface_get_format(s2)
- && cairo_image_surface_get_width(s1) == cairo_image_surface_get_width(s2)
- && cairo_image_surface_get_height(s1) == cairo_image_surface_get_height(s2)
- && cairo_image_surface_get_stride(s1) == cairo_image_surface_get_stride(s2)
- && !memcmp(const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s1))),
- const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s2))),
- cairo_image_surface_get_height(s1)*cairo_image_surface_get_stride(s1)));
-}
-
static void testWebViewSnapshot(SnapshotWebViewTest* test, gconstpointer)
{
test->loadHtml("<html><body><p>Whatever</p></body></html>", 0);
test->waitUntilLoadFinished();
// WebView not visible.
- cairo_surface_t* surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ cairo_surface_t* surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
g_assert(!surface1);
// Show surface, resize to 50x50, try again.
test->showInWindowAndWaitUntilMapped();
test->resizeView(50, 50);
- surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
g_assert(surface1);
// obtained surface should be at the most 50x50. Store the size
@@ -1234,43 +1196,38 @@
g_assert_cmpint(width, <=, 50);
g_assert_cmpint(height, <=, 50);
- cairo_surface_destroy(surface1);
-
// Select all text in the WebView, request a snapshot ignoring selection.
test->selectAll();
- surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ surface1 = cairo_surface_reference(test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE));
g_assert(surface1);
g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, width);
g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, height);
// Create identical surface.
- cairo_surface_t* surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ cairo_surface_t* surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
g_assert(surface2);
// Compare these two, they should be identical.
- g_assert(cairoSurfacesEqual(surface1, surface2));
- cairo_surface_destroy(surface2);
+ g_assert(Test::cairoSurfacesEqual(surface1, surface2));
// Request a new snapshot, including the selection this time. The
// size should be the same but the result must be different to the
// one previously obtained.
- surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING);
+ surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING);
g_assert(surface2);
g_assert_cmpint(cairo_image_surface_get_width(surface2), ==, width);
g_assert_cmpint(cairo_image_surface_get_height(surface2), ==, height);
- g_assert(!cairoSurfacesEqual(surface1, surface2));
- cairo_surface_destroy(surface2);
+ g_assert(!Test::cairoSurfacesEqual(surface1, surface2));
// Request a snapshot of the whole document in the WebView. The
// result should be different from the size obtained previously.
- surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE);
g_assert(surface2);
g_assert_cmpint(cairo_image_surface_get_width(surface2), >, width);
g_assert_cmpint(cairo_image_surface_get_height(surface2), >, height);
- g_assert(!cairoSurfacesEqual(surface1, surface2));
+ g_assert(!Test::cairoSurfacesEqual(surface1, surface2));
cairo_surface_destroy(surface1);
- cairo_surface_destroy(surface2);
g_assert(test->getSnapshotAndCancel());
}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (148787 => 148788)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp 2013-04-20 08:23:19 UTC (rev 148788)
@@ -30,6 +30,7 @@
, m_parentWindow(0)
, m_javascriptResult(0)
, m_resourceDataSize(0)
+ , m_surface(0)
{
assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView));
}
@@ -40,6 +41,8 @@
gtk_widget_destroy(m_parentWindow);
if (m_javascriptResult)
webkit_javascript_result_unref(m_javascriptResult);
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
g_object_unref(m_webView);
g_main_loop_unref(m_mainLoop);
}
@@ -420,3 +423,22 @@
return JSValueIsUndefined(context, value);
}
+static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, WebViewTest* test)
+{
+ GOwnPtr<GError> error;
+ test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr());
+ g_assert(!test->m_surface || !error.get());
+ if (error)
+ g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE);
+ test->quitMainLoop();
+}
+
+cairo_surface_t* WebViewTest::getSnapshotAndWaitUntilReady(WebKitSnapshotRegion region, WebKitSnapshotOptions options)
+{
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
+ m_surface = 0;
+ webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this);
+ g_main_loop_run(m_mainLoop);
+ return m_surface;
+}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h (148787 => 148788)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h 2013-04-20 08:23:19 UTC (rev 148788)
@@ -66,6 +66,8 @@
static bool _javascript_ResultIsNull(WebKitJavascriptResult*);
static bool _javascript_ResultIsUndefined(WebKitJavascriptResult*);
+ cairo_surface_t* getSnapshotAndWaitUntilReady(WebKitSnapshotRegion, WebKitSnapshotOptions);
+
WebKitWebView* m_webView;
GMainLoop* m_mainLoop;
CString m_activeURI;
@@ -75,6 +77,7 @@
GError** m_javascriptError;
GOwnPtr<char> m_resourceData;
size_t m_resourceDataSize;
+ cairo_surface_t* m_surface;
private:
void doMouseButtonEvent(GdkEventType, int, int, unsigned int, unsigned int);
Modified: trunk/Tools/ChangeLog (148787 => 148788)
--- trunk/Tools/ChangeLog 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Tools/ChangeLog 2013-04-20 08:23:19 UTC (rev 148788)
@@ -1,3 +1,13 @@
+2013-04-20 Manuel Rego Casasnovas <[email protected]>
+
+ [GTK] Fix unit test webkit2/WebKitFindController/hide
+ https://bugs.webkit.org/show_bug.cgi?id=89810
+
+ Reviewed by Carlos Garcia Campos.
+
+ * Scripts/run-gtk-tests:
+ (TestRunner): Unskip test webkit2/WebKitFindController/hide.
+
2013-04-19 Ryosuke Niwa <[email protected]>
Build fixes for the flakiness dashboard.
Modified: trunk/Tools/Scripts/run-gtk-tests (148787 => 148788)
--- trunk/Tools/Scripts/run-gtk-tests 2013-04-20 04:38:43 UTC (rev 148787)
+++ trunk/Tools/Scripts/run-gtk-tests 2013-04-20 08:23:19 UTC (rev 148788)
@@ -70,7 +70,6 @@
SkippedTest("WebKit2APITests/TestInspectorServer", SkippedTest.ENTIRE_SUITE, "Test times out", 105866),
SkippedTest("WebKit2APITests/TestResources", "/webkit2/WebKitWebView/resources", "Test is flaky in GTK Linux 32-bit Release bot", 82868),
SkippedTest("WebKit2APITests/TestWebKitAccessibility", "/webkit2/WebKitAccessibility/atspi-basic-hierarchy", "Test fails", 100408),
- SkippedTest("WebKit2APITests/TestWebKitFindController", "/webkit2/WebKitFindController/hide", "Test always fails in Xvfb", 89810),
SkippedTest("TestWebKitAPI/TestWebKit2", "WebKit2.CanHandleRequest", "Test fails", 88453),
SkippedTest("TestWebKitAPI/TestWebKit2", "WebKit2.MouseMoveAfterCrash", "Test is flaky", 85066),
SkippedTest("TestWebKitAPI/TestWebKit2", "WebKit2.NewFirstVisuallyNonEmptyLayoutForImages", "Test is flaky", 85066),