summaryrefslogtreecommitdiff
path: root/chromium/net/dns/dns_transaction_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/dns/dns_transaction_unittest.cc')
-rw-r--r--chromium/net/dns/dns_transaction_unittest.cc93
1 files changed, 82 insertions, 11 deletions
diff --git a/chromium/net/dns/dns_transaction_unittest.cc b/chromium/net/dns/dns_transaction_unittest.cc
index e3196cfc21e..17f6bf62e72 100644
--- a/chromium/net/dns/dns_transaction_unittest.cc
+++ b/chromium/net/dns/dns_transaction_unittest.cc
@@ -28,6 +28,7 @@
#include "net/base/port_util.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/url_util.h"
+#include "net/cookies/cookie_inclusion_status.h"
#include "net/cookies/cookie_util.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_query.h"
@@ -324,7 +325,8 @@ class TransactionHelper {
void OnTransactionComplete(DnsTransaction* t,
int rv,
- const DnsResponse* response) {
+ const DnsResponse* response,
+ base::Optional<std::string> doh_provider_id) {
EXPECT_FALSE(completed_);
EXPECT_EQ(transaction_.get(), t);
@@ -1200,8 +1202,17 @@ TEST_F(DnsTransactionTestWithMockTime, ServerFallbackAndRotate) {
EXPECT_TRUE(helper1.Run(transaction_factory_.get()));
size_t kOrder[] = {
- 0, 1, 2, 0, 1, // The first transaction.
- 1, 2, 0, // The second transaction starts from the next server.
+ // The first transaction.
+ 0,
+ 1,
+ 2,
+ 0,
+ 1,
+ // The second transaction starts from the next server, and 0 is skipped
+ // because it already has 2 consecutive failures.
+ 1,
+ 2,
+ 1,
};
CheckServerOrder(kOrder, base::size(kOrder));
}
@@ -2178,14 +2189,15 @@ class CookieCallback {
CookieCallback()
: result_(false), loop_to_quit_(std::make_unique<base::RunLoop>()) {}
- void SetCookieCallback(CanonicalCookie::CookieInclusionStatus result) {
+ void SetCookieCallback(CookieInclusionStatus result) {
result_ = result.IsInclude();
loop_to_quit_->Quit();
}
- void GetCookieListCallback(const net::CookieStatusList& list,
- const net::CookieStatusList& excluded_cookies) {
- list_ = cookie_util::StripStatuses(list);
+ void GetCookieListCallback(
+ const net::CookieAccessResultList& list,
+ const net::CookieAccessResultList& excluded_cookies) {
+ list_ = cookie_util::StripAccessResults(list);
loop_to_quit_->Quit();
}
@@ -2384,6 +2396,63 @@ TEST_F(DnsTransactionTest, HttpsPostLookupWithLog) {
EXPECT_EQ(observer.dict_count(), 3);
}
+// Test for when a slow DoH response is delayed until after the initial timeout
+// and no more attempts are configured.
+TEST_F(DnsTransactionTestWithMockTime, SlowHttpsResponse_SingleAttempt) {
+ config_.doh_attempts = 1;
+ ConfigureDohServers(false /* use_post */);
+
+ AddQueryAndTimeout(kT0HostName, kT0Qtype,
+ DnsQuery::PaddingStrategy::BLOCK_LENGTH_128);
+
+ TransactionHelper helper(kT0HostName, kT0Qtype, true /* secure */,
+ ERR_DNS_TIMED_OUT, resolve_context_.get());
+ ASSERT_FALSE(helper.Run(transaction_factory_.get()));
+
+ // Only one attempt configured, so expect immediate failure after timeout
+ // period.
+ FastForwardBy(resolve_context_->NextDohTimeout(0 /* doh_server_index */,
+ session_.get()));
+ EXPECT_TRUE(helper.has_completed());
+}
+
+// Test for when a slow DoH response is delayed until after the initial timeout
+// but a retry is configured.
+TEST_F(DnsTransactionTestWithMockTime, SlowHttpsResponse_TwoAttempts) {
+ config_.doh_attempts = 2;
+ ConfigureDohServers(false /* use_post */);
+
+ // Simulate a slow response by using an ERR_IO_PENDING read error to delay
+ // until SequencedSocketData::Resume() is called.
+ auto data = std::make_unique<DnsSocketData>(
+ 1 /* id */, kT1HostName, kT1Qtype, ASYNC, Transport::HTTPS,
+ nullptr /* opt_rdata */, DnsQuery::PaddingStrategy::BLOCK_LENGTH_128);
+ data->AddReadError(ERR_IO_PENDING, ASYNC);
+ data->AddResponseData(kT1ResponseDatagram, base::size(kT1ResponseDatagram),
+ ASYNC);
+ SequencedSocketData* sequenced_socket_data = data->GetProvider();
+ AddSocketData(std::move(data));
+
+ TransactionHelper helper(kT1HostName, kT1Qtype, true /* secure */,
+ kT1RecordCount, resolve_context_.get());
+ ASSERT_FALSE(helper.Run(transaction_factory_.get()));
+ ASSERT_TRUE(sequenced_socket_data->IsPaused());
+
+ // Another attempt configured, so transaction should not fail after initial
+ // timeout. Setup the second attempt to never receive a response.
+ AddQueryAndTimeout(kT1HostName, kT1Qtype,
+ DnsQuery::PaddingStrategy::BLOCK_LENGTH_128);
+ FastForwardBy(resolve_context_->NextDohTimeout(0 /* doh_server_index */,
+ session_.get()));
+ EXPECT_FALSE(helper.has_completed());
+
+ // Expect first attempt to continue in parallel with retry, so expect the
+ // transaction to complete when the first query is allowed to resume.
+ sequenced_socket_data->Resume();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(helper.has_completed());
+}
+
TEST_F(DnsTransactionTest, TCPLookup) {
AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
@@ -3100,8 +3169,9 @@ TEST_F(DnsTransactionTestWithMockTime, RestartFinishedProbe) {
// Mark server unavailabe and restart runner.
for (int i = 0; i < ResolveContext::kAutomaticModeFailureLimit; ++i) {
- resolve_context_->RecordServerFailure(
- 0u /* server_index */, true /* is_doh_server */, session_.get());
+ resolve_context_->RecordServerFailure(0u /* server_index */,
+ true /* is_doh_server */, ERR_FAILED,
+ session_.get());
}
ASSERT_FALSE(resolve_context_->GetDohServerAvailability(
0u /* doh_server_index */, session_.get()));
@@ -3149,8 +3219,9 @@ TEST_F(DnsTransactionTestWithMockTime, FastProbeRestart) {
// becoming unavailable and might as well replecate real behavior for the
// test.
for (int i = 0; i < ResolveContext::kAutomaticModeFailureLimit; ++i) {
- resolve_context_->RecordServerFailure(
- 0u /* server_index */, true /* is_doh_server */, session_.get());
+ resolve_context_->RecordServerFailure(0u /* server_index */,
+ true /* is_doh_server */, ERR_FAILED,
+ session_.get());
}
ASSERT_FALSE(resolve_context_->GetDohServerAvailability(
0u /* doh_server_index */, session_.get()));