|
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/. */ |
|
6 |
|
7 /** |
|
8 * This is a mock Link object which can be used in tests. |
|
9 */ |
|
10 |
|
11 #ifndef mock_Link_h__ |
|
12 #define mock_Link_h__ |
|
13 |
|
14 #include "mozilla/MemoryReporting.h" |
|
15 #include "mozilla/dom/Link.h" |
|
16 #include "mozilla/dom/URLSearchParams.h" |
|
17 |
|
18 class mock_Link : public mozilla::dom::Link |
|
19 { |
|
20 public: |
|
21 NS_DECL_ISUPPORTS |
|
22 |
|
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 } |
|
36 |
|
37 virtual void SetLinkState(nsLinkState aState) |
|
38 { |
|
39 // Notify our callback function. |
|
40 mHandler(aState); |
|
41 |
|
42 // Break the cycle so the object can be destroyed. |
|
43 mDeathGrip = 0; |
|
44 } |
|
45 |
|
46 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const |
|
47 { |
|
48 return 0; // the value shouldn't matter |
|
49 } |
|
50 |
|
51 ~mock_Link() { |
|
52 // Run the next test if we are supposed to. |
|
53 if (mRunNextTest) { |
|
54 run_next_test(); |
|
55 } |
|
56 } |
|
57 |
|
58 private: |
|
59 void (*mHandler)(nsLinkState); |
|
60 bool mRunNextTest; |
|
61 nsRefPtr<Link> mDeathGrip; |
|
62 }; |
|
63 |
|
64 NS_IMPL_ISUPPORTS( |
|
65 mock_Link, |
|
66 mozilla::dom::Link |
|
67 ) |
|
68 |
|
69 //////////////////////////////////////////////////////////////////////////////// |
|
70 //// Needed Link Methods |
|
71 |
|
72 namespace mozilla { |
|
73 namespace dom { |
|
74 |
|
75 Link::Link(Element* aElement) |
|
76 : mElement(aElement) |
|
77 , mLinkState(eLinkState_NotLink) |
|
78 , mRegistered(false) |
|
79 { |
|
80 } |
|
81 |
|
82 Link::~Link() |
|
83 { |
|
84 } |
|
85 |
|
86 bool |
|
87 Link::ElementHasHref() const |
|
88 { |
|
89 NS_NOTREACHED("Unexpected call to Link::ElementHasHref"); |
|
90 return false; // suppress compiler warning |
|
91 } |
|
92 |
|
93 void |
|
94 Link::SetLinkState(nsLinkState aState) |
|
95 { |
|
96 NS_NOTREACHED("Unexpected call to Link::SetLinkState"); |
|
97 } |
|
98 |
|
99 void |
|
100 Link::ResetLinkState(bool aNotify, bool aHasHref) |
|
101 { |
|
102 NS_NOTREACHED("Unexpected call to Link::ResetLinkState"); |
|
103 } |
|
104 |
|
105 nsIURI* |
|
106 Link::GetURI() const |
|
107 { |
|
108 NS_NOTREACHED("Unexpected call to Link::GetURI"); |
|
109 return nullptr; // suppress compiler warning |
|
110 } |
|
111 |
|
112 size_t |
|
113 Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const |
|
114 { |
|
115 NS_NOTREACHED("Unexpected call to Link::SizeOfExcludingThis"); |
|
116 return 0; |
|
117 } |
|
118 |
|
119 void |
|
120 Link::URLSearchParamsUpdated() |
|
121 { |
|
122 NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated"); |
|
123 } |
|
124 |
|
125 void |
|
126 Link::UpdateURLSearchParams() |
|
127 { |
|
128 NS_NOTREACHED("Unexpected call to Link::UpdateURLSearchParams"); |
|
129 } |
|
130 |
|
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) |
|
137 |
|
138 NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams) |
|
139 NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams) |
|
140 |
|
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 |
|
145 |
|
146 |
|
147 URLSearchParams::URLSearchParams() |
|
148 { |
|
149 } |
|
150 |
|
151 URLSearchParams::~URLSearchParams() |
|
152 { |
|
153 } |
|
154 |
|
155 JSObject* |
|
156 URLSearchParams::WrapObject(JSContext* aCx) |
|
157 { |
|
158 return nullptr; |
|
159 } |
|
160 |
|
161 void |
|
162 URLSearchParams::ParseInput(const nsACString& aInput, |
|
163 URLSearchParamsObserver* aObserver) |
|
164 { |
|
165 NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput"); |
|
166 } |
|
167 |
|
168 void |
|
169 URLSearchParams::AddObserver(URLSearchParamsObserver* aObserver) |
|
170 { |
|
171 NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver"); |
|
172 } |
|
173 |
|
174 void |
|
175 URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver) |
|
176 { |
|
177 NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver"); |
|
178 } |
|
179 |
|
180 void |
|
181 URLSearchParams::Serialize(nsAString& aValue) const |
|
182 { |
|
183 NS_NOTREACHED("Unexpected call to URLSearchParams::Serialize"); |
|
184 } |
|
185 |
|
186 void |
|
187 URLSearchParams::Get(const nsAString& aName, nsString& aRetval) |
|
188 { |
|
189 NS_NOTREACHED("Unexpected call to URLSearchParams::Get"); |
|
190 } |
|
191 |
|
192 void |
|
193 URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString >& aRetval) |
|
194 { |
|
195 NS_NOTREACHED("Unexpected call to URLSearchParams::GetAll"); |
|
196 } |
|
197 |
|
198 void |
|
199 URLSearchParams::Set(const nsAString& aName, const nsAString& aValue) |
|
200 { |
|
201 NS_NOTREACHED("Unexpected call to URLSearchParams::Set"); |
|
202 } |
|
203 |
|
204 void |
|
205 URLSearchParams::Append(const nsAString& aName, const nsAString& aValue) |
|
206 { |
|
207 NS_NOTREACHED("Unexpected call to URLSearchParams::Append"); |
|
208 } |
|
209 |
|
210 void |
|
211 URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue) |
|
212 { |
|
213 NS_NOTREACHED("Unexpected call to URLSearchParams::AppendInternal"); |
|
214 } |
|
215 |
|
216 bool |
|
217 URLSearchParams::Has(const nsAString& aName) |
|
218 { |
|
219 NS_NOTREACHED("Unexpected call to URLSearchParams::Has"); |
|
220 return false; |
|
221 } |
|
222 |
|
223 void |
|
224 URLSearchParams::Delete(const nsAString& aName) |
|
225 { |
|
226 NS_NOTREACHED("Unexpected call to URLSearchParams::Delete"); |
|
227 } |
|
228 |
|
229 void |
|
230 URLSearchParams::DeleteAll() |
|
231 { |
|
232 NS_NOTREACHED("Unexpected call to URLSearchParams::DeleteAll"); |
|
233 } |
|
234 |
|
235 void |
|
236 URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver) |
|
237 { |
|
238 NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObservers"); |
|
239 } |
|
240 |
|
241 } // namespace dom |
|
242 } // namespace mozilla |
|
243 |
|
244 #endif // mock_Link_h__ |