Skip to content

Commit

Permalink
Merge r178644 - [GTK] [WK2] TestWebKitWebView snapshot fails
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=120404

Reviewed by Žan Doberšek.

Rework the test to make sure the snapshot is always created at the
desired size.

* Scripts/run-gtk-tests:
(TestRunner): Unskip /webkit2/WebKitWebView/snapshot.
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
(testWebViewSnapshot): Use a fixed size for the document, and
disable scrollbars to make sure the visible area is always the
WebView size.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::showInWindowAndWaitUntilMapped): Add optional width
and height parameters to create the window with a given size.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:

Canonical link: https://commits.webkit.org/154760.304@webkitgtk/2.6
git-svn-id: https://svn.webkit.org/repository/webkit/releases/WebKitGTK/webkit-2.6@182390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Apr 6, 2015
1 parent 222720f commit 7078ad7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
21 changes: 21 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,24 @@
2015-01-19 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] [WK2] TestWebKitWebView snapshot fails
https://bugs.webkit.org/show_bug.cgi?id=120404

Reviewed by Žan Doberšek.

Rework the test to make sure the snapshot is always created at the
desired size.

* Scripts/run-gtk-tests:
(TestRunner): Unskip /webkit2/WebKitWebView/snapshot.
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
(testWebViewSnapshot): Use a fixed size for the document, and
disable scrollbars to make sure the visible area is always the
WebView size.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::showInWindowAndWaitUntilMapped): Add optional width
and height parameters to create the window with a given size.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:

2015-01-26 Michael Catanzaro <mcatanzaro@igalia.com> and Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] gtkdoc does not appear in DevHelp
Expand Down
1 change: 0 additions & 1 deletion Tools/Scripts/run-gtk-tests
Expand Up @@ -64,7 +64,6 @@ class TestRunner:
SkippedTest("WebKit2Gtk/TestUIClient", "/webkit2/WebKitWebView/mouse-target", "Test times out after r150890", 117689),
SkippedTest("WebKit2Gtk/TestContextMenu", SkippedTest.ENTIRE_SUITE, "Test times out after r150890", 117689),
SkippedTest("WebKit2APITests/TestWebKitAccessibility", "/webkit2/WebKitAccessibility/atspi-basic-hierarchy", "Test is flaky", 132134),
SkippedTest("WebKit2Gtk/TestWebKitWebView", "/webkit2/WebKitWebView/snapshot", "Test fails", 120404),
SkippedTest("WebKit2Gtk/TestWebKitWebView", "/webkit2/WebKitWebView/page-visibility", "Test fails or times out", 131731),
SkippedTest("WebKit2Gtk/TestCookieManager", "/webkit2/WebKitCookieManager/persistent-storage", "Test is flaky", 134580),
SkippedTest("WebKit2/TestWebKit2", "WebKit2.MouseMoveAfterCrash", "Test is flaky", 85066),
Expand Down
55 changes: 20 additions & 35 deletions Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp
Expand Up @@ -515,59 +515,44 @@ class SnapshotWebViewTest: public WebViewTest {

static void testWebViewSnapshot(SnapshotWebViewTest* test, gconstpointer)
{
test->loadHtml("<html><body><p>Whatever</p></body></html>", 0);
test->loadHtml("<html><head><style>html { width: 200px; height: 100px; } ::-webkit-scrollbar { display: none; }</style></head><body><p>Whatever</p></body></html>", nullptr);
test->waitUntilLoadFinished();

// WebView not visible.
// WEBKIT_SNAPSHOT_REGION_VISIBLE returns a null surface when the view is not visible.
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->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
// WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT works even if the window is not visible.
surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE);
g_assert(surface1);
g_assert_cmpuint(cairo_surface_get_type(surface1), ==, CAIRO_SURFACE_TYPE_IMAGE);
g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, 200);
g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, 100);

// obtained surface should be at the most 50x50. Store the size
// for comparison later.
int width = cairo_image_surface_get_width(surface1);
int height = cairo_image_surface_get_height(surface1);
g_assert_cmpint(width, <=, 50);
g_assert_cmpint(height, <=, 50);

// Select all text in the WebView, request a snapshot ignoring selection.
test->selectAll();
// Show the WebView in a popup widow of 50x50 and try again with WEBKIT_SNAPSHOT_REGION_VISIBLE.
test->showInWindowAndWaitUntilMapped(GTK_WINDOW_POPUP, 50, 50);
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);
g_assert_cmpuint(cairo_surface_get_type(surface1), ==, CAIRO_SURFACE_TYPE_IMAGE);
g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, 50);
g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, 50);

// Create identical surface.
// Select all text in the WebView, request a snapshot ignoring selection.
test->selectAll();
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(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.
// 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->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(!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->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_cmpuint(cairo_surface_get_type(surface2), ==, CAIRO_SURFACE_TYPE_IMAGE);
g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, cairo_image_surface_get_width(surface2));
g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, cairo_image_surface_get_height(surface2));
g_assert(!Test::cairoSurfacesEqual(surface1, surface2));

cairo_surface_destroy(surface1);

// Test that cancellation works.
g_assert(test->getSnapshotAndCancel());
}

Expand Down
4 changes: 3 additions & 1 deletion Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp
Expand Up @@ -235,10 +235,12 @@ void WebViewTest::showInWindow(GtkWindowType windowType)
gtk_widget_show(m_parentWindow);
}

void WebViewTest::showInWindowAndWaitUntilMapped(GtkWindowType windowType)
void WebViewTest::showInWindowAndWaitUntilMapped(GtkWindowType windowType, int width, int height)
{
g_assert(!m_parentWindow);
m_parentWindow = gtk_window_new(windowType);
if (width && height)
gtk_window_resize(GTK_WINDOW(m_parentWindow), width, height);
gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView));
gtk_widget_show(GTK_WIDGET(m_webView));

Expand Down
2 changes: 1 addition & 1 deletion Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h
Expand Up @@ -49,7 +49,7 @@ class WebViewTest: public Test {
void waitUntilTitleChangedTo(const char* expectedTitle);
void waitUntilTitleChanged();
void showInWindow(GtkWindowType = GTK_WINDOW_POPUP);
void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP);
void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP, int width = 0, int height = 0);
void resizeView(int width, int height);
void selectAll();
const char* mainResourceData(size_t& mainResourceDataSize);
Expand Down

0 comments on commit 7078ad7

Please sign in to comment.