Fix some flaky tests by using longer timeout and/or fake clock.
Also use const variables for timeout values.

BUG=webrtc:6500
R=deadbeef@webrtc.org

Review URL: https://codereview.webrtc.org/2431473004 .

Cr-Commit-Position: refs/heads/master@{#14711}
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index 7e65b4b..d367d26 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -41,6 +41,8 @@
 // Default timeout for tests in this file.
 // Should be large enough for slow buildbots to run the tests reliably.
 static const int kDefaultTimeout = 10000;
+static const int kMediumTimeout = 3000;
+static const int kShortTimeout = 1000;
 
 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
                                    cricket::PORTALLOCATOR_DISABLE_RELAY |
@@ -543,14 +545,11 @@
 
     // Create the channels and wait for them to connect.
     CreateChannels();
-    EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL &&
-                            ep2_ch1() != NULL &&
-                            ep1_ch1()->receiving() &&
-                            ep1_ch1()->writable() &&
-                            ep2_ch1()->receiving() &&
-                            ep2_ch1()->writable(),
-                            expected.connect_wait,
-                            1000);
+    EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
+                                ep1_ch1()->receiving() &&
+                                ep1_ch1()->writable() &&
+                                ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                            expected.connect_wait, kShortTimeout);
     connect_time = rtc::TimeMillis() - connect_start;
     if (connect_time < expected.connect_wait) {
       LOG(LS_INFO) << "Connect time: " << connect_time << " ms";
@@ -596,10 +595,12 @@
       const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
       int len = static_cast<int>(strlen(data));
       // local_channel1 <==> remote_channel1
-      EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), 1000);
-      EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len), 1000);
-      EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), 1000);
-      EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len), 1000);
+      EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), kMediumTimeout);
+      EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len),
+                       kMediumTimeout);
+      EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), kMediumTimeout);
+      EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len),
+                       kMediumTimeout);
     }
   }
 
@@ -612,8 +613,8 @@
     ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
     ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
     EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                            ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                            1000, 1000);
+                                ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                            kShortTimeout, kShortTimeout);
 
     const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
     const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
@@ -629,17 +630,17 @@
     ep2_ch1()->MaybeStartGathering();
 
     EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() !=
-                            old_local_candidate1->generation(),
-                            1000, 1000);
+                                old_local_candidate1->generation(),
+                            kShortTimeout, kShortTimeout);
     EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() !=
-                            old_local_candidate2->generation(),
-                            1000, 1000);
+                                old_local_candidate2->generation(),
+                            kShortTimeout, kShortTimeout);
     EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() !=
-                            old_remote_candidate1->generation(),
-                            1000, 1000);
+                                old_remote_candidate1->generation(),
+                            kShortTimeout, kShortTimeout);
     EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() !=
-                            old_remote_candidate2->generation(),
-                            1000, 1000);
+                                old_remote_candidate2->generation(),
+                            kShortTimeout, kShortTimeout);
     EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation());
     EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation());
   }
@@ -655,14 +656,12 @@
     CreateChannels();
     // Since both the channels initiated with controlling state and channel2
     // has higher tiebreaker value, channel1 should receive SignalRoleConflict.
-    EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000);
+    EXPECT_TRUE_WAIT(GetRoleConflict(0), kShortTimeout);
     EXPECT_FALSE(GetRoleConflict(1));
 
-    EXPECT_TRUE_WAIT(ep1_ch1()->receiving() &&
-                     ep1_ch1()->writable() &&
-                     ep2_ch1()->receiving() &&
-                     ep2_ch1()->writable(),
-                     1000);
+    EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
+                         ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                     kShortTimeout);
 
     EXPECT_TRUE(ep1_ch1()->selected_connection() &&
                 ep2_ch1()->selected_connection());
@@ -1160,8 +1159,8 @@
                      kDefaultPortAllocatorFlags);
   CreateChannels();
   EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                          ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                          1000, 1000);
+                              ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                          kShortTimeout, kShortTimeout);
   TestSendRecv();
   ConnectionInfos infos;
   ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
@@ -1366,7 +1365,7 @@
 
   // Wait until the callee becomes writable to make sure that a ping request is
   // received by the caller before his remote ICE credentials are set.
-  ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000);
+  ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout);
   // Add two sets of remote ICE credentials, so that the ones used by the
   // candidate will be generation 1 instead of 0.
   ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
@@ -1376,7 +1375,7 @@
   const Connection* selected_connection = nullptr;
   ASSERT_TRUE_WAIT(
       (selected_connection = ep1_ch1()->selected_connection()) != nullptr,
-      2000);
+      kMediumTimeout);
   EXPECT_EQ("prflx", selected_connection->remote_candidate().type());
   EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username());
   EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password());
@@ -1386,7 +1385,7 @@
   // Verify ep1's selected connection is updated to use the 'local' candidate.
   EXPECT_EQ_WAIT("local",
                  ep1_ch1()->selected_connection()->remote_candidate().type(),
-                 2000);
+                 kMediumTimeout);
   EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
   DestroyChannels();
 }
@@ -1407,7 +1406,7 @@
 
   // Wait until the callee becomes writable to make sure that a ping request is
   // received by the caller before his remote ICE credentials are set.
-  ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000);
+  ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout);
   // Add two sets of remote ICE credentials, so that the ones used by the
   // candidate will be generation 1 instead of 0.
   ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
@@ -1418,7 +1417,7 @@
   const Connection* selected_connection = nullptr;
   ASSERT_TRUE_WAIT(
       (selected_connection = ep1_ch1()->selected_connection()) != nullptr,
-      2000);
+      kMediumTimeout);
   EXPECT_EQ("prflx", selected_connection->remote_candidate().type());
   EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username());
   EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password());
@@ -1428,7 +1427,7 @@
 
   EXPECT_EQ_WAIT("prflx",
                  ep1_ch1()->selected_connection()->remote_candidate().type(),
-                 2000);
+                 kMediumTimeout);
   EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
   DestroyChannels();
 }
@@ -1495,15 +1494,19 @@
 
 // Test that if remote candidates don't have ufrag and pwd, we still work.
 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
