Bug 1632115 - adjust gtest TestMailCookie.TestMailCookieMain for
bug 1631565. rs=bustage-fix DONBTUILD
Channel is no longer allowed to be null
--- 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);