<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[162343] releases/WebKitGTK/webkit-2.2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/162343">162343</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2014-01-20 08:25:58 -0800 (Mon, 20 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/162056">r162056</a> - [GTK] UI process crashes when the web process crashes while printing
https://bugs.webkit.org/show_bug.cgi?id=126977

Reviewed by Gustavo Noronha Silva.

Source/WebKit2:

When the web process crashes, the printing callback is
invalidated, so the function is called with a NULL error.

* UIProcess/API/gtk/WebKitPrintOperation.cpp:
(drawPagesForPrintingCompleted): Check wkError is not NULL before
trying to use it.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewPrintFrame): Set the print mode of the operation
before emitting the print signal.

Tools:

Add new test case to check that closing the window right after
printing works. It's skipped for now, because this patch only
fixes the UI process crash, but not the web process one.

* Scripts/run-gtk-tests:
(TestRunner): Skip
/webkit2/WebKitPrintOperation/close-after-print.
* TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp:
(testPrintOperationPrintPrinter):
(findPrintToFilePrinter):
(testPrintOperationPrint):
(testPrintOperationErrors):
(testPrintOperationCloseAfterPrint):
(beforeAll):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit22SourceWebKit2ChangeLog">releases/WebKitGTK/webkit-2.2/Source/WebKit2/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit22SourceWebKit2UIProcessAPIgtkWebKitPrintOperationcpp">releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit22SourceWebKit2UIProcessAPIgtkWebKitWebViewcpp">releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit22ToolsChangeLog">releases/WebKitGTK/webkit-2.2/Tools/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit22ToolsScriptsrungtktests">releases/WebKitGTK/webkit-2.2/Tools/Scripts/run-gtk-tests</a></li>
<li><a href="#releasesWebKitGTKwebkit22ToolsTestWebKitAPITestsWebKit2GtkTestPrintingcpp">releases/WebKitGTK/webkit-2.2/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit22SourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.2/Source/WebKit2/ChangeLog (162342 => 162343)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.2/Source/WebKit2/ChangeLog        2014-01-20 16:18:27 UTC (rev 162342)
+++ releases/WebKitGTK/webkit-2.2/Source/WebKit2/ChangeLog        2014-01-20 16:25:58 UTC (rev 162343)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2014-01-14  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] UI process crashes when the web process crashes while printing
+        https://bugs.webkit.org/show_bug.cgi?id=126977
+
+        Reviewed by Gustavo Noronha Silva.
+
+        When the web process crashes, the printing callback is
+        invalidated, so the function is called with a NULL error.
+
+        * UIProcess/API/gtk/WebKitPrintOperation.cpp:
+        (drawPagesForPrintingCompleted): Check wkError is not NULL before
+        trying to use it.
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewPrintFrame): Set the print mode of the operation
+        before emitting the print signal.
+
</ins><span class="cx"> 2014-01-15  Tomas Popela  &lt;tpopela@redhat.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [SOUP] [WK2] - Disable MemoryCache when the DOCUMENT_VIEWER cache model is set
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit22SourceWebKit2UIProcessAPIgtkWebKitPrintOperationcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp (162342 => 162343)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp        2014-01-20 16:18:27 UTC (rev 162342)
+++ releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp        2014-01-20 16:25:58 UTC (rev 162343)
</span><span class="lines">@@ -269,7 +269,7 @@
</span><span class="cx">     if (printOperation-&gt;priv-&gt;printMode == PrintInfo::PrintModeAsync)
</span><span class="cx">         page-&gt;endPrinting();
</span><span class="cx"> 
</span><del>-    const WebCore::ResourceError&amp; resourceError = toImpl(wkPrintError)-&gt;platformError();
</del><ins>+    const WebCore::ResourceError&amp; resourceError = wkPrintError ? toImpl(wkPrintError)-&gt;platformError() : WebCore::ResourceError();
</ins><span class="cx">     if (!resourceError.isNull()) {
</span><span class="cx">         GOwnPtr&lt;GError&gt; printError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()),
</span><span class="cx">                                                      resourceError.errorCode(),
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit22SourceWebKit2UIProcessAPIgtkWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (162342 => 162343)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2014-01-20 16:18:27 UTC (rev 162342)
+++ releases/WebKitGTK/webkit-2.2/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2014-01-20 16:25:58 UTC (rev 162343)
</span><span class="lines">@@ -1638,12 +1638,12 @@
</span><span class="cx"> void webkitWebViewPrintFrame(WebKitWebView* webView, WebFrameProxy* frame)
</span><span class="cx"> {
</span><span class="cx">     GRefPtr&lt;WebKitPrintOperation&gt; printOperation = adoptGRef(webkit_print_operation_new(webView));
</span><ins>+    webkitPrintOperationSetPrintMode(printOperation.get(), PrintInfo::PrintModeSync);
</ins><span class="cx">     gboolean returnValue;
</span><span class="cx">     g_signal_emit(webView, signals[PRINT], 0, printOperation.get(), &amp;returnValue);
</span><span class="cx">     if (returnValue)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    webkitPrintOperationSetPrintMode(printOperation.get(), PrintInfo::PrintModeSync);
</del><span class="cx">     WebKitPrintOperationResponse response = webkitPrintOperationRunDialogForFrame(printOperation.get(), 0, frame);
</span><span class="cx">     if (response == WEBKIT_PRINT_OPERATION_RESPONSE_CANCEL)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit22ToolsChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.2/Tools/ChangeLog (162342 => 162343)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.2/Tools/ChangeLog        2014-01-20 16:18:27 UTC (rev 162342)
+++ releases/WebKitGTK/webkit-2.2/Tools/ChangeLog        2014-01-20 16:25:58 UTC (rev 162343)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-01-14  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] UI process crashes when the web process crashes while printing
+        https://bugs.webkit.org/show_bug.cgi?id=126977
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add new test case to check that closing the window right after
+        printing works. It's skipped for now, because this patch only
+        fixes the UI process crash, but not the web process one.
+
+        * Scripts/run-gtk-tests:
+        (TestRunner): Skip
+        /webkit2/WebKitPrintOperation/close-after-print.
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp:
+        (testPrintOperationPrintPrinter):
+        (findPrintToFilePrinter):
+        (testPrintOperationPrint):
+        (testPrintOperationErrors):
+        (testPrintOperationCloseAfterPrint):
+        (beforeAll):
+
</ins><span class="cx"> 2014-01-09  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [SOUP] Partial file left on disk after a download fails or is cancelled in WebKit2
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit22ToolsScriptsrungtktests"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.2/Tools/Scripts/run-gtk-tests (162342 => 162343)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.2/Tools/Scripts/run-gtk-tests        2014-01-20 16:18:27 UTC (rev 162342)
+++ releases/WebKitGTK/webkit-2.2/Tools/Scripts/run-gtk-tests        2014-01-20 16:25:58 UTC (rev 162343)
</span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx">         SkippedTest(&quot;WebKit2Gtk/TestUIClient&quot;, &quot;/webkit2/WebKitWebView/mouse-target&quot;, &quot;Test times out after r150890&quot;, 117689),
</span><span class="cx">         SkippedTest(&quot;WebKit2Gtk/TestAuthentication&quot;, SkippedTest.ENTIRE_SUITE, &quot;Test times out after r150890&quot;, 117689),
</span><span class="cx">         SkippedTest(&quot;WebKit2Gtk/TestContextMenu&quot;, SkippedTest.ENTIRE_SUITE, &quot;Test times out after r150890&quot;, 117689),
</span><ins>+        SkippedTest(&quot;WebKit2Gtk/TestPrinting&quot;, &quot;/webkit2/WebKitPrintOperation/close-after-print&quot;, &quot;Test times out&quot;, 126979),
</ins><span class="cx">         SkippedTest(&quot;WebKit2/TestWebKit2&quot;, &quot;WebKit2.MouseMoveAfterCrash&quot;, &quot;Test is flaky&quot;, 85066),
</span><span class="cx">         SkippedTest(&quot;WebKit2/TestWebKit2&quot;, &quot;WebKit2.NewFirstVisuallyNonEmptyLayoutForImages&quot;, &quot;Test is flaky&quot;, 85066),
</span><span class="cx">         SkippedTest(&quot;WebKit2/TestWebKit2&quot;, &quot;WebKit2.NewFirstVisuallyNonEmptyLayoutFrames&quot;, &quot;Test fails&quot;, 85037),
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit22ToolsTestWebKitAPITestsWebKit2GtkTestPrintingcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.2/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp (162342 => 162343)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.2/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp        2014-01-20 16:18:27 UTC (rev 162342)
+++ releases/WebKitGTK/webkit-2.2/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestPrinting.cpp        2014-01-20 16:25:58 UTC (rev 162343)
</span><span class="lines">@@ -72,6 +72,23 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #ifdef HAVE_GTK_UNIX_PRINTING
</span><ins>+static gboolean testPrintOperationPrintPrinter(GtkPrinter* printer, gpointer userData)
+{
+    if (strcmp(gtk_printer_get_name(printer), &quot;Print to File&quot;))
+        return FALSE;
+
+    GtkPrinter** foundPrinter = static_cast&lt;GtkPrinter**&gt;(userData);
+    *foundPrinter = static_cast&lt;GtkPrinter*&gt;(g_object_ref(printer));
+    return TRUE;
+}
+
+static GtkPrinter* findPrintToFilePrinter()
+{
+    GtkPrinter* printer = 0;
+    gtk_enumerate_printers(testPrintOperationPrintPrinter, &amp;printer, 0, TRUE);
+    return printer;
+}
+
</ins><span class="cx"> class PrintTest: public WebViewTest {
</span><span class="cx"> public:
</span><span class="cx">     MAKE_GLIB_TEST_FIXTURE(PrintTest);
</span><span class="lines">@@ -97,23 +114,6 @@
</span><span class="cx">         g_signal_connect(m_printOperation.get(), &quot;failed&quot;, G_CALLBACK(printFailedCallback), this);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    static gboolean testPrintOperationPrintPrinter(GtkPrinter* printer, gpointer userData)
-    {
-        if (strcmp(gtk_printer_get_name(printer), &quot;Print to File&quot;))
-            return FALSE;
-
-        GtkPrinter** foundPrinter = static_cast&lt;GtkPrinter**&gt;(userData);
-        *foundPrinter = static_cast&lt;GtkPrinter*&gt;(g_object_ref(printer));
-        return TRUE;
-    }
-
-    GtkPrinter* findPrintToFilePrinter()
-    {
-        GtkPrinter* printer = 0;
-        gtk_enumerate_printers(testPrintOperationPrintPrinter, &amp;printer, 0, TRUE);
-        return printer;
-    }
-
</del><span class="cx">     void waitUntilPrintFinished()
</span><span class="cx">     {
</span><span class="cx">         g_main_loop_run(m_mainLoop);
</span><span class="lines">@@ -128,7 +128,7 @@
</span><span class="cx">     test-&gt;loadHtml(&quot;&lt;html&gt;&lt;body&gt;WebKitGTK+ printing test&lt;/body&gt;&lt;/html&gt;&quot;, 0);
</span><span class="cx">     test-&gt;waitUntilLoadFinished();
</span><span class="cx"> 
</span><del>-    GRefPtr&lt;GtkPrinter&gt; printer = adoptGRef(test-&gt;findPrintToFilePrinter());
</del><ins>+    GRefPtr&lt;GtkPrinter&gt; printer = adoptGRef(findPrintToFilePrinter());
</ins><span class="cx">     if (!printer) {
</span><span class="cx">         g_message(&quot;%s&quot;, &quot;Cannot test WebKitPrintOperation/print: no suitable printer found&quot;);
</span><span class="cx">         return;
</span><span class="lines">@@ -160,7 +160,7 @@
</span><span class="cx">     test-&gt;loadHtml(&quot;&lt;html&gt;&lt;body&gt;WebKitGTK+ printing errors test&lt;/body&gt;&lt;/html&gt;&quot;, 0);
</span><span class="cx">     test-&gt;waitUntilLoadFinished();
</span><span class="cx"> 
</span><del>-    GRefPtr&lt;GtkPrinter&gt; printer = adoptGRef(test-&gt;findPrintToFilePrinter());
</del><ins>+    GRefPtr&lt;GtkPrinter&gt; printer = adoptGRef(findPrintToFilePrinter());
</ins><span class="cx">     if (!printer) {
</span><span class="cx">         g_message(&quot;%s&quot;, &quot;Cannot test WebKitPrintOperation/print: no suitable printer found&quot;);
</span><span class="cx">         return;
</span><span class="lines">@@ -188,6 +188,105 @@
</span><span class="cx">     webkit_print_operation_print(test-&gt;m_printOperation.get());
</span><span class="cx">     test-&gt;waitUntilPrintFinished();
</span><span class="cx"> }
</span><ins>+
+class CloseAfterPrintTest: public WebViewTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(CloseAfterPrintTest);
+
+    static GtkWidget* webViewCreate(WebKitWebView* webView, CloseAfterPrintTest* test)
+    {
+        return test-&gt;createWebView();
+    }
+
+    static gboolean webViewPrint(WebKitWebView* webView, WebKitPrintOperation* printOperation, CloseAfterPrintTest* test)
+    {
+        test-&gt;print(printOperation);
+        return TRUE;
+    }
+
+    static void printOperationFinished(WebKitPrintOperation* printOperation, CloseAfterPrintTest* test)
+    {
+        test-&gt;printFinished();
+    }
+
+    static void webViewClosed(WebKitWebView* webView, CloseAfterPrintTest* test)
+    {
+        gtk_widget_destroy(GTK_WIDGET(webView));
+        test-&gt;m_webViewClosed = true;
+        if (test-&gt;m_printFinished)
+            g_main_loop_quit(test-&gt;m_mainLoop);
+    }
+
+    CloseAfterPrintTest()
+        : m_webViewClosed(false)
+        , m_printFinished(false)
+    {
+        webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE);
+        g_signal_connect(m_webView, &quot;create&quot;, G_CALLBACK(webViewCreate), this);
+    }
+
+    GtkWidget* createWebView()
+    {
+        GtkWidget* newWebView = webkit_web_view_new();
+        g_object_ref_sink(newWebView);
+
+        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newWebView));
+        g_signal_connect(newWebView, &quot;print&quot;, G_CALLBACK(webViewPrint), this);
+        g_signal_connect(newWebView, &quot;close&quot;, G_CALLBACK(webViewClosed), this);
+        return newWebView;
+    }
+
+    void print(WebKitPrintOperation* printOperation)
+    {
+        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation));
+
+        GRefPtr&lt;GtkPrinter&gt; printer = adoptGRef(findPrintToFilePrinter());
+        if (!printer) {
+            g_message(&quot;%s&quot;, &quot;Cannot test WebKitPrintOperation/print: no suitable printer found&quot;);
+            return;
+        }
+
+        GOwnPtr&lt;char&gt; outputFilename(g_build_filename(kTempDirectory, &quot;webkit-close-after-print.pdf&quot;, NULL));
+        m_outputFile = adoptGRef(g_file_new_for_path(outputFilename.get()));
+        GOwnPtr&lt;char&gt; outputURI(g_file_get_uri(m_outputFile.get()));
+
+        GRefPtr&lt;GtkPrintSettings&gt; printSettings = adoptGRef(gtk_print_settings_new());
+        gtk_print_settings_set_printer(printSettings.get(), gtk_printer_get_name(printer.get()));
+        gtk_print_settings_set(printSettings.get(), GTK_PRINT_SETTINGS_OUTPUT_URI, outputURI.get());
+        webkit_print_operation_set_print_settings(printOperation, printSettings.get());
+
+        m_printOperation = printOperation;
+        g_signal_connect(m_printOperation.get(), &quot;finished&quot;, G_CALLBACK(printOperationFinished), this);
+        webkit_print_operation_print(m_printOperation.get());
+    }
+
+    void printFinished()
+    {
+        m_printFinished = true;
+        m_printOperation = nullptr;
+        g_assert(m_outputFile);
+        g_file_delete(m_outputFile.get(), 0, 0);
+        m_outputFile = nullptr;
+        if (m_webViewClosed)
+            g_main_loop_quit(m_mainLoop);
+    }
+
+    void waitUntilPrintFinishedAndViewClosed()
+    {
+        g_main_loop_run(m_mainLoop);
+    }
+
+    GRefPtr&lt;WebKitPrintOperation&gt; m_printOperation;
+    GRefPtr&lt;GFile&gt; m_outputFile;
+    bool m_webViewClosed;
+    bool m_printFinished;
+};
+
+static void testPrintOperationCloseAfterPrint(CloseAfterPrintTest* test, gconstpointer)
+{
+    test-&gt;loadHtml(&quot;&lt;html&gt;&lt;body onLoad=\&quot;w = window.open();w.print();w.close();\&quot;&gt;&lt;/body&gt;&lt;/html&gt;&quot;, 0);
+    test-&gt;waitUntilPrintFinishedAndViewClosed();
+}
</ins><span class="cx"> #endif // HAVE_GTK_UNIX_PRINTING
</span><span class="cx"> 
</span><span class="cx"> void beforeAll()
</span><span class="lines">@@ -200,6 +299,7 @@
</span><span class="cx"> #ifdef HAVE_GTK_UNIX_PRINTING
</span><span class="cx">     PrintTest::add(&quot;WebKitPrintOperation&quot;, &quot;print&quot;, testPrintOperationPrint);
</span><span class="cx">     PrintTest::add(&quot;WebKitPrintOperation&quot;, &quot;print-errors&quot;, testPrintOperationErrors);
</span><ins>+    CloseAfterPrintTest::add(&quot;WebKitPrintOperation&quot;, &quot;close-after-print&quot;, testPrintOperationCloseAfterPrint);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>