+  rtc::ScopedFakeClock clock;
   set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
   ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
                      kDefaultPortAllocatorFlags);
   CreateChannels();
   const Connection* selected_connection = NULL;
   // Wait until the callee's connections are created.
-  WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000);
-  // Wait to see if they get culled; they shouldn't.
-  WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000);
+  EXPECT_TRUE_SIMULATED_WAIT(
+      (selected_connection = ep2_ch1()->selected_connection()) != NULL,
+      kMediumTimeout, clock);
+  // Wait to make sure the selected connection is not changed.
+  SIMULATED_WAIT(ep2_ch1()->selected_connection() != selected_connection,
+                 kShortTimeout, clock);
   EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection);
   DestroyChannels();
 }
@@ -1519,7 +1522,7 @@
   ep1_ch1()->set_incoming_only(true);
 
   // Pump for 1 second and verify that the channels are not connected.
-  rtc::Thread::Current()->ProcessMessages(1000);
+  rtc::Thread::Current()->ProcessMessages(kShortTimeout);
 
   EXPECT_FALSE(ep1_ch1()->receiving());
   EXPECT_FALSE(ep1_ch1()->writable());
@@ -1540,9 +1543,9 @@
   ep1_ch1()->set_incoming_only(true);
 
   EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
-                          ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                          ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                          1000, 1000);
+                              ep1_ch1()->receiving() && ep1_ch1()->writable() &&
+                              ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                          kShortTimeout, kShortTimeout);
 
   DestroyChannels();
 }
@@ -1583,8 +1586,8 @@
   ResumeCandidates(1);
 
   EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                   ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                   1000);
+                       ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                   kShortTimeout);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
@@ -1615,7 +1618,7 @@
 
   CreateChannels();
 
-  EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000);
+  EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), kShortTimeout);
 
   const std::vector<PortInterface*> ports_before = ep1_ch1()->ports();
   for (size_t i = 0; i < ports_before.size(); ++i) {
@@ -1634,11 +1637,9 @@
     EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker());
   }
 
-  EXPECT_TRUE_WAIT(ep1_ch1()->receiving() &&
-                   ep1_ch1()->writable() &&
-                   ep2_ch1()->receiving() &&
-                   ep2_ch1()->writable(),
-                   1000);
+  EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
+                       ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                   kShortTimeout);
 
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection());
@@ -1692,8 +1693,8 @@
   CreateChannels();
 
   EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                   ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                   1000);
+                       ep2_ch1()->receiving() && ep2_ch1()->writable(),
+                   kShortTimeout);
   EXPECT_TRUE(
       ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
       LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) &&
@@ -1718,7 +1719,7 @@
 
   EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                        ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                   2000);
+                   kMediumTimeout);
 
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection());
@@ -1735,6 +1736,7 @@
 // Test that if continual gathering is set to true, ICE gathering state will
 // not change to "Complete", and vice versa.
 TEST_F(P2PTransportChannelTest, TestContinualGathering) {
+  rtc::ScopedFakeClock clock;
   ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
                      kDefaultPortAllocatorFlags);
   SetAllocationStepDelay(0, kDefaultStepDelay);
@@ -1745,12 +1747,14 @@
   IceConfig default_config;
   CreateChannels(continual_gathering_config, default_config);
 
-  EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
-                              ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                              ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                          1000, 1000);
-  WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(),
-       1000);
+  EXPECT_TRUE_SIMULATED_WAIT(
+      ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
+          ep1_ch1()->writable() && ep2_ch1()->receiving() &&
+          ep2_ch1()->writable(),
+      kMediumTimeout, clock);
+  SIMULATED_WAIT(
+      IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(),
+      kShortTimeout, clock);
   EXPECT_EQ(IceGatheringState::kIceGatheringGathering,
             ep1_ch1()->gathering_state());
   // By now, ep2 should have completed gathering.
@@ -1763,6 +1767,7 @@
 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
 // PortAllocatorSession that has not yet finished gathering candidates.
 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) {
+  rtc::ScopedFakeClock clock;
   ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
                      kDefaultPortAllocatorFlags);
   // First create a pooled session for each endpoint.
@@ -1786,10 +1791,11 @@
   EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty());
   // Now let the endpoints connect and try exchanging some data.
   CreateChannels();
-  EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
-                              ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                              ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                          1000, 1000);
+  EXPECT_TRUE_SIMULATED_WAIT(
+      ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
+          ep1_ch1()->writable() && ep2_ch1()->receiving() &&
+          ep2_ch1()->writable(),
+      kMediumTimeout, clock);
   TestSendRecv();
   // Make sure the P2PTransportChannels are actually using ports from the
   // pooled sessions.
@@ -1806,6 +1812,7 @@
 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
 // PortAllocatorSession that already finished gathering candidates.
 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) {
+  rtc::ScopedFakeClock clock;
   ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
                      kDefaultPortAllocatorFlags);
   // First create a pooled session for each endpoint.
@@ -1824,15 +1831,16 @@
   ASSERT_NE(nullptr, pooled_session_2);
   // Wait for the pooled sessions to finish gathering before the
   // P2PTransportChannels try to use them.
-  EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() &&
-                       pooled_session_2->CandidatesAllocationDone(),
-                   kDefaultTimeout);
+  EXPECT_TRUE_SIMULATED_WAIT(pooled_session_1->CandidatesAllocationDone() &&
+                                 pooled_session_2->CandidatesAllocationDone(),
+                             kDefaultTimeout, clock);
   // Now let the endpoints connect and try exchanging some data.
   CreateChannels();
-  EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
-                              ep1_ch1()->receiving() && ep1_ch1()->writable() &&
-                              ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                          1000, 1000);
+  EXPECT_TRUE_SIMULATED_WAIT(
+      ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
+          ep1_ch1()->writable() && ep2_ch1()->receiving() &&
+          ep2_ch1()->writable(),
+      kMediumTimeout, clock);
   TestSendRecv();
   // Make sure the P2PTransportChannels are actually using ports from the
   // pooled sessions.
