Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Unified Diff: net/dns/dns_test_util.h

Issue 2030783003: Allow a callback to populate mock DNS responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/dns_test_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_test_util.h
diff --git a/net/dns/dns_test_util.h b/net/dns/dns_test_util.h
index d28c9e446092e9d177f34b6b52699397c81e65de..136a3becc0b1907ef0177135e094df3decbd251b 100644
--- a/net/dns/dns_test_util.h
+++ b/net/dns/dns_test_util.h
@@ -12,6 +12,8 @@
#include <string>
#include <vector>
+#include "base/big_endian.h"
+#include "base/callback_forward.h"
#include "net/dns/dns_client.h"
#include "net/dns/dns_config_service.h"
#include "net/dns/dns_protocol.h"
@@ -165,18 +167,42 @@ struct MockDnsClientRule {
OK, // Return a response with loopback address.
};
+ // The type of callback invoked in order to prepare a response to a mock DNS
+ // request. An empty response will be created, which can then be manipulated
+ // via the |response_header| and |answer_writer|. It must return net::OK
+ // when done, unless it is intended that the request fail, in which case it
+ // must return a different net::Error.
+ using ResponseCallback =
+ base::Callback<int(dns_protocol::Header* response_header,
+ base::BigEndianWriter* answer_writer)>;
+
+ // Expect a mock DNS request with the given |prefix| and |qtype|.
+ // The response is dictated by |result|.
// If |delay| is true, matching transactions will be delayed until triggered
// by the consumer.
- MockDnsClientRule(const std::string& prefix_arg,
- uint16_t qtype_arg,
- Result result_arg,
- bool delay)
- : result(result_arg),
- prefix(prefix_arg),
- qtype(qtype_arg),
- delay(delay) {}
-
- Result result;
+ MockDnsClientRule(const std::string& prefix,
+ uint16_t qtype,
+ Result result,
+ bool delay);
+
+ // Expect a mock DNS request with the given |prefix| and |qtype|.
+ // In response, invoke |response_callback|, which can modify the response
+ // header, write answers into the response, or return a net::Error.
+ // If |delay| is true, matching transactions will be delayed until triggered
+ // by the consumer.
+ MockDnsClientRule(const std::string& prefix,
+ uint16_t qtype,
+ ResponseCallback response_callback,
+ bool delay);
+
+ MockDnsClientRule(const MockDnsClientRule& copy);
+ MockDnsClientRule(MockDnsClientRule&& move);
+ ~MockDnsClientRule();
+ MockDnsClientRule& operator=(MockDnsClientRule o);
+
+ friend void swap(MockDnsClientRule& x, MockDnsClientRule& y);
+
+ ResponseCallback response_callback;
std::string prefix;
uint16_t qtype;
bool delay;
« no previous file with comments | « no previous file | net/dns/dns_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698