Bug 1539819 - P4: Some adjustments to pass trr test r=dragana,necko-reviewers
authorKershaw Chang <kershaw@mozilla.com>
Mon, 18 May 2020 20:18:13 +0000
changeset 530706 a0f338331b410462ac54b92603232828cecc65f4
parent 530705 d332f00b2ada23ed72448219d551d37449723144
child 530707 7c84257e93bec6b4b09514e349886e29b6f7e573
push id116316
push userkjang@mozilla.com
push dateMon, 18 May 2020 20:28:45 +0000
treeherderautoland@7c84257e93be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, necko-reviewers
bugs1539819
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1539819 - P4: Some adjustments to pass trr test r=dragana,necko-reviewers Differential Revision: https://phabricator.services.mozilla.com/D68881
netwerk/dns/ChildDNSService.cpp
netwerk/dns/DNSRequestChild.cpp
netwerk/dns/DNSRequestParent.cpp
netwerk/dns/PDNSRequestParams.ipdlh
netwerk/dns/PTRRService.ipdl
netwerk/dns/TRRServiceChild.cpp
netwerk/dns/TRRServiceChild.h
netwerk/dns/TRRServiceParent.cpp
netwerk/dns/TRRServiceParent.h
netwerk/dns/nsDNSService2.cpp
netwerk/test/unit/test_trr.js
--- a/netwerk/dns/ChildDNSService.cpp
+++ b/netwerk/dns/ChildDNSService.cpp
@@ -354,21 +354,25 @@ ChildDNSService::GetDNSCacheEntries(
     nsTArray<mozilla::net::DNSCacheEntries>* args) {
   // Only used by networking dashboard, so may not ever need this in child.
   // (and would provide a way to spy on what hosts other apps are connecting to,
   // unless we start keeping per-app DNS caches).
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-ChildDNSService::ClearCache(bool aTrrToo) { return NS_ERROR_NOT_AVAILABLE; }
+ChildDNSService::ClearCache(bool aTrrToo) {
+  Unused << mTRRServiceParent->SendClearDNSCache(aTrrToo);
+  return NS_OK;
+}
 
 NS_IMETHODIMP
 ChildDNSService::ReloadParentalControlEnabled() {
-  return NS_ERROR_NOT_AVAILABLE;
+  mTRRServiceParent->UpdateParentalControlEnabled();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 ChildDNSService::SetDetectedTrrURI(const nsACString& aURI) {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
--- a/netwerk/dns/DNSRequestChild.cpp
+++ b/netwerk/dns/DNSRequestChild.cpp
@@ -45,23 +45,27 @@ class ChildDNSRecord : public nsIDNSReco
 
  private:
   virtual ~ChildDNSRecord() = default;
 
   nsCString mCanonicalName;
   nsTArray<NetAddr> mAddresses;
   uint32_t mCurrent;  // addr iterator
   uint16_t mFlags;
+  double mTrrFetchDuration;
+  double mTrrFetchDurationNetworkOnly;
 };
 
 NS_IMPL_ISUPPORTS(ChildDNSRecord, nsIDNSRecord)
 
 ChildDNSRecord::ChildDNSRecord(const DNSRecord& reply, uint16_t flags)
     : mCurrent(0), mFlags(flags) {
   mCanonicalName = reply.canonicalName();
+  mTrrFetchDuration = reply.trrFetchDuration();
+  mTrrFetchDurationNetworkOnly = reply.trrFetchDurationNetworkOnly();
 
   // A shame IPDL gives us no way to grab ownership of array: so copy it.
   const nsTArray<NetAddr>& addrs = reply.addrs();
   mAddresses = addrs.Clone();
 }
 
 //-----------------------------------------------------------------------------
 // ChildDNSRecord::nsIDNSRecord
@@ -80,24 +84,24 @@ ChildDNSRecord::GetCanonicalName(nsACStr
 NS_IMETHODIMP
 ChildDNSRecord::IsTRR(bool* retval) {
   *retval = false;
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
 ChildDNSRecord::GetTrrFetchDuration(double* aTime) {
-  *aTime = 0;
-  return NS_ERROR_NOT_AVAILABLE;
+  *aTime = mTrrFetchDuration;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 ChildDNSRecord::GetTrrFetchDurationNetworkOnly(double* aTime) {
-  *aTime = 0;
-  return NS_ERROR_NOT_AVAILABLE;
+  *aTime = mTrrFetchDurationNetworkOnly;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 ChildDNSRecord::GetNextAddr(uint16_t port, NetAddr* addr) {
   if (mCurrent >= mAddresses.Length()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
--- a/netwerk/dns/DNSRequestParent.cpp
+++ b/netwerk/dns/DNSRequestParent.cpp
@@ -120,18 +120,25 @@ DNSRequestHandler::OnLookupComplete(nsIC
 
     // Get IP addresses for hostname (use port 80 as dummy value for NetAddr)
     nsTArray<NetAddr> array;
     NetAddr addr;
     while (NS_SUCCEEDED(rec->GetNextAddr(80, &addr))) {
       array.AppendElement(addr);
     }
 
-    SendLookupCompletedHelper(mIPCActor,
-                              DNSRequestResponse(DNSRecord(cname, array)));
+    double trrFetchDuration;
+    rec->GetTrrFetchDuration(&trrFetchDuration);
+
+    double trrFetchDurationNetworkOnly;
+    rec->GetTrrFetchDurationNetworkOnly(&trrFetchDurationNetworkOnly);
+
+    SendLookupCompletedHelper(
+        mIPCActor, DNSRequestResponse(DNSRecord(cname, array, trrFetchDuration,
+                                                trrFetchDurationNetworkOnly)));
   } else {
     SendLookupCompletedHelper(mIPCActor, DNSRequestResponse(status));
   }
 
   return NS_OK;
 }
 
 void DNSRequestHandler::OnIPCActorDestroy() { mIPCActor = nullptr; }
--- a/netwerk/dns/PDNSRequestParams.ipdlh
+++ b/netwerk/dns/PDNSRequestParams.ipdlh
@@ -15,16 +15,18 @@ namespace net {
 //-----------------------------------------------------------------------------
 // DNS IPDL structs
 //-----------------------------------------------------------------------------
 
 struct DNSRecord
 {
   nsCString canonicalName;
   NetAddr[] addrs;
+  double trrFetchDuration;
+  double trrFetchDurationNetworkOnly;
 };
 
 union DNSRequestResponse
 {
   DNSRecord;
   IPCTypeRecord; // The result of a by-type query
   nsresult;   // if error
 };
--- a/netwerk/dns/PTRRService.ipdl
+++ b/netwerk/dns/PTRRService.ipdl
@@ -16,13 +16,14 @@ async refcounted protocol PTRRService
   manager PSocketProcess;
 
 child:
   async __delete__();
   async NotifyObserver(nsCString aTopic, nsString aData);
   async UpdatePlatformDNSInformation(nsCString[] aSuffixList,
                                      bool aPlatformDisabledTRR);
   async InitTRRBLStorage(DataStorageEntry aEntry, FileDescriptor aWriteFd);
-
+  async UpdateParentalControlEnabled(bool aEnabled);
+  async ClearDNSCache(bool aTrrToo);
 };
 
 } //namespace net
 } //namespace mozilla
--- a/netwerk/dns/TRRServiceChild.cpp
+++ b/netwerk/dns/TRRServiceChild.cpp
@@ -53,10 +53,22 @@ mozilla::ipc::IPCResult TRRServiceChild:
   RefPtr<DataStorage> storage =
       DataStorage::Get(DataStorageClass::TRRBlacklist);
   if (storage) {
     storage->Init(&aEntry.items(), aWriteFd);
   }
   return IPC_OK();
 }
 
+mozilla::ipc::IPCResult TRRServiceChild::RecvUpdateParentalControlEnabled(
+    const bool& aEnabled) {
+  gTRRService->mParentalControlEnabled = aEnabled;
+  return IPC_OK();
+}
+
+mozilla::ipc::IPCResult TRRServiceChild::RecvClearDNSCache(
+    const bool& aTrrToo) {
+  Unused << sDNSService->ClearCache(aTrrToo);
+  return IPC_OK();
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/dns/TRRServiceChild.h
+++ b/netwerk/dns/TRRServiceChild.h
@@ -26,16 +26,19 @@ class TRRServiceChild : public PTRRServi
   void Init(const bool& aCaptiveIsPassed, const bool& aParentalControlEnabled,
             nsTArray<nsCString>&& aDNSSuffixList);
   mozilla::ipc::IPCResult RecvNotifyObserver(const nsCString& aTopic,
                                              const nsString& aData);
   mozilla::ipc::IPCResult RecvUpdatePlatformDNSInformation(
       nsTArray<nsCString>&& aDNSSuffixList, const bool& aPlatformDisabledTRR);
   mozilla::ipc::IPCResult RecvInitTRRBLStorage(
       const psm::DataStorageEntry& aEntry, const FileDescriptor& aWriteFd);
+  mozilla::ipc::IPCResult RecvUpdateParentalControlEnabled(
+      const bool& aEnabled);
+  mozilla::ipc::IPCResult RecvClearDNSCache(const bool& aTrrToo);
 
  private:
   virtual ~TRRServiceChild() = default;
 };
 
 }  // namespace net
 }  // namespace mozilla
 
--- a/netwerk/dns/TRRServiceParent.cpp
+++ b/netwerk/dns/TRRServiceParent.cpp
@@ -112,10 +112,15 @@ TRRServiceParent::Observe(nsISupports* a
       Unused << SendUpdatePlatformDNSInformation(suffixList,
                                                  platformDisabledTRR);
     }
   }
 
   return NS_OK;
 }
 
