DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
 * 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/. */

/**
 * This is a mock Link object which can be used in tests.
 */

#ifndef mock_Link_h__
#define mock_Link_h__

#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Link.h"
#include "mozilla/dom/URLSearchParams.h"

class mock_Link : public mozilla::dom::Link
{
public:
  NS_DECL_ISUPPORTS

  mock_Link(void (*aHandlerFunction)(nsLinkState),
            bool aRunNextTest = true)
  : mozilla::dom::Link(nullptr)
  , mHandler(aHandlerFunction)
  , mRunNextTest(aRunNextTest)
  {
    // Create a cyclic ownership, so that the link will be released only
    // after its status has been updated.  This will ensure that, when it should
    // run the next test, it will happen at the end of the test function, if
    // the link status has already been set before.  Indeed the link status is
    // updated on a separate connection, thus may happen at any time.
    mDeathGrip = this;
  }

  virtual void SetLinkState(nsLinkState aState)
  {
    // Notify our callback function.
    mHandler(aState);

    // Break the cycle so the object can be destroyed.
    mDeathGrip = 0;
  }

  virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
  {
    return 0;   // the value shouldn't matter
  }

protected:
  ~mock_Link() {
    // Run the next test if we are supposed to.
    if (mRunNextTest) {
      run_next_test();
    }
  }

private:
  void (*mHandler)(nsLinkState);
  bool mRunNextTest;
  nsRefPtr<Link> mDeathGrip;
};

NS_IMPL_ISUPPORTS(
  mock_Link,
  mozilla::dom::Link
)

////////////////////////////////////////////////////////////////////////////////
//// Needed Link Methods

namespace mozilla {
namespace dom {

Link::Link(Element* aElement)
: mElement(aElement)
, mLinkState(eLinkState_NotLink)
, mRegistered(false)
{
}

Link::~Link()
{
}

bool
Link::ElementHasHref() const
{
  NS_NOTREACHED("Unexpected call to Link::ElementHasHref");
  return false; // suppress compiler warning
}

void
Link::SetLinkState(nsLinkState aState)
{
  NS_NOTREACHED("Unexpected call to Link::SetLinkState");
}

void
Link::ResetLinkState(bool aNotify, bool aHasHref)
{
  NS_NOTREACHED("Unexpected call to Link::ResetLinkState");
}

nsIURI*
Link::GetURI() const
{
  NS_NOTREACHED("Unexpected call to Link::GetURI");
  return nullptr; // suppress compiler warning
}

size_t
Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
  NS_NOTREACHED("Unexpected call to Link::SizeOfExcludingThis");
  return 0;
}

void
Link::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
{
  NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated");
}

void
Link::UpdateURLSearchParams()
{
  NS_NOTREACHED("Unexpected call to Link::UpdateURLSearchParams");
}

NS_IMPL_CYCLE_COLLECTION_CLASS(URLSearchParams)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(URLSearchParams)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(URLSearchParams)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(URLSearchParams)

NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams)
NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams)
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END


URLSearchParams::URLSearchParams()
{
}

URLSearchParams::~URLSearchParams()
{
}

JSObject*
URLSearchParams::WrapObject(JSContext* aCx)
{
  return nullptr;
}

void
URLSearchParams::ParseInput(const nsACString& aInput,
                            URLSearchParamsObserver* aObserver)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput");
}

void
URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
}

void
URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
}

void
URLSearchParams::Serialize(nsAString& aValue) const
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::Serialize");
}

void
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::Get");
}

void
URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString >& aRetval)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::GetAll");
}

void
URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::Set");
}

void
URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::Append");
}

void
URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::AppendInternal");
}

bool
URLSearchParams::Has(const nsAString& aName)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::Has");
  return false;
}

void
URLSearchParams::Delete(const nsAString& aName)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::Delete");
}

void
URLSearchParams::DeleteAll()
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::DeleteAll");
}

void
URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
{
  NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObservers");
}

} // namespace dom
} // namespace mozilla

#endif // mock_Link_h__