@@ -1918,7 +1926,7 @@
 
   // Wait for the TURN<->prflx connection.
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(),
-                             1000, fake_clock);
+                             kShortTimeout, fake_clock);
   ASSERT_NE(nullptr, ep1_ch1()->selected_connection());
   EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
   EXPECT_EQ(PRFLX_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
@@ -1927,8 +1935,8 @@
   EXPECT_FALSE(ep1_ch1()->selected_connection()->writable());
 
   // Now wait for it to actually become writable.
-  EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->writable(), 1000,
-                             fake_clock);
+  EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->writable(),
+                             kShortTimeout, fake_clock);
 
   // Explitly destroy channels, before fake clock is destroyed.
   DestroyChannels();
@@ -1957,12 +1965,13 @@
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable() &&
                                  ep2_ch1()->selected_connection()->writable(),
-                             1000, fake_clock);
+                             kShortTimeout, fake_clock);
   const Connection* old_selected_connection = ep1_ch1()->selected_connection();
   // Destroy the second channel and wait for the current connection on the
   // first channel to become "unreliable", making it no longer writable.
   GetEndpoint(1)->cd1_.ch_.reset();
-  EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), 10000, fake_clock);
+  EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), kDefaultTimeout,
+                             fake_clock);
   EXPECT_NE(nullptr, ep1_ch1()->selected_connection());
   // Add a remote TURN candidate. The first channel should still have a TURN
   // port available to make a TURN<->TURN pair that's presumed writable.
@@ -2117,7 +2126,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
@@ -2132,13 +2141,13 @@
   // We should detect loss of receiving within 1 second or so.
   EXPECT_TRUE_SIMULATED_WAIT(
       !selected_connection1->receiving() && !selected_connection2->receiving(),
-      3000, clock);
+      kMediumTimeout, clock);
 
   // We should switch over to use the alternate addr on both sides
   // when we are not receiving.
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
                                  ep2_ch1()->selected_connection()->receiving(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
   EXPECT_TRUE(
       RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]));
@@ -2169,7 +2178,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
@@ -2184,13 +2193,13 @@
   // We should detect loss of receiving within 1 second or so.
   EXPECT_TRUE_SIMULATED_WAIT(
       !selected_connection1->receiving() && !selected_connection2->receiving(),
-      3000, clock);
+      kMediumTimeout, clock);
 
   // We should switch over to use the alternate addr on both sides
   // when we are not receiving.
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
                                  ep2_ch1()->selected_connection()->receiving(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(
     LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
   EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
@@ -2224,7 +2233,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE_SIMULATED_WAIT(
       ep2_ch1()->selected_connection()->remote_nomination() > 0 &&
           ep1_ch1()->selected_connection()->acked_nomination() > 0,
@@ -2236,7 +2245,7 @@
   // |selected_connection2| should not be nominated any more since the previous
   // nomination has been acknowledged.
   ConnectSignalNominated(selected_connection2);
-  SIMULATED_WAIT(nominated(), 3000, clock);
+  SIMULATED_WAIT(nominated(), kMediumTimeout, clock);
   EXPECT_FALSE(nominated());
 
   // Blackhole any traffic to or from the public addrs.
@@ -2245,7 +2254,8 @@
 
   // The selected connection on the controlling side should switch.
   EXPECT_TRUE_SIMULATED_WAIT(
-      ep1_ch1()->selected_connection() != selected_connection1, 3000, clock);
+      ep1_ch1()->selected_connection() != selected_connection1, kMediumTimeout,
+      clock);
   // The connection on the controlled side should be nominated again
   // and have an increased nomination.
   EXPECT_TRUE_SIMULATED_WAIT(
@@ -2280,7 +2290,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
@@ -2302,7 +2312,7 @@
   // We should detect loss of receiving within 1 second or so.
   EXPECT_TRUE_SIMULATED_WAIT(
       !selected_connection1->receiving() && !selected_connection2->receiving(),
-      3000, clock);
+      kMediumTimeout, clock);
   // After a short while, the link recovers itself.
   SIMULATED_WAIT(false, 10, clock);
   fw()->ClearRules();
@@ -2311,7 +2321,7 @@
   // switches should have happened.
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
                                  ep2_ch1()->selected_connection()->receiving(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
   EXPECT_TRUE(LocalCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[1]));
   EXPECT_EQ(0, reset_selected_candidate_pair_switches());
@@ -2339,7 +2349,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
@@ -2360,7 +2370,7 @@
   // We should detect loss of receiving within 1 second or so.
   EXPECT_TRUE_SIMULATED_WAIT(
       !selected_connection1->receiving() && !selected_connection2->receiving(),
-      3000, clock);
+      kMediumTimeout, clock);
   // The link recovers after a short while.
   SIMULATED_WAIT(false, 10, clock);
   fw()->ClearRules();
@@ -2369,7 +2379,7 @@
   // dampening.
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
                                  ep2_ch1()->selected_connection()->receiving(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
   EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0]));
   EXPECT_EQ(0, reset_selected_candidate_pair_switches());
@@ -2404,7 +2414,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE_SIMULATED_WAIT(
       ep1_ch1()->selected_connection() &&
           LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
@@ -2416,7 +2426,8 @@
   // After a short while, the backup connection will be writable but not
   // receiving because backup connection is pinged at a slower rate.
   EXPECT_TRUE_SIMULATED_WAIT(
-      backup_conn->writable() && !backup_conn->receiving(), 5000, clock);
+      backup_conn->writable() && !backup_conn->receiving(), kDefaultTimeout,
+      clock);
   reset_selected_candidate_pair_switches();
   // Blackhole any traffic to or from the remote WiFi networks.
   LOG(LS_INFO) << "Failing over...";
@@ -2520,10 +2531,11 @@
   const std::vector<Connection*>& connections = ep2_ch1()->connections();
   ASSERT_EQ(2U, connections.size());
   Connection* backup_conn = connections[1];