+void TRRServiceParent::UpdateParentalControlEnabled() {
+  bool enabled = TRRService::GetParentalControlEnabledInternal();
+  Unused << SendUpdateParentalControlEnabled(enabled);
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/dns/TRRServiceParent.h
+++ b/netwerk/dns/TRRServiceParent.h
@@ -19,16 +19,17 @@ class TRRServiceParent : public nsIObser
                          public nsSupportsWeakReference,
                          public PTRRServiceParent {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   explicit TRRServiceParent() : mTRRBLStorageInited(false) {}
   void Init();
+  void UpdateParentalControlEnabled();
 
  private:
   virtual ~TRRServiceParent() = default;
 
   bool mTRRBLStorageInited;
 };
 
 }  // namespace net
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -1345,17 +1345,18 @@ nsDNSService::ClearCache(bool aTrrToo) {
   NS_ENSURE_TRUE(mResolver, NS_ERROR_NOT_INITIALIZED);
   mResolver->FlushCache(aTrrToo);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDNSService::ReloadParentalControlEnabled() {
   if (mTrrService) {
-    mTrrService->GetParentalControlEnabledInternal();
+    mTrrService->mParentalControlEnabled =
+        TRRService::GetParentalControlEnabledInternal();
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDNSService::SetDetectedTrrURI(const nsACString& aURI) {
   if (mTrrService) {
     mTrrService->SetDetectedTrrURI(aURI);
--- a/netwerk/test/unit/test_trr.js
+++ b/netwerk/test/unit/test_trr.js
@@ -1457,23 +1457,25 @@ add_task(async function test_async_resol
   await new DNSListener("bar_with_trr3.example.com", "2.2.2.2");
 });
 
 // Test AsyncResoleWithTrrServer.
 add_task(async function test_async_resolve_with_trr_server_5() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 5); // TRR-user-disabled
 
+  // When dns is resolved in socket process, we can't set |expectEarlyFail| to true.
+  let inSocketProcess = mozinfo.socketprocess_networking;
   let [_] = await new DNSListener(
     "bar_with_trr3.example.com",
     undefined,
     false,
     undefined,
     `https://foo.example.com:${h2Port}/doh?responseIP=3.3.3.3`,
-    true
+    !inSocketProcess
   );
 
   // Call normal AsyncOpen, it will return result from the native resolver.
   await new DNSListener("bar_with_trr3.example.com", "127.0.0.1");
 });
 
 // Test AsyncResoleWithTrrServer.
 add_task(async function test_async_resolve_with_trr_server_different_cache() {