[Download][TDAF-1353] Exception fix for 'start' function 35/251135/1
authorArkadiusz Pietraszek <a.pietraszek@samsung.com>
Thu, 7 Jan 2021 19:32:28 +0000 (20:32 +0100)
committerArkadiusz Pietraszek <a.pietraszek@samsung.com>
Fri, 8 Jan 2021 10:27:36 +0000 (10:27 +0000)
`start` function was returning unknown error exception instead of
unsupported error in case when networkType in DownloadRequest wasn't
supported by the device.

Additionally fix enables null values to be used (in accordance with the documentation).

[Verification] Code builds without errors. TCT suites deprecated, download and systeminfo pass rate: 100%.
Tested in developer console on devices with telephony set to true and false.
Below code was used with all network types, as well as invalid values.
```
var downloadRequest = new tizen.DownloadRequest(
                    "http://download.tizen.org/tct/2_1/webapi-tizen-download-test-image-lq.png",
                    null, null, "CELLULAR", null);

tizen.download.start(downloadRequest);
```

Change-Id: I4f2866a07019f129c852024970783b110ef11abc
Signed-off-by: Arkadiusz Pietraszek <a.pietraszek@samsung.com>
src/download/download_api.js
src/download/download_instance.cc

index 5ea0cf7f5218159960361ea8b6dc4f6af3c12b49..826ab87393ffae156c9514ae728fc8e0601f38b9 100755 (executable)
@@ -90,12 +90,29 @@ tizen.DownloadRequest = function(url, destination, fileName, networkType, httpHe
     validator_.isConstructorCall(this, tizen.DownloadRequest);
 
     var url_ = converter_.toString(url);
-    var destination_ = destination === undefined ? '' : converter_.toString(destination);
-    var fileName_ = fileName === undefined ? '' : converter_.toString(fileName);
+    var destination_;
+
+    if (undefined === destination || null === destination) {
+        destination_ = '';
+    } else {
+        destination_ = converter_.toString(destination);
+    }
+
+    var fileName_;
+
+    if (undefined === fileName || null === fileName) {
+        fileName_ = '';
+    } else {
+        fileName_ = converter_.toString(fileName);
+    }
 
     var networkType_;
 
-    if (networkType === undefined || !(networkType in DownloadNetworkType)) {
+    if (
+        undefined === networkType ||
+        null === networkType ||
+        !(networkType in DownloadNetworkType)
+    ) {
         networkType_ = 'ALL';
     } else {
         networkType_ = networkType;
index 49905f533a677b6a87ec1b08e7db6fc0e8547f4c..3a3b6c3a1349aba32d715407d81378a6a801dc08 100644 (file)
@@ -492,6 +492,8 @@ common::PlatformResult DownloadInstance::CheckNetworkConnection(const std::strin
                                                                 bool& network_support,
                                                                 bool& network_available,
                                                                 DownloadInfoPtr di_ptr) {
+  ScopeLogger("network_type: %s", network_type.c_str());
+
   connection_h connection = nullptr;
   int ret = connection_create(&connection);
   CHECK_CONNECTION_ERROR(ret)
@@ -503,11 +505,6 @@ common::PlatformResult DownloadInstance::CheckNetworkConnection(const std::strin
   ret = connection_get_type(connection, &connection_type);
   CHECK_CONNECTION_ERROR(ret)
 
-  if (CONNECTION_TYPE_DISCONNECTED == connection_type) {
-    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occurred",
-                              ("Connection type is disconnected"));
-  }
-
   if ("CELLULAR" == network_type) {
     // check if connection type is supported
     bool cell_support = false;
@@ -549,6 +546,10 @@ common::PlatformResult DownloadInstance::CheckNetworkConnection(const std::strin
         "The input parameter contains an invalid network type.",
         ("The input parameter contains an invalid network type: %s", network_type.c_str()));
   }
+  if (CONNECTION_TYPE_DISCONNECTED == connection_type) {
+    return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occurred",
+                              ("Connection type is disconnected"));
+  }
   return common::PlatformResult(common::ErrorCode::NO_ERROR);
 }
 #undef CHECK_CONNECTION_ERROR