-  EXPECT_TRUE_WAIT(backup_conn->writable(), 3000);
+  EXPECT_TRUE_WAIT(backup_conn->writable(), kMediumTimeout);
   int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
   EXPECT_TRUE_WAIT(
-      last_ping_response_ms < backup_conn->last_ping_response_received(), 5000);
+      last_ping_response_ms < backup_conn->last_ping_response_received(),
+      kDefaultTimeout);
   int time_elapsed =
       backup_conn->last_ping_response_received() - last_ping_response_ms;
   LOG(LS_INFO) << "Time elapsed: " << time_elapsed;
@@ -2533,6 +2545,7 @@
 }
 
 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) {
+  rtc::ScopedFakeClock clock;
   AddAddress(0, kAlternateAddrs[0]);
   AddAddress(0, kPublicAddrs[0]);
   AddAddress(1, kPublicAddrs[1]);
@@ -2540,10 +2553,10 @@
   CreateChannels();
 
   // Both transport channels will reach STATE_COMPLETED quickly.
-  EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(),
-                 1000);
-  EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(),
-                 1000);
+  EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED,
+                           ep1_ch1()->GetState(), kShortTimeout, clock);
+  EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED,
+                           ep2_ch1()->GetState(), kShortTimeout, clock);
 }
 
 // Tests that when a network interface becomes inactive, if Continual Gathering
@@ -2657,7 +2670,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(
       ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
       LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
@@ -2672,7 +2685,7 @@
       ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
           LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
           RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
-      3000, clock);
+      kMediumTimeout, clock);
 
   // Remove one address first and then add another address.
   LOG(LS_INFO) << "Draining again...";
@@ -2682,7 +2695,7 @@
       ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
           LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
           RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]),
-      3000, clock);
+      kMediumTimeout, clock);
 
   DestroyChannels();
 }
@@ -2713,7 +2726,7 @@
   CreateChannels(config, config);
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                               ep2_ch1()->receiving() && ep2_ch1()->writable(),
-                          3000, clock);
+                          kMediumTimeout, clock);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
@@ -2729,7 +2742,7 @@
       ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
           LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) &&
           RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
-      3000, clock);
+      kMediumTimeout, clock);
 
   DestroyChannels();
 }
@@ -2755,7 +2768,7 @@
   EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
                                  ep2_ch1()->receiving() &&
                                  ep2_ch1()->writable(),
-                             3000, clock);
+                             kMediumTimeout, clock);
   EXPECT_TRUE(ep1_ch1()->selected_connection() &&
               ep2_ch1()->selected_connection() &&
               LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
@@ -2772,7 +2785,7 @@
       (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) !=
               nullptr &&
           conn != ep1_ch1()->selected_connection() && conn->writable(),
-      5000, clock);
+      kDefaultTimeout, clock);
 
   DestroyChannels();
 }
@@ -2805,10 +2818,11 @@
                                   int port_num,
                                   rtc::FakeClock* clock = nullptr) {
     if (clock == nullptr) {
-      EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
+      EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
+                       kMediumTimeout);
     } else {
       EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
-                                 3000, *clock);
+                                 kMediumTimeout, *clock);
     }
     return GetConnectionTo(ch, ip, port_num);
   }
@@ -2863,7 +2877,8 @@
     channel.AddRemoteCandidate(
         CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority));
     EXPECT_TRUE_SIMULATED_WAIT(
-        GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock);
+        GetConnectionTo(&channel, ip_addr, port) != nullptr, kMediumTimeout,
+        clock);
     Connection* conn = GetConnectionTo(&channel, ip_addr, port);
 
     if (conn && writable) {
@@ -3020,7 +3035,8 @@
   start = clock.TimeNanos();
   // The connection becomes strong but not stable because we haven't been able
   // to converge the RTT.
-  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
+  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
+                 clock);
   ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
   EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
   EXPECT_LE(ping_interval_ms,
@@ -3035,7 +3051,8 @@
   }
   ping_sent_before = conn->num_pings_sent();
   start = clock.TimeNanos();
-  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
+  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
+                 clock);
   ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
   EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
   EXPECT_LE(ping_interval_ms,
@@ -3049,20 +3066,22 @@
   start = clock.TimeNanos();
   // In-flight ping timeout and the connection will be unstable.
   SIMULATED_WAIT(
-      !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000,
-      clock);
+      !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec),
+      kMediumTimeout, clock);
   int64_t duration_ms =
       (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
   EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE);
   EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE);
   // The connection become unstable due to not receiving ping responses.
   ping_sent_before = conn->num_pings_sent();
-  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
+  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
+                 clock);
   // The interval is expected to be
   // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL.
   start = clock.TimeNanos();
   ping_sent_before = conn->num_pings_sent();
-  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
+  SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
+                 clock);
   ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
   EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
   EXPECT_LE(ping_interval_ms,
@@ -3207,7 +3226,7 @@
       CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2]));
   Connection* conn3 = nullptr;
   ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
-                   3000);
+                   kMediumTimeout);
   const Candidate& new_candidate = conn3->remote_candidate();
   EXPECT_EQ(kIcePwd[2], new_candidate.password());
   EXPECT_EQ(1U, new_candidate.generation());
@@ -3245,7 +3264,7 @@
   conn2->ReceivedPingResponse(LOW_RTT, "id");
 
   // Wait for conn1 to be pruned.
-  EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
+  EXPECT_TRUE_WAIT(conn1->pruned(), kMediumTimeout);
   // Destroy the connection to test SignalUnknownAddress.
   conn1->Destroy();
   EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
@@ -3760,11 +3779,11 @@
   ASSERT_TRUE(conn2 != nullptr);
   conn2->ReceivedPingResponse(LOW_RTT, "id");  // Becomes writable and receiving
   NominateConnection(conn2);
-  EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), 3000, clock);
+  EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), kMediumTimeout, clock);
 
   ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
   // Wait until conn2 becomes not receiving.
-  EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), 3000, clock);
+  EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), kMediumTimeout, clock);
 
   ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
   Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
@@ -3853,7 +3872,7 @@
   EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
   EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
   // Wait for |conn1| becoming not receiving.
