<!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>[173456] trunk</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/173456">173456</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-09-10 01:37:17 -0700 (Wed, 10 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] allow overwriting destination of download
https://bugs.webkit.org/show_bug.cgi?id=136372

Patch by Michael Catanzaro &lt;mcatanzaro@igalia.com&gt; on 2014-09-10
Reviewed by Carlos Garcia Campos.

Source/WebKit2:

* UIProcess/API/gtk/WebKitDownload.cpp:
(webkitDownloadGetProperty): Added
(webkit_download_class_init): Install webkitDownloadGetProperty
(webkitDownloadDecideDestinationWithSuggestedFilename): Add
allowOverwrite parameter and set it appropriately
(webkit_download_get_allow_overwrite): Added
(webkit_download_set_allow_overwrite): Added
* UIProcess/API/gtk/WebKitDownload.h: New API
* UIProcess/API/gtk/WebKitDownloadClient.cpp:
(decideDestinationWithSuggestedFilename): Pass allowOverwrite to
webkitDownloadDecideDestinationWithSuggestedFilename
* UIProcess/API/gtk/WebKitDownloadPrivate.h: Add allowOverwrite
parameter to webkitDownloadDecideDestinationWithSuggestedFilename
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: New API

Tools:

* TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
(downloadLocalFileSuccessfully): Split from testDownloadLocalFile
(testDownloadLocalFile): Split off downloadLocalFileSuccessfully
(createFileAtDestination): Added
(testDownloadOverwriteDestinationAllowed): Added
(testDownloadOverwriteDestinationDisallowed): Added
(testDownloadLocalFileError): Use new DownloadErrorTest::ExpectedError
(testDownloadRemoteFileError): Use new DownloadErrorTest::ExpectedError
(beforeAll): New tests</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadh">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadClientcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadPrivateh">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkdocswebkit2gtksectionstxt">trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkTestDownloadscpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Source/WebKit2/ChangeLog        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-09-10  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
+
+        [GTK] allow overwriting destination of download
+        https://bugs.webkit.org/show_bug.cgi?id=136372
+
+        Reviewed by Carlos Garcia Campos.
+
+        * UIProcess/API/gtk/WebKitDownload.cpp:
+        (webkitDownloadGetProperty): Added
+        (webkit_download_class_init): Install webkitDownloadGetProperty
+        (webkitDownloadDecideDestinationWithSuggestedFilename): Add
+        allowOverwrite parameter and set it appropriately
+        (webkit_download_get_allow_overwrite): Added
+        (webkit_download_set_allow_overwrite): Added
+        * UIProcess/API/gtk/WebKitDownload.h: New API
+        * UIProcess/API/gtk/WebKitDownloadClient.cpp:
+        (decideDestinationWithSuggestedFilename): Pass allowOverwrite to
+        webkitDownloadDecideDestinationWithSuggestedFilename
+        * UIProcess/API/gtk/WebKitDownloadPrivate.h: Add allowOverwrite
+        parameter to webkitDownloadDecideDestinationWithSuggestedFilename
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: New API
+
</ins><span class="cx"> 2014-09-10  Rohit Kumar  &lt;kumar.rohit@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Clean up the WebKit build from unused parameter warning in Webkit2/UIProcess module
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Igalia S.L.
</del><ins>+ * Copyright (C) 2012, 2014 Igalia S.L.
</ins><span class="cx">  *
</span><span class="cx">  * This library is free software; you can redistribute it and/or
</span><span class="cx">  * modify it under the terms of the GNU Library General Public
</span><span class="lines">@@ -63,7 +63,8 @@
</span><span class="cx"> 
</span><span class="cx">     PROP_DESTINATION,
</span><span class="cx">     PROP_RESPONSE,
</span><del>-    PROP_ESTIMATED_PROGRESS
</del><ins>+    PROP_ESTIMATED_PROGRESS,
+    PROP_ALLOW_OVERWRITE
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct _WebKitDownloadPrivate {
</span><span class="lines">@@ -84,12 +85,26 @@
</span><span class="cx">     GUniquePtr&lt;GTimer&gt; timer;
</span><span class="cx">     gdouble lastProgress;
</span><span class="cx">     gdouble lastElapsed;
</span><ins>+    bool allowOverwrite;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static guint signals[LAST_SIGNAL] = { 0, };
</span><span class="cx"> 
</span><span class="cx"> WEBKIT_DEFINE_TYPE(WebKitDownload, webkit_download, G_TYPE_OBJECT)
</span><span class="cx"> 
</span><ins>+static void webkitDownloadSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
+{
+    WebKitDownload* download = WEBKIT_DOWNLOAD(object);
+
+    switch (propId) {
+    case PROP_ALLOW_OVERWRITE:
+        webkit_download_set_allow_overwrite(download, g_value_get_boolean(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
</ins><span class="cx"> static void webkitDownloadGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
</span><span class="cx"> {
</span><span class="cx">     WebKitDownload* download = WEBKIT_DOWNLOAD(object);
</span><span class="lines">@@ -104,6 +119,9 @@
</span><span class="cx">     case PROP_ESTIMATED_PROGRESS:
</span><span class="cx">         g_value_set_double(value, webkit_download_get_estimated_progress(download));
</span><span class="cx">         break;
</span><ins>+    case PROP_ALLOW_OVERWRITE:
+        g_value_set_boolean(value, webkit_download_get_allow_overwrite(download));
+        break;
</ins><span class="cx">     default:
</span><span class="cx">         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
</span><span class="cx">     }
</span><span class="lines">@@ -130,6 +148,7 @@
</span><span class="cx"> static void webkit_download_class_init(WebKitDownloadClass* downloadClass)
</span><span class="cx"> {
</span><span class="cx">     GObjectClass* objectClass = G_OBJECT_CLASS(downloadClass);
</span><ins>+    objectClass-&gt;set_property = webkitDownloadSetProperty;
</ins><span class="cx">     objectClass-&gt;get_property = webkitDownloadGetProperty;
</span><span class="cx"> 
</span><span class="cx">     downloadClass-&gt;decide_destination = webkitDownloadDecideDestination;
</span><span class="lines">@@ -179,6 +198,25 @@
</span><span class="cx">                                                         WEBKIT_PARAM_READABLE));
</span><span class="cx"> 
</span><span class="cx">     /**
</span><ins>+     * WebKitDownload:allow-overwrite:
+     *
+     * Whether or not the download is allowed to overwrite an existing file on
+     * disk. If this property is %FALSE and the destination already exists,
+     * the download will fail.
+     *
+     * Since: 2.6
+     */
+    g_object_class_install_property(
+        objectClass,
+        PROP_ALLOW_OVERWRITE,
+        g_param_spec_boolean(
+            &quot;allow-overwrite&quot;,
+            _(&quot;Allow Overwrite&quot;),
+            _(&quot;Whether the destination may be overwritten&quot;),
+            FALSE,
+            WEBKIT_PARAM_READWRITE));
+
+    /**
</ins><span class="cx">      * WebKitDownload::received-data:
</span><span class="cx">      * @download: the #WebKitDownload
</span><span class="cx">      * @data_length: the length of data received in bytes
</span><span class="lines">@@ -370,12 +408,13 @@
</span><span class="cx">     g_signal_emit(download, signals[FINISHED], 0, NULL);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString&amp; suggestedFilename)
</del><ins>+CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString&amp; suggestedFilename, bool&amp; allowOverwrite)
</ins><span class="cx"> {
</span><span class="cx">     if (download-&gt;priv-&gt;isCancelled)
</span><span class="cx">         return &quot;&quot;;
</span><span class="cx">     gboolean returnValue;
</span><span class="cx">     g_signal_emit(download, signals[DECIDE_DESTINATION], 0, suggestedFilename.data(), &amp;returnValue);
</span><ins>+    allowOverwrite = download-&gt;priv-&gt;allowOverwrite;
</ins><span class="cx">     return download-&gt;priv-&gt;destinationURI;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -568,3 +607,44 @@
</span><span class="cx"> 
</span><span class="cx">     return download-&gt;priv-&gt;webView;
</span><span class="cx"> }
</span><ins>+
+/**
+ * webkit_download_get_allow_overwrite:
+ * @download: a #WebKitDownload
+ *
+ * Returns the current value of the #WebKitDownload:allow-overwrite property,
+ * which determines whether the download will overwrite an existing file on
+ * disk, or if it will fail if the destination already exists.
+ *
+ * Returns: the current value of the #WebKitDownload:allow-overwrite property
+ *
+ * Since: 2.6
+ */
+gboolean webkit_download_get_allow_overwrite(WebKitDownload* download)
+{
+    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), FALSE);
+
+    return download-&gt;priv-&gt;allowOverwrite;
+}
+
+/**
+ * webkit_download_set_allow_overwrite:
+ * @download: a #WebKitDownload
+ * @allowed: the new value for the #WebKitDownload:allow-overwrite property
+ *
+ * Sets the #WebKitDownload:allow-overwrite property, which determines whether
+ * the download may overwrite an existing file on disk, or if it will fail if
+ * the destination already exists.
+ *
+ * Since: 2.6
+ */
+void webkit_download_set_allow_overwrite(WebKitDownload* download, gboolean allowed)
+{
+    g_return_if_fail(WEBKIT_IS_DOWNLOAD(download));
+
+    if (allowed == download-&gt;priv-&gt;allowOverwrite)
+        return;
+
+    download-&gt;priv-&gt;allowOverwrite = allowed;
+    g_object_notify(G_OBJECT(download), &quot;allow-overwrite&quot;);
+}
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -92,6 +92,13 @@
</span><span class="cx"> WEBKIT_API WebKitWebView *
</span><span class="cx"> webkit_download_get_web_view             (WebKitDownload *download);
</span><span class="cx"> 
</span><ins>+WEBKIT_API gboolean
+webkit_download_get_allow_overwrite      (WebKitDownload *download);
+
+WEBKIT_API void
+webkit_download_set_allow_overwrite      (WebKitDownload *download,
+                                          gboolean        allowed);
+
</ins><span class="cx"> G_END_DECLS
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -54,11 +54,10 @@
</span><span class="cx">     webkitDownloadNotifyProgress(download.get(), length);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* /* allowOverwrite */, const void* /* clientInfo */)
</del><ins>+static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* allowOverwrite, const void* /* clientInfo */)
</ins><span class="cx"> {
</span><span class="cx">     GRefPtr&lt;WebKitDownload&gt; download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
</span><del>-    CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(),
-                                                                                  toImpl(filename)-&gt;string().utf8());
</del><ins>+    CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), toImpl(filename)-&gt;string().utf8(), *allowOverwrite);
</ins><span class="cx">     return WKStringCreateWithUTF8CString(destinationURI.data());
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -35,7 +35,7 @@
</span><span class="cx"> void webkitDownloadFailed(WebKitDownload*, const WebCore::ResourceError&amp;);
</span><span class="cx"> void webkitDownloadCancelled(WebKitDownload*);
</span><span class="cx"> void webkitDownloadFinished(WebKitDownload*);
</span><del>-CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString&amp; suggestedFilename);
</del><ins>+CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString&amp; suggestedFilename, bool&amp; allowOverwrite);
</ins><span class="cx"> void webkitDownloadDestinationCreated(WebKitDownload*, const CString&amp; destinationURI);
</span><span class="cx"> 
</span><span class="cx"> #endif // WebKitDownloadPrivate_h
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkdocswebkit2gtksectionstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -522,6 +522,8 @@
</span><span class="cx"> webkit_download_get_elapsed_time
</span><span class="cx"> webkit_download_get_received_data_length
</span><span class="cx"> webkit_download_get_web_view
</span><ins>+webkit_download_get_allow_overwrite
+webkit_download_set_allow_overwrite
</ins><span class="cx"> 
</span><span class="cx"> &lt;SUBSECTION Standard&gt;
</span><span class="cx"> WebKitDownloadClass
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Tools/ChangeLog        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2014-09-10  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
+
+        [GTK] allow overwriting destination of download
+        https://bugs.webkit.org/show_bug.cgi?id=136372
+
+        Reviewed by Carlos Garcia Campos.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
+        (downloadLocalFileSuccessfully): Split from testDownloadLocalFile
+        (testDownloadLocalFile): Split off downloadLocalFileSuccessfully
+        (createFileAtDestination): Added
+        (testDownloadOverwriteDestinationAllowed): Added
+        (testDownloadOverwriteDestinationDisallowed): Added
+        (testDownloadLocalFileError): Use new DownloadErrorTest::ExpectedError
+        (testDownloadRemoteFileError): Use new DownloadErrorTest::ExpectedError
+        (beforeAll): New tests
+
</ins><span class="cx"> 2014-08-05  David Farler  &lt;dfarler@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         iOS Simulator: run-webkit-tests chokes on unterminated UTF-8 when writing a test result
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkTestDownloadscpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp (173455 => 173456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp        2014-09-10 07:21:19 UTC (rev 173455)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp        2014-09-10 08:37:17 UTC (rev 173456)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Igalia S.L.
</del><ins>+ * Copyright (C) 2012, 2014 Igalia S.L.
</ins><span class="cx">  *
</span><span class="cx">  * This library is free software; you can redistribute it and/or
</span><span class="cx">  * modify it under the terms of the GNU Library General Public
</span><span class="lines">@@ -56,6 +56,8 @@
</span><span class="cx">     {
</span><span class="cx">         g_assert(webkit_download_get_destination(download));
</span><span class="cx">         g_assert_cmpstr(webkit_download_get_destination(download), ==, destination);
</span><ins>+        GRefPtr&lt;GFile&gt; file = adoptGRef(g_file_new_for_uri(destination));
+        g_assert(g_file_query_exists(file.get(), nullptr));
</ins><span class="cx">         test-&gt;createdDestination(download, destination);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -72,6 +74,14 @@
</span><span class="cx">     static void failedCallback(WebKitDownload* download, GError* error, DownloadTest* test)
</span><span class="cx">     {
</span><span class="cx">         g_assert(error);
</span><ins>+
+        const char* destinationURI = webkit_download_get_destination(download);
+        if (destinationURI) {
+            GUniquePtr&lt;char&gt; tempFileURI(g_strconcat(destinationURI, &quot;.wkdownload&quot;, nullptr));
+            GRefPtr&lt;GFile&gt; tempFile = adoptGRef(g_file_new_for_uri(tempFileURI.get()));
+            g_assert(!g_file_query_exists(tempFile.get(), nullptr));
+        }
+
</ins><span class="cx">         test-&gt;failed(download, error);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -98,6 +108,7 @@
</span><span class="cx">         : m_webContext(webkit_web_context_get_default())
</span><span class="cx">         , m_mainLoop(g_main_loop_new(0, TRUE))
</span><span class="cx">         , m_downloadSize(0)
</span><ins>+        , m_allowOverwrite(false)
</ins><span class="cx">     {
</span><span class="cx">         g_signal_connect(m_webContext, &quot;download-started&quot;, G_CALLBACK(downloadStartedCallback), this);
</span><span class="cx">     }
</span><span class="lines">@@ -110,6 +121,8 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void started(WebKitDownload* download)
</span><span class="cx">     {
</span><ins>+        m_downloadSize = 0;
+        m_downloadEvents.clear();
</ins><span class="cx">         m_downloadEvents.append(Started);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -154,6 +167,10 @@
</span><span class="cx">         WebKitDownload* download = webkit_web_context_download_uri(m_webContext, requestURI.data());
</span><span class="cx">         assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download));
</span><span class="cx"> 
</span><ins>+        g_assert(!webkit_download_get_allow_overwrite(download));
+        webkit_download_set_allow_overwrite(download, m_allowOverwrite);
+        g_assert(webkit_download_get_allow_overwrite(download) == m_allowOverwrite);
+
</ins><span class="cx">         WebKitURIRequest* request = webkit_download_get_request(download);
</span><span class="cx">         g_assert(request);
</span><span class="cx">         ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
</span><span class="lines">@@ -178,11 +195,12 @@
</span><span class="cx">     GMainLoop* m_mainLoop;
</span><span class="cx">     Vector&lt;DownloadEvent&gt; m_downloadEvents;
</span><span class="cx">     guint64 m_downloadSize;
</span><ins>+    bool m_allowOverwrite;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><del>-static void testDownloadLocalFile(DownloadTest* test, gconstpointer)
</del><ins>+static GRefPtr&lt;WebKitDownload&gt; downloadLocalFileSuccessfully(DownloadTest* test, const char* filename)
</ins><span class="cx"> {
</span><del>-    GUniquePtr&lt;char&gt; sourcePath(g_build_filename(Test::getResourcesDir().data(), &quot;test.pdf&quot;, nullptr));
</del><ins>+    GUniquePtr&lt;char&gt; sourcePath(g_build_filename(Test::getResourcesDir().data(), filename, nullptr));
</ins><span class="cx">     GRefPtr&lt;GFile&gt; source = adoptGRef(g_file_new_for_path(sourcePath.get()));
</span><span class="cx">     GRefPtr&lt;GFileInfo&gt; sourceInfo = adoptGRef(g_file_query_info(source.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast&lt;GFileQueryInfoFlags&gt;(0), 0, 0));
</span><span class="cx">     GUniquePtr&lt;char&gt; sourceURI(g_file_get_uri(source.get()));
</span><span class="lines">@@ -204,15 +222,50 @@
</span><span class="cx">     g_assert_cmpint(test-&gt;m_downloadSize, ==, g_file_info_get_size(sourceInfo.get()));
</span><span class="cx">     g_assert(webkit_download_get_destination(download.get()));
</span><span class="cx">     g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1);
</span><del>-    test-&gt;checkDestinationAndDeleteFile(download.get(), &quot;test.pdf&quot;);
</del><ins>+
+    return download;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void testDownloadLocalFile(DownloadTest* test, gconstpointer)
+{
+    static const char* filename = &quot;test.pdf&quot;;
+    GRefPtr&lt;WebKitDownload&gt; download = downloadLocalFileSuccessfully(test, filename);
+    test-&gt;checkDestinationAndDeleteFile(download.get(), filename);
+}
+
+static void createFileAtDestination(const char* filename)
+{
+    GUniquePtr&lt;char&gt; path(g_build_filename(kTempDirectory, filename, nullptr));
+    GRefPtr&lt;GFile&gt; file = adoptGRef(g_file_new_for_path(path.get()));
+    GUniqueOutPtr&lt;GError&gt; error;
+    g_file_create(file.get(), G_FILE_CREATE_NONE, nullptr, &amp;error.outPtr());
+    g_assert(!error);
+    g_assert(g_file_query_exists(file.get(), nullptr));
+}
+
+static void testDownloadOverwriteDestinationAllowed(DownloadTest* test, gconstpointer)
+{
+    static const char* filename = &quot;test.pdf&quot;;
+    createFileAtDestination(filename);
+
+    test-&gt;m_allowOverwrite = true;
+    GRefPtr&lt;WebKitDownload&gt; download = downloadLocalFileSuccessfully(test, filename);
+    test-&gt;checkDestinationAndDeleteFile(download.get(), filename);
+}
+
</ins><span class="cx"> class DownloadErrorTest: public DownloadTest {
</span><span class="cx"> public:
</span><span class="cx">     MAKE_GLIB_TEST_FIXTURE(DownloadErrorTest);
</span><span class="cx"> 
</span><ins>+    enum ExpectedError {
+        NetworkError,
+        DownloadCancelled,
+        InvalidDestination,
+        DestinationExists
+    };
+
</ins><span class="cx">     DownloadErrorTest()
</span><del>-        : m_expectedError(WEBKIT_DOWNLOAD_ERROR_NETWORK)
</del><ins>+        : m_expectedError(NetworkError)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -223,7 +276,7 @@
</span><span class="cx"> 
</span><span class="cx">     void createdDestination(WebKitDownload* download, const char* destination)
</span><span class="cx">     {
</span><del>-        if (m_expectedError == WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER)
</del><ins>+        if (m_expectedError == DownloadCancelled)
</ins><span class="cx">             webkit_download_cancel(download);
</span><span class="cx">         else
</span><span class="cx">             g_assert_not_reached();
</span><span class="lines">@@ -231,25 +284,64 @@
</span><span class="cx"> 
</span><span class="cx">     void failed(WebKitDownload* download, GError* error)
</span><span class="cx">     {
</span><del>-        g_assert(g_error_matches(error, WEBKIT_DOWNLOAD_ERROR, m_expectedError));
</del><ins>+        g_assert(g_error_matches(error, WEBKIT_DOWNLOAD_ERROR, expectedErrorToWebKitDownloadError(m_expectedError)));
</ins><span class="cx">         DownloadTest::failed(download, error);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void decideDestination(WebKitDownload* download, const gchar* suggestedFilename)
</span><span class="cx">     {
</span><del>-        if (m_expectedError != WEBKIT_DOWNLOAD_ERROR_DESTINATION) {
</del><ins>+        if (m_expectedError != InvalidDestination) {
</ins><span class="cx">             DownloadTest::decideDestination(download, suggestedFilename);
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         webkit_download_set_destination(download, &quot;file:///foo/bar&quot;);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebKitDownloadError m_expectedError;
</del><ins>+    static WebKitDownloadError expectedErrorToWebKitDownloadError(ExpectedError expected)
+    {
+        switch (expected) {
+        case NetworkError:
+            return WEBKIT_DOWNLOAD_ERROR_NETWORK;
+        case DownloadCancelled:
+            return WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;
+        case InvalidDestination:
+            return WEBKIT_DOWNLOAD_ERROR_DESTINATION;
+        case DestinationExists:
+            return WEBKIT_DOWNLOAD_ERROR_DESTINATION;
+        default:
+            g_assert_not_reached();
+        }
+    }
+
+    ExpectedError m_expectedError;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><ins>+static void testDownloadOverwriteDestinationDisallowed(DownloadErrorTest* test, gconstpointer)
+{
+    static const char* filename = &quot;test.pdf&quot;;
+    createFileAtDestination(filename);
+
+    test-&gt;m_expectedError = DownloadErrorTest::DestinationExists;
+    GUniquePtr&lt;char&gt; sourcePath(g_build_filename(Test::getResourcesDir().data(), filename, nullptr));
+    GRefPtr&lt;GFile&gt; source = adoptGRef(g_file_new_for_path(sourcePath.get()));
+    GUniquePtr&lt;char&gt; sourceURI(g_file_get_uri(source.get()));
+    GRefPtr&lt;WebKitDownload&gt; download = adoptGRef(test-&gt;downloadURIAndWaitUntilFinishes(sourceURI.get()));
+    g_assert(!webkit_download_get_web_view(download.get()));
+
+    Vector&lt;DownloadTest::DownloadEvent&gt;&amp; events = test-&gt;m_downloadEvents;
+    g_assert_cmpint(events.size(), ==, 4);
+    g_assert_cmpint(events[0], ==, DownloadTest::Started);
+    g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse);
+    g_assert_cmpint(events[2], ==, DownloadTest::Failed);
+    g_assert_cmpint(events[3], ==, DownloadTest::Finished);
+    g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 0);
+
+    test-&gt;checkDestinationAndDeleteFile(download.get(), filename);
+}
+
</ins><span class="cx"> static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer)
</span><span class="cx"> {
</span><del>-    test-&gt;m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK;
</del><ins>+    test-&gt;m_expectedError = DownloadErrorTest::NetworkError;
</ins><span class="cx">     GRefPtr&lt;WebKitDownload&gt; download = adoptGRef(test-&gt;downloadURIAndWaitUntilFinishes(&quot;file:///foo/bar&quot;));
</span><span class="cx">     g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx"> 
</span><span class="lines">@@ -261,7 +353,7 @@
</span><span class="cx">     events.clear();
</span><span class="cx">     g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), &lt;, 1);
</span><span class="cx"> 
</span><del>-    test-&gt;m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION;
</del><ins>+    test-&gt;m_expectedError = DownloadErrorTest::InvalidDestination;
</ins><span class="cx">     GUniquePtr&lt;char&gt; path(g_build_filename(Test::getResourcesDir().data(), &quot;test.pdf&quot;, nullptr));
</span><span class="cx">     GRefPtr&lt;GFile&gt; file = adoptGRef(g_file_new_for_path(path.get()));
</span><span class="cx">     GUniquePtr&lt;char&gt; uri(g_file_get_uri(file.get()));
</span><span class="lines">@@ -277,7 +369,7 @@
</span><span class="cx">     g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), &lt;, 1);
</span><span class="cx">     test-&gt;checkDestinationAndDeleteFile(download.get(), &quot;bar&quot;);
</span><span class="cx"> 
</span><del>-    test-&gt;m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;
</del><ins>+    test-&gt;m_expectedError = DownloadErrorTest::DownloadCancelled;
</ins><span class="cx">     download = adoptGRef(test-&gt;downloadURIAndWaitUntilFinishes(uri.get()));
</span><span class="cx">     g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx"> 
</span><span class="lines">@@ -369,7 +461,7 @@
</span><span class="cx"> 
</span><span class="cx"> static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer)
</span><span class="cx"> {
</span><del>-    test-&gt;m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK;
</del><ins>+    test-&gt;m_expectedError = DownloadErrorTest::NetworkError;
</ins><span class="cx">     GRefPtr&lt;WebKitDownload&gt; download = adoptGRef(test-&gt;downloadURIAndWaitUntilFinishes(kServer-&gt;getURIForPath(&quot;/foo&quot;)));
</span><span class="cx">     g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx"> 
</span><span class="lines">@@ -384,7 +476,7 @@
</span><span class="cx">     g_assert_cmpuint(webkit_uri_response_get_status_code(response), ==, 404);
</span><span class="cx">     g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), &lt;, 1);
</span><span class="cx"> 
</span><del>-    test-&gt;m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION;
</del><ins>+    test-&gt;m_expectedError = DownloadErrorTest::InvalidDestination;
</ins><span class="cx">     download = adoptGRef(test-&gt;downloadURIAndWaitUntilFinishes(kServer-&gt;getURIForPath(&quot;/test.pdf&quot;)));
</span><span class="cx">     g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx"> 
</span><span class="lines">@@ -397,7 +489,7 @@
</span><span class="cx">     g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), &lt;, 1);
</span><span class="cx">     test-&gt;checkDestinationAndDeleteFile(download.get(), &quot;bar&quot;);
</span><span class="cx"> 
</span><del>-    test-&gt;m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;
</del><ins>+    test-&gt;m_expectedError = DownloadErrorTest::DownloadCancelled;
</ins><span class="cx">     download = adoptGRef(test-&gt;downloadURIAndWaitUntilFinishes(kServer-&gt;getURIForPath(&quot;/cancel-after-destination&quot;)));
</span><span class="cx">     g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx"> 
</span><span class="lines">@@ -533,6 +625,8 @@
</span><span class="cx">     g_assert(kTempDirectory);
</span><span class="cx"> 
</span><span class="cx">     DownloadTest::add(&quot;Downloads&quot;, &quot;local-file&quot;, testDownloadLocalFile);
</span><ins>+    DownloadTest::add(&quot;Downloads&quot;, &quot;overwrite-destination-allowed&quot;, testDownloadOverwriteDestinationAllowed);
+    DownloadErrorTest::add(&quot;Downloads&quot;, &quot;overwrite-destination-disallowed&quot;, testDownloadOverwriteDestinationDisallowed);
</ins><span class="cx">     DownloadErrorTest::add(&quot;Downloads&quot;, &quot;local-file-error&quot;, testDownloadLocalFileError);
</span><span class="cx">     DownloadTest::add(&quot;Downloads&quot;, &quot;remote-file&quot;, testDownloadRemoteFile);
</span><span class="cx">     DownloadErrorTest::add(&quot;Downloads&quot;, &quot;remote-file-error&quot;, testDownloadRemoteFileError);
</span></span></pre>
</div>
</div>

</body>
</html>