toolkit/components/places/tests/cpp/mock_Link.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8  * This is a mock Link object which can be used in tests.
     9  */
    11 #ifndef mock_Link_h__
    12 #define mock_Link_h__
    14 #include "mozilla/MemoryReporting.h"
    15 #include "mozilla/dom/Link.h"
    16 #include "mozilla/dom/URLSearchParams.h"
    18 class mock_Link : public mozilla::dom::Link
    19 {
    20 public:
    21   NS_DECL_ISUPPORTS
    23   mock_Link(void (*aHandlerFunction)(nsLinkState),
    24             bool aRunNextTest = true)
    25   : mozilla::dom::Link(nullptr)
    26   , mHandler(aHandlerFunction)
    27   , mRunNextTest(aRunNextTest)
    28   {
    29     // Create a cyclic ownership, so that the link will be released only
    30     // after its status has been updated.  This will ensure that, when it should
    31     // run the next test, it will happen at the end of the test function, if
    32     // the link status has already been set before.  Indeed the link status is
    33     // updated on a separate connection, thus may happen at any time.
    34     mDeathGrip = this;
    35   }
    37   virtual void SetLinkState(nsLinkState aState)
    38   {
    39     // Notify our callback function.
    40     mHandler(aState);
    42     // Break the cycle so the object can be destroyed.
    43     mDeathGrip = 0;
    44   }
    46   virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
    47   {
    48     return 0;   // the value shouldn't matter
    49   }
    51   ~mock_Link() {
    52     // Run the next test if we are supposed to.
    53     if (mRunNextTest) {
    54       run_next_test();
    55     }
    56   }
    58 private:
    59   void (*mHandler)(nsLinkState);
    60   bool mRunNextTest;
    61   nsRefPtr<Link> mDeathGrip;
    62 };
    64 NS_IMPL_ISUPPORTS(
    65   mock_Link,
    66   mozilla::dom::Link
    67 )
    69 ////////////////////////////////////////////////////////////////////////////////
    70 //// Needed Link Methods
    72 namespace mozilla {
    73 namespace dom {
    75 Link::Link(Element* aElement)
    76 : mElement(aElement)
    77 , mLinkState(eLinkState_NotLink)
    78 , mRegistered(false)
    79 {
    80 }
    82 Link::~Link()
    83 {
    84 }
    86 bool
    87 Link::ElementHasHref() const
    88 {
    89   NS_NOTREACHED("Unexpected call to Link::ElementHasHref");
    90   return false; // suppress compiler warning
    91 }
    93 void
    94 Link::SetLinkState(nsLinkState aState)
    95 {
    96   NS_NOTREACHED("Unexpected call to Link::SetLinkState");
    97 }
    99 void
   100 Link::ResetLinkState(bool aNotify, bool aHasHref)
   101 {
   102   NS_NOTREACHED("Unexpected call to Link::ResetLinkState");
   103 }
   105 nsIURI*
   106 Link::GetURI() const
   107 {
   108   NS_NOTREACHED("Unexpected call to Link::GetURI");
   109   return nullptr; // suppress compiler warning
   110 }
   112 size_t
   113 Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
   114 {
   115   NS_NOTREACHED("Unexpected call to Link::SizeOfExcludingThis");
   116   return 0;
   117 }
   119 void
   120 Link::URLSearchParamsUpdated()
   121 {
   122   NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated");
   123 }
   125 void
   126 Link::UpdateURLSearchParams()
   127 {
   128   NS_NOTREACHED("Unexpected call to Link::UpdateURLSearchParams");
   129 }
   131 NS_IMPL_CYCLE_COLLECTION_CLASS(URLSearchParams)
   132 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(URLSearchParams)
   133 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
   134 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(URLSearchParams)
   135 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
   136 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(URLSearchParams)
   138 NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams)
   139 NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams)
   141 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams)
   142   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   143   NS_INTERFACE_MAP_ENTRY(nsISupports)
   144 NS_INTERFACE_MAP_END
   147 URLSearchParams::URLSearchParams()
   148 {
   149 }
   151 URLSearchParams::~URLSearchParams()
   152 {
   153 }
   155 JSObject*
   156 URLSearchParams::WrapObject(JSContext* aCx)
   157 {
   158   return nullptr;
   159 }
   161 void
   162 URLSearchParams::ParseInput(const nsACString& aInput,
   163                             URLSearchParamsObserver* aObserver)
   164 {
   165   NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput");
   166 }
   168 void
   169 URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver)
   170 {
   171   NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
   172 }
   174 void
   175 URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
   176 {
   177   NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
   178 }
   180 void
   181 URLSearchParams::Serialize(nsAString& aValue) const
   182 {
   183   NS_NOTREACHED("Unexpected call to URLSearchParams::Serialize");
   184 }
   186 void
   187 URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
   188 {
   189   NS_NOTREACHED("Unexpected call to URLSearchParams::Get");
   190 }
   192 void
   193 URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString >& aRetval)
   194 {
   195   NS_NOTREACHED("Unexpected call to URLSearchParams::GetAll");
   196 }
   198 void
   199 URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
   200 {
   201   NS_NOTREACHED("Unexpected call to URLSearchParams::Set");
   202 }
   204 void
   205 URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
   206 {
   207   NS_NOTREACHED("Unexpected call to URLSearchParams::Append");
   208 }
   210 void
   211 URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue)
   212 {
   213   NS_NOTREACHED("Unexpected call to URLSearchParams::AppendInternal");
   214 }
   216 bool
   217 URLSearchParams::Has(const nsAString& aName)
   218 {
   219   NS_NOTREACHED("Unexpected call to URLSearchParams::Has");
   220   return false;
   221 }
   223 void
   224 URLSearchParams::Delete(const nsAString& aName)
   225 {
   226   NS_NOTREACHED("Unexpected call to URLSearchParams::Delete");
   227 }
   229 void
   230 URLSearchParams::DeleteAll()
   231 {
   232   NS_NOTREACHED("Unexpected call to URLSearchParams::DeleteAll");
   233 }
   235 void
   236 URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
   237 {
   238   NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObservers");
   239 }
   241 } // namespace dom
   242 } // namespace mozilla
   244 #endif // mock_Link_h__

mercurial