-  EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), 3000, clock);
+  EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), kMediumTimeout, clock);
   // Make sure conn2 is not deleted.
   conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
   ASSERT_TRUE(conn2 != nullptr);
@@ -4076,14 +4095,14 @@
        TestRelayRelayFirstWhenNothingPingedYet) {
   const int max_strong_interval = 100;
   P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval);
-  EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
+  EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout);
   EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
   EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
 
   ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
   ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
 
-  EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
+  EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
 
   // Relay/Relay should be the first pingable connection.
   Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
@@ -4117,7 +4136,7 @@
   // Verify that conn3 will be the "selected connection" since it is readable
   // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
   // pingable connection.
-  EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000);
+  EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), kDefaultTimeout);
   WAIT(false, max_strong_interval + 100);
   conn3->ReceivedPingResponse(LOW_RTT, "id");
   ASSERT_TRUE(conn3->writable());
@@ -4132,12 +4151,12 @@
 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
        TestRelayRelayFirstWhenEverythingPinged) {
   P2PTransportChannel& ch = StartTransportChannel(true, 100);
-  EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
+  EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout);
   EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
   EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
 
   ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
-  EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
+  EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
 
   // Initially, only have Local/Local and Local/Relay.
   VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
@@ -4145,7 +4164,7 @@
 
   // Remote Relay candidate arrives.
   ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2));
-  EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
+  EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
 
   // Relay/Relay should be the first since it hasn't been pinged before.
   VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
@@ -4163,12 +4182,12 @@
 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
        TestNoStarvationOnNonRelayConnection) {
   P2PTransportChannel& ch = StartTransportChannel(true, 100);
-  EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
+  EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout);
   EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
   EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
 
   ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
-  EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
+  EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
 
   // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
   VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
@@ -4178,7 +4197,7 @@
 
   // Remote Local candidate arrives.
   ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
-  EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
+  EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
 
   // Local/Local should be the first since it hasn't been pinged before.
   VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
@@ -4202,14 +4221,14 @@
   allocator()->AddTurnServer(config);
 
   P2PTransportChannel& ch = StartTransportChannel(true, 100);
-  EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000);
+  EXPECT_TRUE_WAIT(ch.ports().size() == 3, kDefaultTimeout);
   EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
   EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
   EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE);
 
   // Remote Relay candidate arrives.
   ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
-  EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000);
+  EXPECT_TRUE_WAIT(ch.connections().size() == 3, kDefaultTimeout);
 
   // UDP Relay/Relay should be pinged first.
   VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc
index 9885ba3..d5767dd 100644
--- a/webrtc/p2p/base/port_unittest.cc
+++ b/webrtc/p2p/base/port_unittest.cc
@@ -48,7 +48,8 @@
 using rtc::SocketAddress;
 using namespace cricket;
 
-static const int kTimeout = 1000;
+static const int kDefaultTimeout = 3000;
+static const int kShortTimeout = 1000;
 static const SocketAddress kLocalAddr1("192.168.1.2", 0);
 static const SocketAddress kLocalAddr2("192.168.1.3", 0);
 static const SocketAddress kNatAddr1("77.77.77.77", rtc::NAT_SERVER_UDP_PORT);
@@ -586,15 +587,16 @@
   // TCP reconnecting mechanism before entering this function.
   void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) {
     ASSERT_TRUE(ch1->conn());
-    EXPECT_TRUE_WAIT(ch1->conn()->connected(), kTimeout);  // for TCP connect
+    EXPECT_TRUE_WAIT(ch1->conn()->connected(),
+                     kDefaultTimeout);  // for TCP connect
     ch1->Ping();
-    WAIT(!ch2->remote_address().IsNil(), kTimeout);
+    WAIT(!ch2->remote_address().IsNil(), kShortTimeout);
 
     // Send a ping from dst to src.
     ch2->AcceptConnection(GetCandidate(ch1->port()));
     ch2->Ping();
     EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2->conn()->write_state(),
-                   kTimeout);
+                   kDefaultTimeout);
   }
 
   // This connects and disconnects the provided channels in the same sequence as
@@ -623,8 +625,8 @@
                                  tcp_conn2->socket()->GetLocalAddress()));
 
     // Wait for both OnClose are delivered.
-    EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kTimeout);
-    EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kTimeout);
+    EXPECT_TRUE_WAIT(!ch1->conn()->connected(), kDefaultTimeout);
+    EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kDefaultTimeout);
 
     // Ensure redundant SignalClose events on TcpConnection won't break tcp
     // reconnection. Chromium will fire SignalClose for all outstanding IPC
@@ -635,7 +637,7 @@
     // Speed up destroying ch2's connection such that the test is ready to
     // accept a new connection from ch1 before ch1's connection destroys itself.
     ch2->conn()->Destroy();
-    EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout);
+    EXPECT_TRUE_WAIT(ch2->conn() == NULL, kDefaultTimeout);
   }
 
   void TestTcpReconnect(bool ping_after_disconnected,
@@ -656,15 +658,15 @@
 
     ch1.Start();
     ch2.Start();
-    ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout);
-    ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout);
+    ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout);
+    ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout);
 
     // Initial connecting the channel, create connection on channel1.
     ch1.CreateConnection(GetCandidate(port2));
     ConnectStartedChannels(&ch1, &ch2);
 
     // Shorten the timeout period.
-    const int kTcpReconnectTimeout = kTimeout;
+    const int kTcpReconnectTimeout = kDefaultTimeout;
     static_cast<TCPConnection*>(ch1.conn())
         ->set_reconnection_timeout(kTcpReconnectTimeout);
     static_cast<TCPConnection*>(ch2.conn())
@@ -689,7 +691,7 @@
       }
 
       // Wait for channel's outgoing TCPConnection connected.
-      EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout);
+      EXPECT_TRUE_WAIT(ch1.conn()->connected(), kDefaultTimeout);
 
       // Verify that we could still connect channels.
       ConnectStartedChannels(&ch1, &ch2);
@@ -703,15 +705,15 @@
       EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE);
       // Since the reconnection never happens, the connections should have been
       // destroyed after the timeout.
