1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/cpp/mock_Link.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,244 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/** 1.11 + * This is a mock Link object which can be used in tests. 1.12 + */ 1.13 + 1.14 +#ifndef mock_Link_h__ 1.15 +#define mock_Link_h__ 1.16 + 1.17 +#include "mozilla/MemoryReporting.h" 1.18 +#include "mozilla/dom/Link.h" 1.19 +#include "mozilla/dom/URLSearchParams.h" 1.20 + 1.21 +class mock_Link : public mozilla::dom::Link 1.22 +{ 1.23 +public: 1.24 + NS_DECL_ISUPPORTS 1.25 + 1.26 + mock_Link(void (*aHandlerFunction)(nsLinkState), 1.27 + bool aRunNextTest = true) 1.28 + : mozilla::dom::Link(nullptr) 1.29 + , mHandler(aHandlerFunction) 1.30 + , mRunNextTest(aRunNextTest) 1.31 + { 1.32 + // Create a cyclic ownership, so that the link will be released only 1.33 + // after its status has been updated. This will ensure that, when it should 1.34 + // run the next test, it will happen at the end of the test function, if 1.35 + // the link status has already been set before. Indeed the link status is 1.36 + // updated on a separate connection, thus may happen at any time. 1.37 + mDeathGrip = this; 1.38 + } 1.39 + 1.40 + virtual void SetLinkState(nsLinkState aState) 1.41 + { 1.42 + // Notify our callback function. 1.43 + mHandler(aState); 1.44 + 1.45 + // Break the cycle so the object can be destroyed. 1.46 + mDeathGrip = 0; 1.47 + } 1.48 + 1.49 + virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const 1.50 + { 1.51 + return 0; // the value shouldn't matter 1.52 + } 1.53 + 1.54 + ~mock_Link() { 1.55 + // Run the next test if we are supposed to. 1.56 + if (mRunNextTest) { 1.57 + run_next_test(); 1.58 + } 1.59 + } 1.60 + 1.61 +private: 1.62 + void (*mHandler)(nsLinkState); 1.63 + bool mRunNextTest; 1.64 + nsRefPtr<Link> mDeathGrip; 1.65 +}; 1.66 + 1.67 +NS_IMPL_ISUPPORTS( 1.68 + mock_Link, 1.69 + mozilla::dom::Link 1.70 +) 1.71 + 1.72 +//////////////////////////////////////////////////////////////////////////////// 1.73 +//// Needed Link Methods 1.74 + 1.75 +namespace mozilla { 1.76 +namespace dom { 1.77 + 1.78 +Link::Link(Element* aElement) 1.79 +: mElement(aElement) 1.80 +, mLinkState(eLinkState_NotLink) 1.81 +, mRegistered(false) 1.82 +{ 1.83 +} 1.84 + 1.85 +Link::~Link() 1.86 +{ 1.87 +} 1.88 + 1.89 +bool 1.90 +Link::ElementHasHref() const 1.91 +{ 1.92 + NS_NOTREACHED("Unexpected call to Link::ElementHasHref"); 1.93 + return false; // suppress compiler warning 1.94 +} 1.95 + 1.96 +void 1.97 +Link::SetLinkState(nsLinkState aState) 1.98 +{ 1.99 + NS_NOTREACHED("Unexpected call to Link::SetLinkState"); 1.100 +} 1.101 + 1.102 +void 1.103 +Link::ResetLinkState(bool aNotify, bool aHasHref) 1.104 +{ 1.105 + NS_NOTREACHED("Unexpected call to Link::ResetLinkState"); 1.106 +} 1.107 + 1.108 +nsIURI* 1.109 +Link::GetURI() const 1.110 +{ 1.111 + NS_NOTREACHED("Unexpected call to Link::GetURI"); 1.112 + return nullptr; // suppress compiler warning 1.113 +} 1.114 + 1.115 +size_t 1.116 +Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const 1.117 +{ 1.118 + NS_NOTREACHED("Unexpected call to Link::SizeOfExcludingThis"); 1.119 + return 0; 1.120 +} 1.121 + 1.122 +void 1.123 +Link::URLSearchParamsUpdated() 1.124 +{ 1.125 + NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated"); 1.126 +} 1.127 + 1.128 +void 1.129 +Link::UpdateURLSearchParams() 1.130 +{ 1.131 + NS_NOTREACHED("Unexpected call to Link::UpdateURLSearchParams"); 1.132 +} 1.133 + 1.134 +NS_IMPL_CYCLE_COLLECTION_CLASS(URLSearchParams) 1.135 +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(URLSearchParams) 1.136 +NS_IMPL_CYCLE_COLLECTION_UNLINK_END 1.137 +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(URLSearchParams) 1.138 +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END 1.139 +NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(URLSearchParams) 1.140 + 1.141 +NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams) 1.142 +NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams) 1.143 + 1.144 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams) 1.145 + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 1.146 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.147 +NS_INTERFACE_MAP_END 1.148 + 1.149 + 1.150 +URLSearchParams::URLSearchParams() 1.151 +{ 1.152 +} 1.153 + 1.154 +URLSearchParams::~URLSearchParams() 1.155 +{ 1.156 +} 1.157 + 1.158 +JSObject* 1.159 +URLSearchParams::WrapObject(JSContext* aCx) 1.160 +{ 1.161 + return nullptr; 1.162 +} 1.163 + 1.164 +void 1.165 +URLSearchParams::ParseInput(const nsACString& aInput, 1.166 + URLSearchParamsObserver* aObserver) 1.167 +{ 1.168 + NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput"); 1.169 +} 1.170 + 1.171 +void 1.172 +URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver) 1.173 +{ 1.174 + NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver"); 1.175 +} 1.176 + 1.177 +void 1.178 +URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver) 1.179 +{ 1.180 + NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver"); 1.181 +} 1.182 + 1.183 +void 1.184 +URLSearchParams::Serialize(nsAString& aValue) const 1.185 +{ 1.186 + NS_NOTREACHED("Unexpected call to URLSearchParams::Serialize"); 1.187 +} 1.188 + 1.189 +void 1.190 +URLSearchParams::Get(const nsAString& aName, nsString& aRetval) 1.191 +{ 1.192 + NS_NOTREACHED("Unexpected call to URLSearchParams::Get"); 1.193 +} 1.194 + 1.195 +void 1.196 +URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString >& aRetval) 1.197 +{ 1.198 + NS_NOTREACHED("Unexpected call to URLSearchParams::GetAll"); 1.199 +} 1.200 + 1.201 +void 1.202 +URLSearchParams::Set(const nsAString& aName, const nsAString& aValue) 1.203 +{ 1.204 + NS_NOTREACHED("Unexpected call to URLSearchParams::Set"); 1.205 +} 1.206 + 1.207 +void 1.208 +URLSearchParams::Append(const nsAString& aName, const nsAString& aValue) 1.209 +{ 1.210 + NS_NOTREACHED("Unexpected call to URLSearchParams::Append"); 1.211 +} 1.212 + 1.213 +void 1.214 +URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue) 1.215 +{ 1.216 + NS_NOTREACHED("Unexpected call to URLSearchParams::AppendInternal"); 1.217 +} 1.218 + 1.219 +bool 1.220 +URLSearchParams::Has(const nsAString& aName) 1.221 +{ 1.222 + NS_NOTREACHED("Unexpected call to URLSearchParams::Has"); 1.223 + return false; 1.224 +} 1.225 + 1.226 +void 1.227 +URLSearchParams::Delete(const nsAString& aName) 1.228 +{ 1.229 + NS_NOTREACHED("Unexpected call to URLSearchParams::Delete"); 1.230 +} 1.231 + 1.232 +void 1.233 +URLSearchParams::DeleteAll() 1.234 +{ 1.235 + NS_NOTREACHED("Unexpected call to URLSearchParams::DeleteAll"); 1.236 +} 1.237 + 1.238 +void 1.239 +URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver) 1.240 +{ 1.241 + NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObservers"); 1.242 +} 1.243 + 1.244 +} // namespace dom 1.245 +} // namespace mozilla 1.246 + 1.247 +#endif // mock_Link_h__