shill: make http_proxy unittests compile and run with clang

The HTTPProxy object in the test fixture references the |sockets_|
field of the test fixture. The HTTPProxy dtor, uses its reference to
|sockets_| to close some sockets before going away.

Unfortunately, though, the HTTPProxy object was declared before
|sockets_|. Hence, it could be calling Close on garbage (rather
than MockSockets).

Fix the problem by reordering the declarations. Update EXPECTations
accordingly.

While there: fix a similar problem in openvpn_management_server
unittests.

BUG=chromium:238790
TEST=manual

manual test
-----------
$ make clean && FEATURES=test USE=clang cros_workon_make --board=link --test --reconf shill
$ make clean && FEATURES=test cros_workon_make --board=link --test --reconf shill

Both commands should run successfully (tests pass, no crashes)

Change-Id: I2a7b6b4e831b5ac0854735c3c7caee9b48e08e9b
Reviewed-on: https://gerrit.chromium.org/gerrit/50546
Commit-Queue: mukesh agrawal <quiche@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/http_proxy_unittest.cc b/http_proxy_unittest.cc
index d814dfe..71e3509 100644
--- a/http_proxy_unittest.cc
+++ b/http_proxy_unittest.cc
@@ -117,6 +117,16 @@
     if (proxy_.sockets_) {
       ExpectStop();
     }
+    const int proxy_fds[] = {
+      proxy_.client_socket_,
+      proxy_.server_socket_,
+      proxy_.proxy_socket_
+    };
+    for (const int fd : proxy_fds) {
+      if (fd != -1) {
+        EXPECT_CALL(sockets_, Close(fd));
+      }
+    }
   }
   string CreateRequest(const string &url, const string &http_version,
                        const string &extra_lines) {
@@ -450,8 +460,8 @@
   MockControl control_;
   scoped_ptr<MockDeviceInfo> device_info_;
   scoped_refptr<MockConnection> connection_;
-  HTTPProxy proxy_;
   StrictMock<MockSockets> sockets_;
+  HTTPProxy proxy_;  // Destroy first, before anything it references.
 };
 
 TEST_F(HTTPProxyTest, StartFailSocket) {
diff --git a/openvpn_management_server_unittest.cc b/openvpn_management_server_unittest.cc
index cc472a7..5aae991 100644
--- a/openvpn_management_server_unittest.cc
+++ b/openvpn_management_server_unittest.cc
@@ -143,9 +143,9 @@
 
   GLib glib_;
   MockOpenVPNDriver driver_;
-  OpenVPNManagementServer server_;
   MockSockets sockets_;
   MockEventDispatcher dispatcher_;
+  OpenVPNManagementServer server_;  // Destroy before anything it references.
 };
 
 // static