-      EXPECT_TRUE_WAIT(!ch1.conn(), kTcpReconnectTimeout + kTimeout);
+      EXPECT_TRUE_WAIT(!ch1.conn(), kTcpReconnectTimeout + kDefaultTimeout);
       EXPECT_TRUE(!ch2.conn());
     }
 
     // Tear down and ensure that goes smoothly.
     ch1.Stop();
     ch2.Stop();
-    EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout);
-    EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout);
+    EXPECT_TRUE_WAIT(ch1.conn() == NULL, kDefaultTimeout);
+    EXPECT_TRUE_WAIT(ch2.conn() == NULL, kDefaultTimeout);
   }
 
   IceMessage* CreateStunMessage(int type) {
@@ -790,6 +792,7 @@
                                 const char* name2, Port* port2,
                                 bool accept, bool same_addr1,
                                 bool same_addr2, bool possible) {
+  rtc::ScopedFakeClock clock;
   LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": ";
   port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
   port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
@@ -803,15 +806,16 @@
   // Acquire addresses.
   ch1.Start();
   ch2.Start();
-  ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout);
-  ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout);
+  ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock);
+  ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock);
 
   // Send a ping from src to dst. This may or may not make it.
   ch1.CreateConnection(GetCandidate(port2));
   ASSERT_TRUE(ch1.conn() != NULL);
-  EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout);  // for TCP connect
+  EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout,
+                             clock);  // for TCP connect
   ch1.Ping();
-  WAIT(!ch2.remote_address().IsNil(), kTimeout);
+  SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock);
 
   if (accept) {
     // We are able to send a ping from src to dst. This is the case when
@@ -828,8 +832,8 @@
     ch2.AcceptConnection(GetCandidate(port1));
     ASSERT_TRUE(ch2.conn() != NULL);
     ch2.Ping();
-    EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(),
-                   kTimeout);
+    EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE,
+                             ch2.conn()->write_state(), kDefaultTimeout, clock);
   } else {
     // We can't send a ping from src to dst, so flip it around. This will happen
     // when the destination NAT is addr/port restricted or symmetric.
@@ -840,7 +844,8 @@
     ch2.CreateConnection(GetCandidate(port1));
     ASSERT_TRUE(ch2.conn() != NULL);
     ch2.Ping();
-    WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, kTimeout);
+    SIMULATED_WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE,
+                   kShortTimeout, clock);
 
     if (same_addr1 && same_addr2) {
       // The new ping got back to the source.
@@ -851,8 +856,9 @@
       // through.  So we will have to do another.
       if (ch1.conn()->write_state() == Connection::STATE_WRITE_INIT) {
         ch1.Ping();
-        EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(),
-                       kTimeout);
+        EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE,
+                                 ch1.conn()->write_state(), kDefaultTimeout,
+                                 clock);
       }
     } else if (!same_addr1 && possible) {
       // The new ping went to the candidate address, but that address was bad.
@@ -863,7 +869,8 @@
       // However, since we have now sent a ping to the source IP, we should be
       // able to get a ping from it. This gives us the real source address.
       ch1.Ping();
-      EXPECT_TRUE_WAIT(!ch2.remote_address().IsNil(), kTimeout);
+      EXPECT_TRUE_SIMULATED_WAIT(!ch2.remote_address().IsNil(), kDefaultTimeout,
+                                 clock);
       EXPECT_FALSE(ch2.conn()->receiving());
       EXPECT_TRUE(ch1.remote_address().IsNil());
 
@@ -871,8 +878,9 @@
       ch2.AcceptConnection(GetCandidate(port1));
       ASSERT_TRUE(ch2.conn() != NULL);
       ch2.Ping();
-      EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(),
-                     kTimeout);
+      EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE,
+                               ch2.conn()->write_state(), kDefaultTimeout,
+                               clock);
     } else if (!same_addr2 && possible) {
       // The new ping came in, but from an unexpected address. This will happen
       // when the destination NAT is symmetric.
@@ -882,14 +890,15 @@
       // Update our address and complete the connection.
       ch1.AcceptConnection(GetCandidate(port2));
       ch1.Ping();
-      EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(),
-                     kTimeout);
+      EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE,
+                               ch1.conn()->write_state(), kDefaultTimeout,
+                               clock);
     } else {  // (!possible)
       // There should be s no way for the pings to reach each other. Check it.
       EXPECT_TRUE(ch1.remote_address().IsNil());
       EXPECT_TRUE(ch2.remote_address().IsNil());
       ch1.Ping();
-      WAIT(!ch2.remote_address().IsNil(), kTimeout);
+      SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock);
       EXPECT_TRUE(ch1.remote_address().IsNil());
       EXPECT_TRUE(ch2.remote_address().IsNil());
     }
@@ -913,8 +922,8 @@
   // Tear down and ensure that goes smoothly.
   ch1.Stop();
   ch2.Stop();
-  EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout);
-  EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout);
+  EXPECT_TRUE_SIMULATED_WAIT(ch1.conn() == NULL, kDefaultTimeout, clock);
+  EXPECT_TRUE_SIMULATED_WAIT(ch2.conn() == NULL, kDefaultTimeout, clock);
 }
 
 class FakePacketSocketFactory : public rtc::PacketSocketFactory {
@@ -1217,7 +1226,7 @@
   EXPECT_EQ(0, ch1.complete_count());
 
   ch1.Start();
-  ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout);
+  ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout);
 
   std::unique_ptr<rtc::AsyncSocket> server(
       vss()->CreateAsyncSocket(kLocalAddr2.family(), SOCK_STREAM));
@@ -1229,7 +1238,7 @@
 
   ch1.CreateConnection(c);
   EXPECT_TRUE(ch1.conn());
