Bug 1556049 - Port bug 1554464: Replace nsICookie2 with nsICookie and change to smart strings in TestMailCookie.cpp. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Fri, 31 May 2019 20:13:40 +0200
changeset 35735 f22dd6d49717e8484fe1cc5994e0c3f844193a3e
parent 35734 264313145933c772a970ab5f4efb71787d623391
child 35736 48a77222e0c6f0aa85e59f4d05752e3f746ee6dc
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersbustage-fix
bugs1556049, 1554464
Bug 1556049 - Port bug 1554464: Replace nsICookie2 with nsICookie and change to smart strings in TestMailCookie.cpp. rs=bustage-fix
chat/protocols/twitter/twitter.js
mail/base/content/sanitize.js
mailnews/base/test/TestMailCookie.cpp
--- a/chat/protocols/twitter/twitter.js
+++ b/chat/protocols/twitter/twitter.js
@@ -985,17 +985,17 @@ Account.prototype = {
     };
     Services.obs.notifyObservers(this._browserRequest, "browser-request");
   },
   finishAuthorizationRequest() {
     // Clean up the cookies, so that several twitter OAuth dialogs can work
     // during the same session (bug 954308).
     let cookies = Services.cookies.getCookiesFromHost("twitter.com", {});
     while (cookies.hasMoreElements()) {
-      let cookie = cookies.getNext().QueryInterface(Ci.nsICookie2);
+      let cookie = cookies.getNext().QueryInterface(Ci.nsICookie);
       Services.cookies.remove(cookie.host, cookie.name, cookie.path, false,
                               cookie.originAttributes);
     }
 
     if (!("_browserRequest" in this))
       return;
     this._browserRequest._active = false;
     if ("_listener" in this._browserRequest)
--- a/mail/base/content/sanitize.js
+++ b/mail/base/content/sanitize.js
@@ -86,17 +86,17 @@ Sanitizer.prototype = {
     },
 
     cookies: {
       clear() {
         if (this.range) {
           // Iterate through the cookies and delete any created after our cutoff.
           var cookiesEnum = Services.cookies.enumerator;
           while (cookiesEnum.hasMoreElements()) {
-            var cookie = cookiesEnum.getNext().QueryInterface(Ci.nsICookie2);
+            var cookie = cookiesEnum.getNext().QueryInterface(Ci.nsICookie);
 
             if (cookie.creationTime > this.range[0])
               // This cookie was created after our cutoff, clear it
               Services.cookies.remove(cookie.host, cookie.name, cookie.path,
                                       false, cookie.originAttributes);
           }
         } else {
           // Remove everything
--- a/mailnews/base/test/TestMailCookie.cpp
+++ b/mailnews/base/test/TestMailCookie.cpp
@@ -2,17 +2,17 @@
 /* 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 "nsIServiceManager.h"
 #include "nsICookieService.h"
 #include "nsICookieManager.h"
-#include "nsICookie2.h"
+#include "nsICookie.h"
 #include <stdio.h>
 #include "plstr.h"
 #include "prprf.h"
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
@@ -36,31 +36,32 @@ static const char kCookiesMaxPerHost[] =
 void SetACookieMail(nsICookieService *aCookieService, const char *aSpec1,
                     const char *aSpec2, const char *aCookieString,
                     const char *aServerTime) {
   nsCOMPtr<nsIURI> uri1, uri2;
   NS_NewURI(getter_AddRefs(uri1), aSpec1);
   if (aSpec2) NS_NewURI(getter_AddRefs(uri2), aSpec2);
 
   nsresult rv = aCookieService->SetCookieStringFromHttp(
-      uri1, uri2, nullptr, (char *)aCookieString, aServerTime, nullptr);
+      uri1, uri2, nullptr, nsDependentCString(aCookieString),
+      nsDependentCString(aServerTime), nullptr);
   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 *aSpec1,
-                    const char *aSpec2, char **aCookie) {
+                    const char *aSpec2, nsACString &aCookie) {
   nsCOMPtr<nsIURI> uri1, uri2;
   NS_NewURI(getter_AddRefs(uri1), aSpec1);
   if (aSpec2) NS_NewURI(getter_AddRefs(uri2), aSpec2);
 
   Unused << aCookieService->GetCookieStringFromHttp(uri1, uri2, nullptr,
                                                     aCookie);
-  return *aCookie != nullptr;
+  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
 #define MUST_NOT_EQUAL 4
@@ -144,28 +145,23 @@ TEST(TestMailCookie, TestMailCookieMain)
 
   // *** mailnews tests
 
   // test some mailnews cookies to ensure blockage.
   // we use null firstURI's deliberately, since we have hacks to deal with
   // this situation...
   SetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr,
                  "test=mailnews", nullptr);
-  GetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr,
-                 getter_Copies(cookie));
+  GetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr, cookie);
   EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
-  GetACookieMail(cookieService, "http://mail.co.uk/", nullptr,
-                 getter_Copies(cookie));
+  GetACookieMail(cookieService, "http://mail.co.uk/", nullptr, cookie);
   EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
   SetACookieMail(cookieService, "http://mail.co.uk/", nullptr, "test=mailnews",
                  nullptr);
-  GetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr,
-                 getter_Copies(cookie));
+  GetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr, cookie);
   EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
-  GetACookieMail(cookieService, "http://mail.co.uk/", nullptr,
-                 getter_Copies(cookie));
+  GetACookieMail(cookieService, "http://mail.co.uk/", nullptr, cookie);
   EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "test=mailnews"));
   SetACookieMail(cookieService, "http://mail.co.uk/", nullptr,
                  "test=mailnews; max-age=0", nullptr);
-  GetACookieMail(cookieService, "http://mail.co.uk/", nullptr,
-                 getter_Copies(cookie));
+  GetACookieMail(cookieService, "http://mail.co.uk/", nullptr, cookie);
   EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
 }