shill: Connection: Do non-empty tests independently for DNS search

Before this change, the DNS domain search was overridden if the
DNS server paramater was non-empty.  Change this so that it is
only overridden if the derived DNS domain search list is non-empty.
This is due to reports that on DHCP renewal some servers return
a non-empty server list but do not renew the DNS domain value.

BUG=chromium-os:34260
TEST=Rerun unit tests.

Change-Id: I0f95808011e13095e467c1440dce7a13059075ad
Reviewed-on: https://gerrit.chromium.org/gerrit/32952
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/connection.cc b/connection.cc
index 07f6ea4..4e18521 100644
--- a/connection.cc
+++ b/connection.cc
@@ -18,6 +18,7 @@
 using base::Unretained;
 using std::deque;
 using std::string;
+using std::vector;
 
 namespace shill {
 
@@ -174,14 +175,17 @@
   // Install any explicitly configured routes at the default metric.
   routing_table_->ConfigureRoutes(interface_index_, config, kDefaultMetric);
 
-  // Save a copy of the last non-null DNS config
+  // Save a copy of the last non-null DNS config.
   if (!config->properties().dns_servers.empty()) {
     dns_servers_ = config->properties().dns_servers;
+  }
+
+  if (!config->properties().domain_search.empty()) {
     dns_domain_search_ = config->properties().domain_search;
-    if (dns_domain_search_.empty() &&
-        !config->properties().domain_name.empty()) {
-      dns_domain_search_.push_back(config->properties().domain_name + ".");
-    }
+  }
+
+  if (!config->properties().domain_name.empty()) {
+    dns_domain_name_ = config->properties().domain_name;
   }
 
   ipconfig_rpc_identifier_ = config->GetRpcIdentifier();
@@ -208,7 +212,11 @@
   is_default_ = is_default;
 
   if (is_default) {
-    resolver_->SetDNSFromLists(dns_servers_, dns_domain_search_,
+    vector<string> domain_search = dns_domain_search_;
+    if (domain_search.empty() && !dns_domain_name_.empty()) {
+      domain_search.push_back(dns_domain_name_ + ".");
+    }
+    resolver_->SetDNSFromLists(dns_servers_, domain_search,
                                dns_timeout_parameters_);
     DeviceRefPtr device = device_info_->GetDevice(interface_index_);
     if (device) {