-  EXPECT_TRUE_WAIT(!ch1.conn(), kTimeout);  // for TCP connect
+  EXPECT_TRUE_WAIT(!ch1.conn(), kDefaultTimeout);  // for TCP connect
 }
 
 /* TODO: Enable these once testrelayserver can accept external TCP.
@@ -1266,8 +1275,8 @@
   // Acquire address.
   ch1.Start();
   ch2.Start();
-  ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout);
-  ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout);
+  ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout);
+  ASSERT_EQ_WAIT(1, ch2.complete_count(), kDefaultTimeout);
 
   // Test case that the connection has never received anything.
   int64_t before_created = rtc::TimeMillis();
@@ -1286,7 +1295,7 @@
   EXPECT_TRUE(ch1.conn() != nullptr);
   // It will be dead after MIN_CONNECTION_LIFETIME and pruned.
   conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1);
-  EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout);
+  EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout);
 
   // Test case that the connection has received something.
   // Create a connection again and receive a ping.
@@ -1302,7 +1311,7 @@
   rtc::Thread::Current()->ProcessMessages(100);
   EXPECT_TRUE(ch1.conn() != nullptr);
   conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1);
-  EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kTimeout);
+  EXPECT_TRUE_WAIT(ch1.conn() == nullptr, kDefaultTimeout);
 }
 
 // This test case verifies standard ICE features in STUN messages. Currently it
@@ -1323,7 +1332,7 @@
 // loopback test when protocol is RFC5245. For success IceTiebreaker, username
 // should remain equal to the request generated by the port and role of port
 // must be in controlling.
-TEST_F(PortTest, TestLoopbackCal) {
+TEST_F(PortTest, TestLoopbackCall) {
   std::unique_ptr<TestPort> lport(
       CreateTestPort(kLocalAddr1, "lfrag", "lpass"));
   lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
@@ -1334,13 +1343,13 @@
                                              Port::ORIGIN_MESSAGE);
   conn->Ping(0);
 
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = lport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   conn->OnReadPacket(lport->last_stun_buf()->data<char>(),
                      lport->last_stun_buf()->size(),
                      rtc::PacketTime());
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   msg = lport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type());
 
@@ -1353,7 +1362,7 @@
                                               Port::ORIGIN_MESSAGE);
   conn1->Ping(0);
 
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   msg = lport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   std::unique_ptr<IceMessage> modified_req(
@@ -1373,7 +1382,7 @@
   std::unique_ptr<ByteBufferWriter> buf(new ByteBufferWriter());
   WriteStunMessage(modified_req.get(), buf.get());
   conn1->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime());
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   msg = lport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type());
 }
@@ -1403,7 +1412,7 @@
                                               Port::ORIGIN_MESSAGE);
   rconn->Ping(0);
 
-  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = rport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   // Send rport binding request to lport.
@@ -1411,7 +1420,7 @@
                       rport->last_stun_buf()->size(),
                       rtc::PacketTime());
 
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type());
   EXPECT_TRUE(role_conflict());
 }
@@ -1618,7 +1627,7 @@
   lconn->Ping(0);
 
   // Check that it's a proper BINDING-REQUEST.
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = lport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   EXPECT_FALSE(msg->IsLegacy());
@@ -1720,7 +1729,7 @@
   rconn->Ping(0);
   rconn->Ping(0);
   rconn->Ping(0);
-  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout);
   msg = rport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   const StunUInt64Attribute* ice_controlled_attr =
@@ -1779,7 +1788,7 @@
   Connection* lconn = lport->CreateConnection(
       rport->Candidates()[0], Port::ORIGIN_MESSAGE);
   lconn->Ping(0);
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = lport->last_stun_msg();
   const StunUInt64Attribute* ice_controlling_attr =
       msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING);
@@ -1838,14 +1847,14 @@
   // message is handled in rconn, The rconn's remote candidate will have cost
   // rtc::kNetworkCostHigh;
   EXPECT_EQ(rtc::kNetworkCostLow, rconn->remote_candidate().network_cost());
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = lport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   // Pass the binding request to rport.
   rconn->OnReadPacket(lport->last_stun_buf()->data<char>(),
                       lport->last_stun_buf()->size(), rtc::PacketTime());
   // Wait until rport sends the response and then check the remote network cost.
-  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout);
   EXPECT_EQ(rtc::kNetworkCostHigh, rconn->remote_candidate().network_cost());
 }
 
@@ -1867,7 +1876,7 @@
   Connection* lconn =
       lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
   lconn->Ping(0);
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = lport->last_stun_msg();
   const StunUInt32Attribute* network_info_attr =
       msg->GetUInt32(STUN_ATTR_NETWORK_INFO);
@@ -1885,7 +1894,7 @@
   Connection* rconn =
       rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
   rconn->Ping(0);
-  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout);
   msg = rport->last_stun_msg();
   network_info_attr = msg->GetUInt32(STUN_ATTR_NETWORK_INFO);
   ASSERT_TRUE(network_info_attr != NULL);
@@ -2157,14 +2166,14 @@
                                               Port::ORIGIN_MESSAGE);
   rconn->Ping(0);
 
-  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = rport->last_stun_msg();
   EXPECT_EQ(STUN_BINDING_REQUEST, msg->type());
   // Send rport binding request to lport.
   lconn->OnReadPacket(rport->last_stun_buf()->data<char>(),
                       rport->last_stun_buf()->size(),
                       rtc::PacketTime());
-  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, kDefaultTimeout);
   EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type());
   int64_t last_ping_received1 = lconn->last_ping_received();
 
@@ -2245,7 +2254,7 @@
   std::unique_ptr<Port> stunport(
       CreateStunPort(kLocalAddr1, nat_socket_factory1()));
   stunport->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kDefaultTimeout);
   EXPECT_NE(tcpport1->Candidates()[0].foundation(),
             stunport->Candidates()[0].foundation());
   EXPECT_NE(tcpport2->Candidates()[0].foundation(),
@@ -2259,7 +2268,7 @@
   relayport->AddServerAddress(
       cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP));
   relayport->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kDefaultTimeout);
   EXPECT_NE(udpport1->Candidates()[0].foundation(),
             relayport->Candidates()[0].foundation());
   EXPECT_NE(udpport2->Candidates()[0].foundation(),
@@ -2268,7 +2277,7 @@
   std::unique_ptr<Port> turnport1(
       CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP));
   turnport1->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, turnport1->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, turnport1->Candidates().size(), kDefaultTimeout);
   EXPECT_NE(udpport1->Candidates()[0].foundation(),
             turnport1->Candidates()[0].foundation());
   EXPECT_NE(udpport2->Candidates()[0].foundation(),
@@ -2278,7 +2287,7 @@
   std::unique_ptr<Port> turnport2(
       CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP));
   turnport2->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, turnport2->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, turnport2->Candidates().size(), kDefaultTimeout);
   EXPECT_EQ(turnport1->Candidates()[0].foundation(),
             turnport2->Candidates()[0].foundation());
 
@@ -2291,7 +2300,7 @@
       CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP,
                      kTurnUdpIntAddr2));
   turnport3->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kDefaultTimeout);
   EXPECT_NE(turnport3->Candidates()[0].foundation(),
             turnport2->Candidates()[0].foundation());
 
@@ -2302,7 +2311,7 @@
   std::unique_ptr<Port> turnport4(
       CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP));
   turnport4->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, turnport4->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, turnport4->Candidates().size(), kDefaultTimeout);
   EXPECT_NE(turnport2->Candidates()[0].foundation(),
             turnport4->Candidates()[0].foundation());
 }
@@ -2322,7 +2331,7 @@
   std::unique_ptr<StunPort> stunport(
       CreateStunPort(kLocalAddr1, nat_socket_factory1()));
   stunport->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, stunport->Candidates().size(), kDefaultTimeout);
   // Check STUN candidate address.
   EXPECT_EQ(stunport->Candidates()[0].address().ipaddr(),
             kNatAddr1.ipaddr());
@@ -2336,7 +2345,7 @@
   relayport->AddServerAddress(
       cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP));
   relayport->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, relayport->Candidates().size(), kDefaultTimeout);
   // For Gturn related address is set to "0.0.0.0:0"
   EXPECT_EQ(rtc::SocketAddress(),
             relayport->Candidates()[0].related_address());
@@ -2345,7 +2354,7 @@
   std::unique_ptr<Port> turnport(
       CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP));
   turnport->PrepareAddress();
-  ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kTimeout);
+  ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kDefaultTimeout);
   EXPECT_EQ(kTurnUdpExtAddr.ipaddr(),
             turnport->Candidates()[0].address().ipaddr());
   EXPECT_EQ(kNatAddr1.ipaddr(),
@@ -2401,6 +2410,7 @@
 }
 
 TEST_F(PortTest, TestWritableState) {
+  rtc::ScopedFakeClock clock;
   UDPPort* port1 = CreateUdpPort(kLocalAddr1);
   port1->SetIceRole(cricket::ICEROLE_CONTROLLING);
   UDPPort* port2 = CreateUdpPort(kLocalAddr2);
@@ -2413,16 +2423,17 @@
   // Acquire addresses.
   ch1.Start();
   ch2.Start();
-  ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout);
-  ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout);
+  ASSERT_EQ_SIMULATED_WAIT(1, ch1.complete_count(), kDefaultTimeout, clock);
+  ASSERT_EQ_SIMULATED_WAIT(1, ch2.complete_count(), kDefaultTimeout, clock);
 
   // Send a ping from src to dst.
   ch1.CreateConnection(GetCandidate(port2));
   ASSERT_TRUE(ch1.conn() != NULL);
   EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state());
-  EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout);  // for TCP connect
+  // for TCP connect
+  EXPECT_TRUE_SIMULATED_WAIT(ch1.conn()->connected(), kDefaultTimeout, clock);
   ch1.Ping();
-  WAIT(!ch2.remote_address().IsNil(), kTimeout);
+  SIMULATED_WAIT(!ch2.remote_address().IsNil(), kShortTimeout, clock);
 
   // Data should be sendable before the connection is accepted.
   char data[] = "abcd";
@@ -2433,8 +2444,8 @@
   // Accept the connection to return the binding response, transition to
   // writable, and allow data to be sent.
   ch2.AcceptConnection(GetCandidate(port1));
-  EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(),
-                 kTimeout);
+  EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE,
+                           ch1.conn()->write_state(), kDefaultTimeout, clock);
   EXPECT_EQ(data_size, ch1.conn()->Send(data, data_size, options));
 
   // Ask the connection to update state as if enough time has passed to lose
@@ -2452,8 +2463,8 @@
 
   // And now allow the other side to process the pings and send binding
   // responses.
-  EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(),
-                 kTimeout);
+  EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_WRITABLE,
+                           ch1.conn()->write_state(), kDefaultTimeout, clock);
 
   // Wait long enough for a full timeout (past however long we've already
   // waited).
@@ -2518,7 +2529,7 @@
   ch1.Start();
   ice_lite_port->PrepareAddress();
 
-  ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout);
+  ASSERT_EQ_WAIT(1, ch1.complete_count(), kDefaultTimeout);
   ASSERT_FALSE(ice_lite_port->Candidates().empty());
 
   ch1.CreateConnection(GetCandidate(ice_lite_port.get()));
@@ -2531,7 +2542,7 @@
 
   // Verify stun ping is without USE_CANDIDATE_ATTR. Getting message directly
   // from port.
-  ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, kDefaultTimeout);
   IceMessage* msg = ice_full_port->last_stun_msg();
   EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL);
 
@@ -2551,15 +2562,15 @@
                            rtc::PacketTime());
   // Verifying full mode connection becomes writable from the response.
   EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(),
-                 kTimeout);
-  EXPECT_TRUE_WAIT(ch1.nominated(), kTimeout);
+                 kDefaultTimeout);
+  EXPECT_TRUE_WAIT(ch1.nominated(), kDefaultTimeout);
 
   // Clear existing stun messsages. Otherwise we will process old stun
   // message right after we send ping.
   ice_full_port->Reset();
   // Send ping. This must have USE_CANDIDATE_ATTR.
   ch1.Ping();
-  ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000);
+  ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, kDefaultTimeout);
   msg = ice_full_port->last_stun_msg();
   EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL);
   ch1.Stop();