Bug 1632115 - adjust gtest TestMailCookie.TestMailCookieMain for bug 1631565. rs=bustage-fix DONBTUILD
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Wed, 22 Apr 2020 15:14:44 +0300
changeset 38906 7e71b9fa21f277a9a50d104010be3c188c69367a
parent 38905 542fb0021c53f7d462c07f07419d80664c4f0e33
child 38907 804e09a2b5711c710984702bfca2551ac7d4e24d
push id401
push userclokep@gmail.com
push dateMon, 01 Jun 2020 20:41:59 +0000
reviewersbustage-fix
bugs1632115, 1631565
Bug 1632115 - adjust gtest TestMailCookie.TestMailCookieMain for bug 1631565. rs=bustage-fix DONBTUILD Channel is no longer allowed to be null
mailnews/base/test/TestMailCookie.cpp
--- a/mailnews/base/test/TestMailCookie.cpp
+++ b/mailnews/base/test/TestMailCookie.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gtest/gtest.h"
+#include "nsContentUtils.h"
 #include "nsIServiceManager.h"
 #include "nsICookieService.h"
 #include "nsICookieManager.h"
 #include "nsICookie.h"
 #include <stdio.h>
 #include "plstr.h"
 #include "prprf.h"
 #include "nsNetUtil.h"
@@ -33,29 +34,43 @@ static const char kCookiesLifetimeCurren
 static const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies";
 static const char kCookiesMaxPerHost[] = "network.cookie.maxPerHost";
 
 void SetACookieMail(nsICookieService *aCookieService, const char *aSpec,
                     const char *aCookieString) {
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), aSpec);
 
+  nsCOMPtr<nsIIOService> service = do_GetIOService();
+  nsCOMPtr<nsIChannel> channel;
+  Unused << service->NewChannelFromURI(
+      uri, nullptr, nsContentUtils::GetSystemPrincipal(),
+      nsContentUtils::GetSystemPrincipal(), 0, nsIContentPolicy::TYPE_DOCUMENT,
+      getter_AddRefs(channel));
+
   nsresult rv = aCookieService->SetCookieStringFromHttp(
-      uri, nsDependentCString(aCookieString), nullptr);
+      uri, nsDependentCString(aCookieString), channel);
   EXPECT_TRUE(NS_SUCCEEDED(rv));
 }
 
 // returns true if cookie(s) for the given host were found; else false.
 // the cookie string is returned via aCookie.
 bool GetACookieMail(nsICookieService *aCookieService, const char *aSpec,
                     nsACString &aCookie) {
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), aSpec);
 
-  Unused << aCookieService->GetCookieStringFromHttp(uri, nullptr, aCookie);
+  nsCOMPtr<nsIIOService> service = do_GetIOService();
+  nsCOMPtr<nsIChannel> channel;
+  Unused << service->NewChannelFromURI(
+      uri, nullptr, nsContentUtils::GetSystemPrincipal(),
+      nsContentUtils::GetSystemPrincipal(), 0, nsIContentPolicy::TYPE_DOCUMENT,
+      getter_AddRefs(channel));
+
+  Unused << aCookieService->GetCookieStringFromHttp(uri, channel, aCookie);
   return !aCookie.IsEmpty();
 }
 
 // some #defines for comparison rules
 #define MUST_BE_NULL 0
 #define MUST_EQUAL 1
 #define MUST_CONTAIN 2
 #define MUST_NOT_CONTAIN 3
@@ -96,16 +111,19 @@ void InitPrefsMail(nsIPrefBranch *aPrefB
   aPrefBranch->SetIntPref(kCookiesLifetimeCurrentSession, 0);
   aPrefBranch->SetIntPref(kCookiesLifetimeDays, 1);
   aPrefBranch->SetBoolPref(kCookiesAskPermission, false);
   // Set the base domain limit to 50 so we have a known value.
   aPrefBranch->SetIntPref(kCookiesMaxPerHost, 50);
 
   // XXX TODO: We need to follow bug 1617611 for the real fix.
   mozilla::Preferences::SetBool("network.cookie.sameSite.laxByDefault", false);
+
+  mozilla::Preferences::SetBool(
+      "network.cookieJarSettings.unblocked_for_testing", true);
 }
 
 TEST(TestMailCookie, TestMailCookieMain)
 {
   nsresult rv0;
 
   nsCOMPtr<nsICookieService> cookieService =
       do_GetService(kCookieServiceCID, &rv0);