[Xfce4-commits] <midori:master> Fix download tooltip crash and extend test case

Christian Dywan noreply at xfce.org
Sat Apr 20 02:48:01 CEST 2013


Updating branch refs/heads/master
         to 33e562f96ddab048310a4ef83e6146f2ec6092c5 (commit)
       from bf13e2347eca986160d5d8901d667bad4583dd73 (commit)

commit 33e562f96ddab048310a4ef83e6146f2ec6092c5
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Apr 20 02:17:10 2013 +0200

    Fix download tooltip crash and extend test case

 midori/midori-download.vala |    4 +-
 tests/download.vala         |   71 ++++++++++++++++++++++++++++++++----------
 2 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/midori/midori-download.vala b/midori/midori-download.vala
index bbf485e..51274e9 100644
--- a/midori/midori-download.vala
+++ b/midori/midori-download.vala
@@ -98,7 +98,7 @@ namespace Midori {
 
             string speed = "";
             uint64? last_size = download.get_data<uint64?> ("last-size");
-            if (elapsed != last_time) {
+            if (last_size != null && elapsed != last_time) {
                 speed = format_size ((uint64)(
                     (current_size - last_size) / (elapsed - last_time)));
             }
@@ -108,7 +108,7 @@ namespace Midori {
             /* i18n: Download tooltip (transfer rate): (130KB/s) */
             speed = _(" (%s/s)").printf (speed);
 
-            if (elapsed - last_time > 5.0) {
+            if (elapsed - last_time > 0.0) {
                 download.set_data<int> ("last-time", (int)elapsed);
                 download.set_data<uint64?> ("last-size", current_size);
             }
diff --git a/tests/download.vala b/tests/download.vala
index 8ef8899..a5b4dcf 100644
--- a/tests/download.vala
+++ b/tests/download.vala
@@ -69,39 +69,76 @@ static void download_unique () {
 }
 
 void download_properties () {
+    var test_address = new Soup.Address ("127.0.0.1", Soup.ADDRESS_ANY_PORT);
+    test_address.resolve_sync (null);
+    var test_server = new Soup.Server ("interface", test_address, null);
+    string test_url = "http://127.0.0.1:%u".printf (test_server.get_port ());
+    test_server.run_async ();
+    test_server.add_handler ("/", (server, msg, path, query, client)=>{
+        Thread.usleep (1000000); /* 1 seconds in µs */
+        if ("/not_found/" in path)
+            msg.set_status (404);
+        else
+            msg.set_status (200);
+        msg.set_response ("text/html", Soup.MemoryUse.COPY, "<body></body>".data);
+        });
+
+    string was_found_url = test_url + "/cat.png";
+    string not_found_url = test_url + "/not_found/dog.png";
 #if HAVE_WEBKIT2
-    var download = WebKit.WebContext.get_default ().download_uri ("file:///klaatu/barada/nikto.ogg");
+    var download = WebKit.WebContext.get_default ().download_uri (was_found_url);
 #else
-    var download = new WebKit.Download (new WebKit.NetworkRequest ("file:///klaatu/barada/nikto.ogg"));
+    var download = new WebKit.Download (new WebKit.NetworkRequest (was_found_url));
 #endif
     assert (Midori.Download.get_type (download) == 0);
     Midori.Download.set_type (download, Midori.DownloadType.OPEN);
     assert (Midori.Download.get_type (download) == Midori.DownloadType.OPEN);
     assert (Midori.Download.get_progress (download) == 0.0);
 
+    string filename, uri;
     try {
-        string filename;
         FileUtils.close (FileUtils.open_tmp ("XXXXXX", out filename));
+        uri = Filename.to_uri (filename, null);
+    }
+    catch (Error error) {
+        GLib.error (error.message);
+    }
+
 #if HAVE_WEBKIT2
-        download.set_destination (Filename.to_uri (filename, null));
+    download.set_destination (uri);
 #else
-        download.destination_uri = Filename.to_uri (filename, null);
-        download.start ();
+    download.destination_uri = uri;
+    download.start ();
 #endif
-        string tee = Midori.Download.get_tooltip (download);
-        assert (Midori.Download.get_progress (download) == 0.0);
-        var loop = MainContext.default ();
-        do { loop.iteration (true); } while (loop.pending ());
+    string tee = Midori.Download.get_tooltip (download);
+    assert (tee.contains (Path.get_basename (filename)));
+    assert (Midori.Download.get_progress (download) == 0.0);
+
+    download.notify["progress"].connect ((pspec) => {
         string tee2 = Midori.Download.get_tooltip (download);
-        assert (tee2.contains (tee));
-        do { loop.iteration (true); } while (!Midori.Download.is_finished (download));
+        assert (tee2.contains (Path.get_basename (filename)));
+    });
+    var loop = MainContext.default ();
+    do { loop.iteration (true); } while (!Midori.Download.is_finished (download));
 #if !HAVE_WEBKIT2
-        assert (download.status == WebKit.DownloadStatus.ERROR);
+    assert (download.status == WebKit.DownloadStatus.FINISHED);
+#endif
+
+#if HAVE_WEBKIT2
+    download = WebKit.WebContext.get_default ().download_uri (not_found_url);
+#else
+    download = new WebKit.Download (new WebKit.NetworkRequest (not_found_url));
+#endif
+#if HAVE_WEBKIT2
+    download.set_destination (uri);
+#else
+    download.destination_uri = uri;
+    download.start ();
+#endif
+    do { loop.iteration (true); } while (!Midori.Download.is_finished (download));
+#if !HAVE_WEBKIT2
+    assert (download.status == WebKit.DownloadStatus.ERROR);
 #endif
-    }
-    catch (Error error) {
-        GLib.error (error.message);
-    }
 }
 
 void main (string[] args) {


More information about the Xfce4-commits mailing list