Avoid DCHECK on SpdySessionPool destruction.

It is possible that a DCHECK in SpdySession::DcheckDraining() is
triggered when SpdySessionPool destructor call
SpdySessionPool::RemoveUnavailableSession() which destroys the
SpdySession, if the SpdySession is in STATE_GOING_AWAY.

One way for this is that on certain platforms,
SpdySessionPool::OnIPAddressChanged() may leave a SpdySession with an
active stream in STATE_GOING_AWAY.

Another possible way is receiving a "graceful GOAWAY" from the server,
which also puts a SpdySession with active streams in STATE_GOING_AWAY.

Patch set 1 introduces two unit tests, one for each of the above
scenarios, that trigger this DCHECK.  See trybot outputs for failing
tests.

Patch set 2 fixes the bug by ensuring in
SpdySessionPool::CloseAllSessions() that every owned SpdySession is
draining, even if there are no currently active sessions. This method
is not only called by SpdySessionPool destructor, but also by
HttpNetworkSession destructor (also adding a TODO for that).

Also include build/build_config.h for OS_ANDROID, OS_WIN, OS_IOS macros.

Bug: 789791
Change-Id: Idc3e2350b2ac6354be5c5e6b32ea8e0227f3e2d6
Reviewed-on: https://chromium-review.googlesource.com/810889
Reviewed-by: Helen Li <[email protected]>
Commit-Queue: Bence Béky <[email protected]>
Cr-Commit-Position: refs/heads/master@{#523186}
diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc
index bcced4e..cb75df0 100644
--- a/net/http/http_network_session.cc
+++ b/net/http/http_network_session.cc
@@ -256,6 +256,8 @@
 HttpNetworkSession::~HttpNetworkSession() {
   DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
   response_drainers_.clear();
+  // TODO(bnc): CloseAllSessions() is also called in SpdySessionPool destructor,
+  // one of the two calls should be removed.
   spdy_session_pool_.CloseAllSessions();
   base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
 }