UNPKG

29.4 kBJavaScriptView Raw
1/**
2 * @license Angular v9.0.3
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs')) :
9 typeof define === 'function' && define.amd ? define('@angular/common/testing', ['exports', '@angular/core', '@angular/common', 'rxjs'], factory) :
10 (global = global || self, factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}, global.ng.common.testing = {}), global.ng.core, global.ng.common, global.rxjs));
11}(this, (function (exports, core, common, rxjs) { 'use strict';
12
13 /*! *****************************************************************************
14 Copyright (c) Microsoft Corporation. All rights reserved.
15 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
16 this file except in compliance with the License. You may obtain a copy of the
17 License at http://www.apache.org/licenses/LICENSE-2.0
18
19 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
21 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
22 MERCHANTABLITY OR NON-INFRINGEMENT.
23
24 See the Apache Version 2.0 License for specific language governing permissions
25 and limitations under the License.
26 ***************************************************************************** */
27 /* global Reflect, Promise */
28
29 var extendStatics = function(d, b) {
30 extendStatics = Object.setPrototypeOf ||
31 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
33 return extendStatics(d, b);
34 };
35
36 function __extends(d, b) {
37 extendStatics(d, b);
38 function __() { this.constructor = d; }
39 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40 }
41
42 var __assign = function() {
43 __assign = Object.assign || function __assign(t) {
44 for (var s, i = 1, n = arguments.length; i < n; i++) {
45 s = arguments[i];
46 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47 }
48 return t;
49 };
50 return __assign.apply(this, arguments);
51 };
52
53 function __rest(s, e) {
54 var t = {};
55 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56 t[p] = s[p];
57 if (s != null && typeof Object.getOwnPropertySymbols === "function")
58 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60 t[p[i]] = s[p[i]];
61 }
62 return t;
63 }
64
65 function __decorate(decorators, target, key, desc) {
66 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
67 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
68 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69 return c > 3 && r && Object.defineProperty(target, key, r), r;
70 }
71
72 function __param(paramIndex, decorator) {
73 return function (target, key) { decorator(target, key, paramIndex); }
74 }
75
76 function __metadata(metadataKey, metadataValue) {
77 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
78 }
79
80 function __awaiter(thisArg, _arguments, P, generator) {
81 return new (P || (P = Promise))(function (resolve, reject) {
82 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
83 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
84 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
85 step((generator = generator.apply(thisArg, _arguments || [])).next());
86 });
87 }
88
89 function __generator(thisArg, body) {
90 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
91 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
92 function verb(n) { return function (v) { return step([n, v]); }; }
93 function step(op) {
94 if (f) throw new TypeError("Generator is already executing.");
95 while (_) try {
96 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
97 if (y = 0, t) op = [op[0] & 2, t.value];
98 switch (op[0]) {
99 case 0: case 1: t = op; break;
100 case 4: _.label++; return { value: op[1], done: false };
101 case 5: _.label++; y = op[1]; op = [0]; continue;
102 case 7: op = _.ops.pop(); _.trys.pop(); continue;
103 default:
104 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
105 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
106 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
107 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
108 if (t[2]) _.ops.pop();
109 _.trys.pop(); continue;
110 }
111 op = body.call(thisArg, _);
112 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
113 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
114 }
115 }
116
117 function __exportStar(m, exports) {
118 for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
119 }
120
121 function __values(o) {
122 var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
123 if (m) return m.call(o);
124 return {
125 next: function () {
126 if (o && i >= o.length) o = void 0;
127 return { value: o && o[i++], done: !o };
128 }
129 };
130 }
131
132 function __read(o, n) {
133 var m = typeof Symbol === "function" && o[Symbol.iterator];
134 if (!m) return o;
135 var i = m.call(o), r, ar = [], e;
136 try {
137 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
138 }
139 catch (error) { e = { error: error }; }
140 finally {
141 try {
142 if (r && !r.done && (m = i["return"])) m.call(i);
143 }
144 finally { if (e) throw e.error; }
145 }
146 return ar;
147 }
148
149 function __spread() {
150 for (var ar = [], i = 0; i < arguments.length; i++)
151 ar = ar.concat(__read(arguments[i]));
152 return ar;
153 }
154
155 function __spreadArrays() {
156 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
157 for (var r = Array(s), k = 0, i = 0; i < il; i++)
158 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
159 r[k] = a[j];
160 return r;
161 };
162
163 function __await(v) {
164 return this instanceof __await ? (this.v = v, this) : new __await(v);
165 }
166
167 function __asyncGenerator(thisArg, _arguments, generator) {
168 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
169 var g = generator.apply(thisArg, _arguments || []), i, q = [];
170 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
171 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
172 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
173 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
174 function fulfill(value) { resume("next", value); }
175 function reject(value) { resume("throw", value); }
176 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
177 }
178
179 function __asyncDelegator(o) {
180 var i, p;
181 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
182 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
183 }
184
185 function __asyncValues(o) {
186 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
187 var m = o[Symbol.asyncIterator], i;
188 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
189 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
190 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
191 }
192
193 function __makeTemplateObject(cooked, raw) {
194 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
195 return cooked;
196 };
197
198 function __importStar(mod) {
199 if (mod && mod.__esModule) return mod;
200 var result = {};
201 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
202 result.default = mod;
203 return result;
204 }
205
206 function __importDefault(mod) {
207 return (mod && mod.__esModule) ? mod : { default: mod };
208 }
209
210 /**
211 * @license
212 * Copyright Google Inc. All Rights Reserved.
213 *
214 * Use of this source code is governed by an MIT-style license that can be
215 * found in the LICENSE file at https://angular.io/license
216 */
217 /**
218 * A spy for {@link Location} that allows tests to fire simulated location events.
219 *
220 * @publicApi
221 */
222 var SpyLocation = /** @class */ (function () {
223 function SpyLocation() {
224 this.urlChanges = [];
225 this._history = [new LocationState('', '', null)];
226 this._historyIndex = 0;
227 /** @internal */
228 this._subject = new core.EventEmitter();
229 /** @internal */
230 this._baseHref = '';
231 /** @internal */
232 this._platformStrategy = null;
233 /** @internal */
234 this._platformLocation = null;
235 /** @internal */
236 this._urlChangeListeners = [];
237 }
238 SpyLocation.prototype.setInitialPath = function (url) { this._history[this._historyIndex].path = url; };
239 SpyLocation.prototype.setBaseHref = function (url) { this._baseHref = url; };
240 SpyLocation.prototype.path = function () { return this._history[this._historyIndex].path; };
241 SpyLocation.prototype.getState = function () { return this._history[this._historyIndex].state; };
242 SpyLocation.prototype.isCurrentPathEqualTo = function (path, query) {
243 if (query === void 0) { query = ''; }
244 var givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
245 var currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
246 return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
247 };
248 SpyLocation.prototype.simulateUrlPop = function (pathname) {
249 this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'popstate' });
250 };
251 SpyLocation.prototype.simulateHashChange = function (pathname) {
252 // Because we don't prevent the native event, the browser will independently update the path
253 this.setInitialPath(pathname);
254 this.urlChanges.push('hash: ' + pathname);
255 this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'hashchange' });
256 };
257 SpyLocation.prototype.prepareExternalUrl = function (url) {
258 if (url.length > 0 && !url.startsWith('/')) {
259 url = '/' + url;
260 }
261 return this._baseHref + url;
262 };
263 SpyLocation.prototype.go = function (path, query, state) {
264 if (query === void 0) { query = ''; }
265 if (state === void 0) { state = null; }
266 path = this.prepareExternalUrl(path);
267 if (this._historyIndex > 0) {
268 this._history.splice(this._historyIndex + 1);
269 }
270 this._history.push(new LocationState(path, query, state));
271 this._historyIndex = this._history.length - 1;
272 var locationState = this._history[this._historyIndex - 1];
273 if (locationState.path == path && locationState.query == query) {
274 return;
275 }
276 var url = path + (query.length > 0 ? ('?' + query) : '');
277 this.urlChanges.push(url);
278 this._subject.emit({ 'url': url, 'pop': false });
279 };
280 SpyLocation.prototype.replaceState = function (path, query, state) {
281 if (query === void 0) { query = ''; }
282 if (state === void 0) { state = null; }
283 path = this.prepareExternalUrl(path);
284 var history = this._history[this._historyIndex];
285 if (history.path == path && history.query == query) {
286 return;
287 }
288 history.path = path;
289 history.query = query;
290 history.state = state;
291 var url = path + (query.length > 0 ? ('?' + query) : '');
292 this.urlChanges.push('replace: ' + url);
293 };
294 SpyLocation.prototype.forward = function () {
295 if (this._historyIndex < (this._history.length - 1)) {
296 this._historyIndex++;
297 this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
298 }
299 };
300 SpyLocation.prototype.back = function () {
301 if (this._historyIndex > 0) {
302 this._historyIndex--;
303 this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
304 }
305 };
306 SpyLocation.prototype.onUrlChange = function (fn) {
307 var _this = this;
308 this._urlChangeListeners.push(fn);
309 this.subscribe(function (v) { _this._notifyUrlChangeListeners(v.url, v.state); });
310 };
311 /** @internal */
312 SpyLocation.prototype._notifyUrlChangeListeners = function (url, state) {
313 if (url === void 0) { url = ''; }
314 this._urlChangeListeners.forEach(function (fn) { return fn(url, state); });
315 };
316 SpyLocation.prototype.subscribe = function (onNext, onThrow, onReturn) {
317 return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
318 };
319 SpyLocation.prototype.normalize = function (url) { return null; };
320 SpyLocation = __decorate([
321 core.Injectable()
322 ], SpyLocation);
323 return SpyLocation;
324 }());
325 var LocationState = /** @class */ (function () {
326 function LocationState(path, query, state) {
327 this.path = path;
328 this.query = query;
329 this.state = state;
330 }
331 return LocationState;
332 }());
333
334 /**
335 * @license
336 * Copyright Google Inc. All Rights Reserved.
337 *
338 * Use of this source code is governed by an MIT-style license that can be
339 * found in the LICENSE file at https://angular.io/license
340 */
341 /**
342 * A mock implementation of {@link LocationStrategy} that allows tests to fire simulated
343 * location events.
344 *
345 * @publicApi
346 */
347 var MockLocationStrategy = /** @class */ (function (_super) {
348 __extends(MockLocationStrategy, _super);
349 function MockLocationStrategy() {
350 var _this = _super.call(this) || this;
351 _this.internalBaseHref = '/';
352 _this.internalPath = '/';
353 _this.internalTitle = '';
354 _this.urlChanges = [];
355 /** @internal */
356 _this._subject = new core.EventEmitter();
357 _this.stateChanges = [];
358 return _this;
359 }
360 MockLocationStrategy.prototype.simulatePopState = function (url) {
361 this.internalPath = url;
362 this._subject.emit(new _MockPopStateEvent(this.path()));
363 };
364 MockLocationStrategy.prototype.path = function (includeHash) {
365 if (includeHash === void 0) { includeHash = false; }
366 return this.internalPath;
367 };
368 MockLocationStrategy.prototype.prepareExternalUrl = function (internal) {
369 if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
370 return this.internalBaseHref + internal.substring(1);
371 }
372 return this.internalBaseHref + internal;
373 };
374 MockLocationStrategy.prototype.pushState = function (ctx, title, path, query) {
375 // Add state change to changes array
376 this.stateChanges.push(ctx);
377 this.internalTitle = title;
378 var url = path + (query.length > 0 ? ('?' + query) : '');
379 this.internalPath = url;
380 var externalUrl = this.prepareExternalUrl(url);
381 this.urlChanges.push(externalUrl);
382 };
383 MockLocationStrategy.prototype.replaceState = function (ctx, title, path, query) {
384 // Reset the last index of stateChanges to the ctx (state) object
385 this.stateChanges[(this.stateChanges.length || 1) - 1] = ctx;
386 this.internalTitle = title;
387 var url = path + (query.length > 0 ? ('?' + query) : '');
388 this.internalPath = url;
389 var externalUrl = this.prepareExternalUrl(url);
390 this.urlChanges.push('replace: ' + externalUrl);
391 };
392 MockLocationStrategy.prototype.onPopState = function (fn) { this._subject.subscribe({ next: fn }); };
393 MockLocationStrategy.prototype.getBaseHref = function () { return this.internalBaseHref; };
394 MockLocationStrategy.prototype.back = function () {
395 if (this.urlChanges.length > 0) {
396 this.urlChanges.pop();
397 this.stateChanges.pop();
398 var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
399 this.simulatePopState(nextUrl);
400 }
401 };
402 MockLocationStrategy.prototype.forward = function () { throw 'not implemented'; };
403 MockLocationStrategy.prototype.getState = function () { return this.stateChanges[(this.stateChanges.length || 1) - 1]; };
404 MockLocationStrategy = __decorate([
405 core.Injectable(),
406 __metadata("design:paramtypes", [])
407 ], MockLocationStrategy);
408 return MockLocationStrategy;
409 }(common.LocationStrategy));
410 var _MockPopStateEvent = /** @class */ (function () {
411 function _MockPopStateEvent(newUrl) {
412 this.newUrl = newUrl;
413 this.pop = true;
414 this.type = 'popstate';
415 }
416 return _MockPopStateEvent;
417 }());
418
419 /**
420 * @license
421 * Copyright Google Inc. All Rights Reserved.
422 *
423 * Use of this source code is governed by an MIT-style license that can be
424 * found in the LICENSE file at https://angular.io/license
425 */
426 /**
427 * Parser from https://tools.ietf.org/html/rfc3986#appendix-B
428 * ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
429 * 12 3 4 5 6 7 8 9
430 *
431 * Example: http://www.ics.uci.edu/pub/ietf/uri/#Related
432 *
433 * Results in:
434 *
435 * $1 = http:
436 * $2 = http
437 * $3 = //www.ics.uci.edu
438 * $4 = www.ics.uci.edu
439 * $5 = /pub/ietf/uri/
440 * $6 = <undefined>
441 * $7 = <undefined>
442 * $8 = #Related
443 * $9 = Related
444 */
445 var urlParse = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
446 function parseUrl(urlStr, baseHref) {
447 var verifyProtocol = /^((http[s]?|ftp):\/\/)/;
448 var serverBase;
449 // URL class requires full URL. If the URL string doesn't start with protocol, we need to add
450 // an arbitrary base URL which can be removed afterward.
451 if (!verifyProtocol.test(urlStr)) {
452 serverBase = 'http://empty.com/';
453 }
454 var parsedUrl;
455 try {
456 parsedUrl = new URL(urlStr, serverBase);
457 }
458 catch (e) {
459 var result = urlParse.exec(serverBase || '' + urlStr);
460 if (!result) {
461 throw new Error("Invalid URL: " + urlStr + " with base: " + baseHref);
462 }
463 var hostSplit = result[4].split(':');
464 parsedUrl = {
465 protocol: result[1],
466 hostname: hostSplit[0],
467 port: hostSplit[1] || '',
468 pathname: result[5],
469 search: result[6],
470 hash: result[8],
471 };
472 }
473 if (parsedUrl.pathname && parsedUrl.pathname.indexOf(baseHref) === 0) {
474 parsedUrl.pathname = parsedUrl.pathname.substring(baseHref.length);
475 }
476 return {
477 hostname: !serverBase && parsedUrl.hostname || '',
478 protocol: !serverBase && parsedUrl.protocol || '',
479 port: !serverBase && parsedUrl.port || '',
480 pathname: parsedUrl.pathname || '/',
481 search: parsedUrl.search || '',
482 hash: parsedUrl.hash || '',
483 };
484 }
485 /**
486 * Provider for mock platform location config
487 *
488 * @publicApi
489 */
490 var MOCK_PLATFORM_LOCATION_CONFIG = new core.InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG');
491 /**
492 * Mock implementation of URL state.
493 *
494 * @publicApi
495 */
496 var MockPlatformLocation = /** @class */ (function () {
497 function MockPlatformLocation(config) {
498 this.baseHref = '';
499 this.hashUpdate = new rxjs.Subject();
500 this.urlChanges = [{ hostname: '', protocol: '', port: '', pathname: '/', search: '', hash: '', state: null }];
501 if (config) {
502 this.baseHref = config.appBaseHref || '';
503 var parsedChanges = this.parseChanges(null, config.startUrl || 'http://<empty>/', this.baseHref);
504 this.urlChanges[0] = __assign({}, parsedChanges);
505 }
506 }
507 Object.defineProperty(MockPlatformLocation.prototype, "hostname", {
508 get: function () { return this.urlChanges[0].hostname; },
509 enumerable: true,
510 configurable: true
511 });
512 Object.defineProperty(MockPlatformLocation.prototype, "protocol", {
513 get: function () { return this.urlChanges[0].protocol; },
514 enumerable: true,
515 configurable: true
516 });
517 Object.defineProperty(MockPlatformLocation.prototype, "port", {
518 get: function () { return this.urlChanges[0].port; },
519 enumerable: true,
520 configurable: true
521 });
522 Object.defineProperty(MockPlatformLocation.prototype, "pathname", {
523 get: function () { return this.urlChanges[0].pathname; },
524 enumerable: true,
525 configurable: true
526 });
527 Object.defineProperty(MockPlatformLocation.prototype, "search", {
528 get: function () { return this.urlChanges[0].search; },
529 enumerable: true,
530 configurable: true
531 });
532 Object.defineProperty(MockPlatformLocation.prototype, "hash", {
533 get: function () { return this.urlChanges[0].hash; },
534 enumerable: true,
535 configurable: true
536 });
537 Object.defineProperty(MockPlatformLocation.prototype, "state", {
538 get: function () { return this.urlChanges[0].state; },
539 enumerable: true,
540 configurable: true
541 });
542 MockPlatformLocation.prototype.getBaseHrefFromDOM = function () { return this.baseHref; };
543 MockPlatformLocation.prototype.onPopState = function (fn) {
544 // No-op: a state stack is not implemented, so
545 // no events will ever come.
546 };
547 MockPlatformLocation.prototype.onHashChange = function (fn) { this.hashUpdate.subscribe(fn); };
548 Object.defineProperty(MockPlatformLocation.prototype, "href", {
549 get: function () {
550 var url = this.protocol + "//" + this.hostname + (this.port ? ':' + this.port : '');
551 url += "" + (this.pathname === '/' ? '' : this.pathname) + this.search + this.hash;
552 return url;
553 },
554 enumerable: true,
555 configurable: true
556 });
557 Object.defineProperty(MockPlatformLocation.prototype, "url", {
558 get: function () { return "" + this.pathname + this.search + this.hash; },
559 enumerable: true,
560 configurable: true
561 });
562 MockPlatformLocation.prototype.parseChanges = function (state, url, baseHref) {
563 if (baseHref === void 0) { baseHref = ''; }
564 // When the `history.state` value is stored, it is always copied.
565 state = JSON.parse(JSON.stringify(state));
566 return __assign(__assign({}, parseUrl(url, baseHref)), { state: state });
567 };
568 MockPlatformLocation.prototype.replaceState = function (state, title, newUrl) {
569 var _a = this.parseChanges(state, newUrl), pathname = _a.pathname, search = _a.search, parsedState = _a.state, hash = _a.hash;
570 this.urlChanges[0] = __assign(__assign({}, this.urlChanges[0]), { pathname: pathname, search: search, hash: hash, state: parsedState });
571 };
572 MockPlatformLocation.prototype.pushState = function (state, title, newUrl) {
573 var _a = this.parseChanges(state, newUrl), pathname = _a.pathname, search = _a.search, parsedState = _a.state, hash = _a.hash;
574 this.urlChanges.unshift(__assign(__assign({}, this.urlChanges[0]), { pathname: pathname, search: search, hash: hash, state: parsedState }));
575 };
576 MockPlatformLocation.prototype.forward = function () { throw new Error('Not implemented'); };
577 MockPlatformLocation.prototype.back = function () {
578 var _this = this;
579 var oldUrl = this.url;
580 var oldHash = this.hash;
581 this.urlChanges.shift();
582 var newHash = this.hash;
583 if (oldHash !== newHash) {
584 scheduleMicroTask(function () { return _this.hashUpdate.next({
585 type: 'hashchange', state: null, oldUrl: oldUrl, newUrl: _this.url
586 }); });
587 }
588 };
589 MockPlatformLocation.prototype.getState = function () { return this.state; };
590 MockPlatformLocation = __decorate([
591 core.Injectable(),
592 __param(0, core.Inject(MOCK_PLATFORM_LOCATION_CONFIG)), __param(0, core.Optional()),
593 __metadata("design:paramtypes", [Object])
594 ], MockPlatformLocation);
595 return MockPlatformLocation;
596 }());
597 function scheduleMicroTask(cb) {
598 Promise.resolve(null).then(cb);
599 }
600
601 /**
602 * @license
603 * Copyright Google Inc. All Rights Reserved.
604 *
605 * Use of this source code is governed by an MIT-style license that can be
606 * found in the LICENSE file at https://angular.io/license
607 */
608
609 /**
610 * @license
611 * Copyright Google Inc. All Rights Reserved.
612 *
613 * Use of this source code is governed by an MIT-style license that can be
614 * found in the LICENSE file at https://angular.io/license
615 */
616 // This file only reexports content of the `src` folder. Keep it that way.
617
618 /**
619 * @license
620 * Copyright Google Inc. All Rights Reserved.
621 *
622 * Use of this source code is governed by an MIT-style license that can be
623 * found in the LICENSE file at https://angular.io/license
624 */
625
626 /**
627 * Generated bundle index. Do not edit.
628 */
629
630 exports.MOCK_PLATFORM_LOCATION_CONFIG = MOCK_PLATFORM_LOCATION_CONFIG;
631 exports.MockLocationStrategy = MockLocationStrategy;
632 exports.MockPlatformLocation = MockPlatformLocation;
633 exports.SpyLocation = SpyLocation;
634
635 Object.defineProperty(exports, '__esModule', { value: true });
636
637})));
638//# sourceMappingURL=common-testing.umd.js.map