Use the socket factory for direct connections as well.

Currently, the passed-in socket factory is only used for
connections to HTTP proxies. I think this was not the intent of
the original socket factory change, because the commit message
said that the "socket factory will be used for all non-proxy
connections and HTTP proxy connections".  So use it for DIRECT
connections as well.

Also add a test to check that a socket factory is used if
specified.

Change-Id: I811b08442d1c80be1a0a268eb51c9aa365febf00