shill: Service: Prefer Online to Connected

This change allows services that are online but still executing
portal detection to remain non-default while portal detection is
still being executed.  This eliminates network disruptions when
higher priority technologies are attached to networks that do
not supply upstream connectivity.  For example, if connected to
a working WiFi, and Ethernet is attached, connectivity will not
be switched until portal detection completes successfully.

Before this change, Ethernet would become default temporarily
until it was discovered that we were in portal mode.  The upside
of this change is large (due to the length of time it takes to
fail portal detection) and the downside is small (successful
portal detection usually does not take long).

BUG=chromium:515570
TEST=Unit tests + manual -- connect to WiFi, then attach
TEST=Ethernet to a router with no upstream connectivity.

Change-Id: I4a6eab276400e6e945cc8cba94b10425aefc2770
Reviewed-on: https://chromium-review.googlesource.com/289812
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/service_unittest.cc b/service_unittest.cc
index 28002c0..afda25c 100644
--- a/service_unittest.cc
+++ b/service_unittest.cc
@@ -2320,6 +2320,11 @@
       .WillRepeatedly(Return(true));
   EXPECT_TRUE(DefaultSortingOrderIs(service10, service2));
 
+  // Online preferred over just connected.
+  EXPECT_CALL(*service2.get(), state())
+      .WillRepeatedly(Return(Service::kStateOnline));
+  EXPECT_TRUE(DefaultSortingOrderIs(service10, service2));
+
   // Connectivity state ignored if this is specified.
   const bool kDoNotCompareConnectivityState = false;
   EXPECT_TRUE(SortingOrderIs(service2, service10,