1 |
|
2 |
|
3 |
|
4 |
|
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 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 | var SpyLocation = (function () {
|
26 | function SpyLocation() {
|
27 | this.urlChanges = [];
|
28 | this._history = [new LocationState('', '', null)];
|
29 | this._historyIndex = 0;
|
30 |
|
31 | this._subject = new core.EventEmitter();
|
32 |
|
33 | this._baseHref = '';
|
34 |
|
35 | this._platformStrategy = null;
|
36 |
|
37 | this._platformLocation = null;
|
38 |
|
39 | this._urlChangeListeners = [];
|
40 | }
|
41 | SpyLocation.prototype.setInitialPath = function (url) {
|
42 | this._history[this._historyIndex].path = url;
|
43 | };
|
44 | SpyLocation.prototype.setBaseHref = function (url) {
|
45 | this._baseHref = url;
|
46 | };
|
47 | SpyLocation.prototype.path = function () {
|
48 | return this._history[this._historyIndex].path;
|
49 | };
|
50 | SpyLocation.prototype.getState = function () {
|
51 | return this._history[this._historyIndex].state;
|
52 | };
|
53 | SpyLocation.prototype.isCurrentPathEqualTo = function (path, query) {
|
54 | if (query === void 0) { query = ''; }
|
55 | var givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
|
56 | var currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
|
57 | return currPath == givenPath + (query.length > 0 ? ('?' + query) : '');
|
58 | };
|
59 | SpyLocation.prototype.simulateUrlPop = function (pathname) {
|
60 | this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'popstate' });
|
61 | };
|
62 | SpyLocation.prototype.simulateHashChange = function (pathname) {
|
63 |
|
64 | this.setInitialPath(pathname);
|
65 | this.urlChanges.push('hash: ' + pathname);
|
66 | this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'hashchange' });
|
67 | };
|
68 | SpyLocation.prototype.prepareExternalUrl = function (url) {
|
69 | if (url.length > 0 && !url.startsWith('/')) {
|
70 | url = '/' + url;
|
71 | }
|
72 | return this._baseHref + url;
|
73 | };
|
74 | SpyLocation.prototype.go = function (path, query, state) {
|
75 | if (query === void 0) { query = ''; }
|
76 | if (state === void 0) { state = null; }
|
77 | path = this.prepareExternalUrl(path);
|
78 | if (this._historyIndex > 0) {
|
79 | this._history.splice(this._historyIndex + 1);
|
80 | }
|
81 | this._history.push(new LocationState(path, query, state));
|
82 | this._historyIndex = this._history.length - 1;
|
83 | var locationState = this._history[this._historyIndex - 1];
|
84 | if (locationState.path == path && locationState.query == query) {
|
85 | return;
|
86 | }
|
87 | var url = path + (query.length > 0 ? ('?' + query) : '');
|
88 | this.urlChanges.push(url);
|
89 | this._subject.emit({ 'url': url, 'pop': false });
|
90 | };
|
91 | SpyLocation.prototype.replaceState = function (path, query, state) {
|
92 | if (query === void 0) { query = ''; }
|
93 | if (state === void 0) { state = null; }
|
94 | path = this.prepareExternalUrl(path);
|
95 | var history = this._history[this._historyIndex];
|
96 | if (history.path == path && history.query == query) {
|
97 | return;
|
98 | }
|
99 | history.path = path;
|
100 | history.query = query;
|
101 | history.state = state;
|
102 | var url = path + (query.length > 0 ? ('?' + query) : '');
|
103 | this.urlChanges.push('replace: ' + url);
|
104 | };
|
105 | SpyLocation.prototype.forward = function () {
|
106 | if (this._historyIndex < (this._history.length - 1)) {
|
107 | this._historyIndex++;
|
108 | this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
|
109 | }
|
110 | };
|
111 | SpyLocation.prototype.back = function () {
|
112 | if (this._historyIndex > 0) {
|
113 | this._historyIndex--;
|
114 | this._subject.emit({ 'url': this.path(), 'state': this.getState(), 'pop': true });
|
115 | }
|
116 | };
|
117 | SpyLocation.prototype.onUrlChange = function (fn) {
|
118 | var _this = this;
|
119 | this._urlChangeListeners.push(fn);
|
120 | if (!this._urlChangeSubscription) {
|
121 | this._urlChangeSubscription = this.subscribe(function (v) {
|
122 | _this._notifyUrlChangeListeners(v.url, v.state);
|
123 | });
|
124 | }
|
125 | };
|
126 |
|
127 | SpyLocation.prototype._notifyUrlChangeListeners = function (url, state) {
|
128 | if (url === void 0) { url = ''; }
|
129 | this._urlChangeListeners.forEach(function (fn) { return fn(url, state); });
|
130 | };
|
131 | SpyLocation.prototype.subscribe = function (onNext, onThrow, onReturn) {
|
132 | return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
|
133 | };
|
134 | SpyLocation.prototype.normalize = function (url) {
|
135 | return null;
|
136 | };
|
137 | return SpyLocation;
|
138 | }());
|
139 | SpyLocation.decorators = [
|
140 | { type: core.Injectable }
|
141 | ];
|
142 | var LocationState = (function () {
|
143 | function LocationState(path, query, state) {
|
144 | this.path = path;
|
145 | this.query = query;
|
146 | this.state = state;
|
147 | }
|
148 | return LocationState;
|
149 | }());
|
150 |
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 | var extendStatics = function (d, b) {
|
167 | extendStatics = Object.setPrototypeOf ||
|
168 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
169 | function (d, b) { for (var p in b)
|
170 | if (b.hasOwnProperty(p))
|
171 | d[p] = b[p]; };
|
172 | return extendStatics(d, b);
|
173 | };
|
174 | function __extends(d, b) {
|
175 | extendStatics(d, b);
|
176 | function __() { this.constructor = d; }
|
177 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
178 | }
|
179 | var __assign = function () {
|
180 | __assign = Object.assign || function __assign(t) {
|
181 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
182 | s = arguments[i];
|
183 | for (var p in s)
|
184 | if (Object.prototype.hasOwnProperty.call(s, p))
|
185 | t[p] = s[p];
|
186 | }
|
187 | return t;
|
188 | };
|
189 | return __assign.apply(this, arguments);
|
190 | };
|
191 | function __rest(s, e) {
|
192 | var t = {};
|
193 | for (var p in s)
|
194 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
195 | t[p] = s[p];
|
196 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
197 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
198 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
199 | t[p[i]] = s[p[i]];
|
200 | }
|
201 | return t;
|
202 | }
|
203 | function __decorate(decorators, target, key, desc) {
|
204 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
205 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
206 | r = Reflect.decorate(decorators, target, key, desc);
|
207 | else
|
208 | for (var i = decorators.length - 1; i >= 0; i--)
|
209 | if (d = decorators[i])
|
210 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
211 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
212 | }
|
213 | function __param(paramIndex, decorator) {
|
214 | return function (target, key) { decorator(target, key, paramIndex); };
|
215 | }
|
216 | function __metadata(metadataKey, metadataValue) {
|
217 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
218 | return Reflect.metadata(metadataKey, metadataValue);
|
219 | }
|
220 | function __awaiter(thisArg, _arguments, P, generator) {
|
221 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
222 | return new (P || (P = Promise))(function (resolve, reject) {
|
223 | function fulfilled(value) { try {
|
224 | step(generator.next(value));
|
225 | }
|
226 | catch (e) {
|
227 | reject(e);
|
228 | } }
|
229 | function rejected(value) { try {
|
230 | step(generator["throw"](value));
|
231 | }
|
232 | catch (e) {
|
233 | reject(e);
|
234 | } }
|
235 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
236 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
237 | });
|
238 | }
|
239 | function __generator(thisArg, body) {
|
240 | var _ = { label: 0, sent: function () { if (t[0] & 1)
|
241 | throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
242 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
243 | function verb(n) { return function (v) { return step([n, v]); }; }
|
244 | function step(op) {
|
245 | if (f)
|
246 | throw new TypeError("Generator is already executing.");
|
247 | while (_)
|
248 | try {
|
249 | 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)
|
250 | return t;
|
251 | if (y = 0, t)
|
252 | op = [op[0] & 2, t.value];
|
253 | switch (op[0]) {
|
254 | case 0:
|
255 | case 1:
|
256 | t = op;
|
257 | break;
|
258 | case 4:
|
259 | _.label++;
|
260 | return { value: op[1], done: false };
|
261 | case 5:
|
262 | _.label++;
|
263 | y = op[1];
|
264 | op = [0];
|
265 | continue;
|
266 | case 7:
|
267 | op = _.ops.pop();
|
268 | _.trys.pop();
|
269 | continue;
|
270 | default:
|
271 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
272 | _ = 0;
|
273 | continue;
|
274 | }
|
275 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
276 | _.label = op[1];
|
277 | break;
|
278 | }
|
279 | if (op[0] === 6 && _.label < t[1]) {
|
280 | _.label = t[1];
|
281 | t = op;
|
282 | break;
|
283 | }
|
284 | if (t && _.label < t[2]) {
|
285 | _.label = t[2];
|
286 | _.ops.push(op);
|
287 | break;
|
288 | }
|
289 | if (t[2])
|
290 | _.ops.pop();
|
291 | _.trys.pop();
|
292 | continue;
|
293 | }
|
294 | op = body.call(thisArg, _);
|
295 | }
|
296 | catch (e) {
|
297 | op = [6, e];
|
298 | y = 0;
|
299 | }
|
300 | finally {
|
301 | f = t = 0;
|
302 | }
|
303 | if (op[0] & 5)
|
304 | throw op[1];
|
305 | return { value: op[0] ? op[1] : void 0, done: true };
|
306 | }
|
307 | }
|
308 | var __createBinding = Object.create ? (function (o, m, k, k2) {
|
309 | if (k2 === undefined)
|
310 | k2 = k;
|
311 | Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
312 | }) : (function (o, m, k, k2) {
|
313 | if (k2 === undefined)
|
314 | k2 = k;
|
315 | o[k2] = m[k];
|
316 | });
|
317 | function __exportStar(m, exports) {
|
318 | for (var p in m)
|
319 | if (p !== "default" && !exports.hasOwnProperty(p))
|
320 | __createBinding(exports, m, p);
|
321 | }
|
322 | function __values(o) {
|
323 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
324 | if (m)
|
325 | return m.call(o);
|
326 | if (o && typeof o.length === "number")
|
327 | return {
|
328 | next: function () {
|
329 | if (o && i >= o.length)
|
330 | o = void 0;
|
331 | return { value: o && o[i++], done: !o };
|
332 | }
|
333 | };
|
334 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
335 | }
|
336 | function __read(o, n) {
|
337 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
338 | if (!m)
|
339 | return o;
|
340 | var i = m.call(o), r, ar = [], e;
|
341 | try {
|
342 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
343 | ar.push(r.value);
|
344 | }
|
345 | catch (error) {
|
346 | e = { error: error };
|
347 | }
|
348 | finally {
|
349 | try {
|
350 | if (r && !r.done && (m = i["return"]))
|
351 | m.call(i);
|
352 | }
|
353 | finally {
|
354 | if (e)
|
355 | throw e.error;
|
356 | }
|
357 | }
|
358 | return ar;
|
359 | }
|
360 | function __spread() {
|
361 | for (var ar = [], i = 0; i < arguments.length; i++)
|
362 | ar = ar.concat(__read(arguments[i]));
|
363 | return ar;
|
364 | }
|
365 | function __spreadArrays() {
|
366 | for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
367 | s += arguments[i].length;
|
368 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
369 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
370 | r[k] = a[j];
|
371 | return r;
|
372 | }
|
373 | ;
|
374 | function __await(v) {
|
375 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
376 | }
|
377 | function __asyncGenerator(thisArg, _arguments, generator) {
|
378 | if (!Symbol.asyncIterator)
|
379 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
380 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
381 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
382 | function verb(n) { if (g[n])
|
383 | i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
384 | function resume(n, v) { try {
|
385 | step(g[n](v));
|
386 | }
|
387 | catch (e) {
|
388 | settle(q[0][3], e);
|
389 | } }
|
390 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
391 | function fulfill(value) { resume("next", value); }
|
392 | function reject(value) { resume("throw", value); }
|
393 | function settle(f, v) { if (f(v), q.shift(), q.length)
|
394 | resume(q[0][0], q[0][1]); }
|
395 | }
|
396 | function __asyncDelegator(o) {
|
397 | var i, p;
|
398 | return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
399 | 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; }
|
400 | }
|
401 | function __asyncValues(o) {
|
402 | if (!Symbol.asyncIterator)
|
403 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
404 | var m = o[Symbol.asyncIterator], i;
|
405 | 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);
|
406 | 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); }); }; }
|
407 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
408 | }
|
409 | function __makeTemplateObject(cooked, raw) {
|
410 | if (Object.defineProperty) {
|
411 | Object.defineProperty(cooked, "raw", { value: raw });
|
412 | }
|
413 | else {
|
414 | cooked.raw = raw;
|
415 | }
|
416 | return cooked;
|
417 | }
|
418 | ;
|
419 | var __setModuleDefault = Object.create ? (function (o, v) {
|
420 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
421 | }) : function (o, v) {
|
422 | o["default"] = v;
|
423 | };
|
424 | function __importStar(mod) {
|
425 | if (mod && mod.__esModule)
|
426 | return mod;
|
427 | var result = {};
|
428 | if (mod != null)
|
429 | for (var k in mod)
|
430 | if (Object.hasOwnProperty.call(mod, k))
|
431 | __createBinding(result, mod, k);
|
432 | __setModuleDefault(result, mod);
|
433 | return result;
|
434 | }
|
435 | function __importDefault(mod) {
|
436 | return (mod && mod.__esModule) ? mod : { default: mod };
|
437 | }
|
438 | function __classPrivateFieldGet(receiver, privateMap) {
|
439 | if (!privateMap.has(receiver)) {
|
440 | throw new TypeError("attempted to get private field on non-instance");
|
441 | }
|
442 | return privateMap.get(receiver);
|
443 | }
|
444 | function __classPrivateFieldSet(receiver, privateMap, value) {
|
445 | if (!privateMap.has(receiver)) {
|
446 | throw new TypeError("attempted to set private field on non-instance");
|
447 | }
|
448 | privateMap.set(receiver, value);
|
449 | return value;
|
450 | }
|
451 |
|
452 | |
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 | var MockLocationStrategy = (function (_super) {
|
459 | __extends(MockLocationStrategy, _super);
|
460 | function MockLocationStrategy() {
|
461 | var _this = _super.call(this) || this;
|
462 | _this.internalBaseHref = '/';
|
463 | _this.internalPath = '/';
|
464 | _this.internalTitle = '';
|
465 | _this.urlChanges = [];
|
466 |
|
467 | _this._subject = new core.EventEmitter();
|
468 | _this.stateChanges = [];
|
469 | return _this;
|
470 | }
|
471 | MockLocationStrategy.prototype.simulatePopState = function (url) {
|
472 | this.internalPath = url;
|
473 | this._subject.emit(new _MockPopStateEvent(this.path()));
|
474 | };
|
475 | MockLocationStrategy.prototype.path = function (includeHash) {
|
476 | if (includeHash === void 0) { includeHash = false; }
|
477 | return this.internalPath;
|
478 | };
|
479 | MockLocationStrategy.prototype.prepareExternalUrl = function (internal) {
|
480 | if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
|
481 | return this.internalBaseHref + internal.substring(1);
|
482 | }
|
483 | return this.internalBaseHref + internal;
|
484 | };
|
485 | MockLocationStrategy.prototype.pushState = function (ctx, title, path, query) {
|
486 |
|
487 | this.stateChanges.push(ctx);
|
488 | this.internalTitle = title;
|
489 | var url = path + (query.length > 0 ? ('?' + query) : '');
|
490 | this.internalPath = url;
|
491 | var externalUrl = this.prepareExternalUrl(url);
|
492 | this.urlChanges.push(externalUrl);
|
493 | };
|
494 | MockLocationStrategy.prototype.replaceState = function (ctx, title, path, query) {
|
495 |
|
496 | this.stateChanges[(this.stateChanges.length || 1) - 1] = ctx;
|
497 | this.internalTitle = title;
|
498 | var url = path + (query.length > 0 ? ('?' + query) : '');
|
499 | this.internalPath = url;
|
500 | var externalUrl = this.prepareExternalUrl(url);
|
501 | this.urlChanges.push('replace: ' + externalUrl);
|
502 | };
|
503 | MockLocationStrategy.prototype.onPopState = function (fn) {
|
504 | this._subject.subscribe({ next: fn });
|
505 | };
|
506 | MockLocationStrategy.prototype.getBaseHref = function () {
|
507 | return this.internalBaseHref;
|
508 | };
|
509 | MockLocationStrategy.prototype.back = function () {
|
510 | if (this.urlChanges.length > 0) {
|
511 | this.urlChanges.pop();
|
512 | this.stateChanges.pop();
|
513 | var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
|
514 | this.simulatePopState(nextUrl);
|
515 | }
|
516 | };
|
517 | MockLocationStrategy.prototype.forward = function () {
|
518 | throw 'not implemented';
|
519 | };
|
520 | MockLocationStrategy.prototype.getState = function () {
|
521 | return this.stateChanges[(this.stateChanges.length || 1) - 1];
|
522 | };
|
523 | return MockLocationStrategy;
|
524 | }(common.LocationStrategy));
|
525 | MockLocationStrategy.decorators = [
|
526 | { type: core.Injectable }
|
527 | ];
|
528 | MockLocationStrategy.ctorParameters = function () { return []; };
|
529 | var _MockPopStateEvent = (function () {
|
530 | function _MockPopStateEvent(newUrl) {
|
531 | this.newUrl = newUrl;
|
532 | this.pop = true;
|
533 | this.type = 'popstate';
|
534 | }
|
535 | return _MockPopStateEvent;
|
536 | }());
|
537 |
|
538 | |
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 | |
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 | var urlParse = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
565 | function parseUrl(urlStr, baseHref) {
|
566 | var verifyProtocol = /^((http[s]?|ftp):\/\/)/;
|
567 | var serverBase;
|
568 |
|
569 |
|
570 | if (!verifyProtocol.test(urlStr)) {
|
571 | serverBase = 'http://empty.com/';
|
572 | }
|
573 | var parsedUrl;
|
574 | try {
|
575 | parsedUrl = new URL(urlStr, serverBase);
|
576 | }
|
577 | catch (e) {
|
578 | var result = urlParse.exec(serverBase || '' + urlStr);
|
579 | if (!result) {
|
580 | throw new Error("Invalid URL: " + urlStr + " with base: " + baseHref);
|
581 | }
|
582 | var hostSplit = result[4].split(':');
|
583 | parsedUrl = {
|
584 | protocol: result[1],
|
585 | hostname: hostSplit[0],
|
586 | port: hostSplit[1] || '',
|
587 | pathname: result[5],
|
588 | search: result[6],
|
589 | hash: result[8],
|
590 | };
|
591 | }
|
592 | if (parsedUrl.pathname && parsedUrl.pathname.indexOf(baseHref) === 0) {
|
593 | parsedUrl.pathname = parsedUrl.pathname.substring(baseHref.length);
|
594 | }
|
595 | return {
|
596 | hostname: !serverBase && parsedUrl.hostname || '',
|
597 | protocol: !serverBase && parsedUrl.protocol || '',
|
598 | port: !serverBase && parsedUrl.port || '',
|
599 | pathname: parsedUrl.pathname || '/',
|
600 | search: parsedUrl.search || '',
|
601 | hash: parsedUrl.hash || '',
|
602 | };
|
603 | }
|
604 | |
605 |
|
606 |
|
607 |
|
608 |
|
609 | var MOCK_PLATFORM_LOCATION_CONFIG = new core.InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG');
|
610 | |
611 |
|
612 |
|
613 |
|
614 |
|
615 | var MockPlatformLocation = (function () {
|
616 | function MockPlatformLocation(config) {
|
617 | this.baseHref = '';
|
618 | this.hashUpdate = new rxjs.Subject();
|
619 | this.urlChanges = [{ hostname: '', protocol: '', port: '', pathname: '/', search: '', hash: '', state: null }];
|
620 | if (config) {
|
621 | this.baseHref = config.appBaseHref || '';
|
622 | var parsedChanges = this.parseChanges(null, config.startUrl || 'http://<empty>/', this.baseHref);
|
623 | this.urlChanges[0] = Object.assign({}, parsedChanges);
|
624 | }
|
625 | }
|
626 | Object.defineProperty(MockPlatformLocation.prototype, "hostname", {
|
627 | get: function () {
|
628 | return this.urlChanges[0].hostname;
|
629 | },
|
630 | enumerable: false,
|
631 | configurable: true
|
632 | });
|
633 | Object.defineProperty(MockPlatformLocation.prototype, "protocol", {
|
634 | get: function () {
|
635 | return this.urlChanges[0].protocol;
|
636 | },
|
637 | enumerable: false,
|
638 | configurable: true
|
639 | });
|
640 | Object.defineProperty(MockPlatformLocation.prototype, "port", {
|
641 | get: function () {
|
642 | return this.urlChanges[0].port;
|
643 | },
|
644 | enumerable: false,
|
645 | configurable: true
|
646 | });
|
647 | Object.defineProperty(MockPlatformLocation.prototype, "pathname", {
|
648 | get: function () {
|
649 | return this.urlChanges[0].pathname;
|
650 | },
|
651 | enumerable: false,
|
652 | configurable: true
|
653 | });
|
654 | Object.defineProperty(MockPlatformLocation.prototype, "search", {
|
655 | get: function () {
|
656 | return this.urlChanges[0].search;
|
657 | },
|
658 | enumerable: false,
|
659 | configurable: true
|
660 | });
|
661 | Object.defineProperty(MockPlatformLocation.prototype, "hash", {
|
662 | get: function () {
|
663 | return this.urlChanges[0].hash;
|
664 | },
|
665 | enumerable: false,
|
666 | configurable: true
|
667 | });
|
668 | Object.defineProperty(MockPlatformLocation.prototype, "state", {
|
669 | get: function () {
|
670 | return this.urlChanges[0].state;
|
671 | },
|
672 | enumerable: false,
|
673 | configurable: true
|
674 | });
|
675 | MockPlatformLocation.prototype.getBaseHrefFromDOM = function () {
|
676 | return this.baseHref;
|
677 | };
|
678 | MockPlatformLocation.prototype.onPopState = function (fn) {
|
679 |
|
680 |
|
681 | };
|
682 | MockPlatformLocation.prototype.onHashChange = function (fn) {
|
683 | this.hashUpdate.subscribe(fn);
|
684 | };
|
685 | Object.defineProperty(MockPlatformLocation.prototype, "href", {
|
686 | get: function () {
|
687 | var url = this.protocol + "//" + this.hostname + (this.port ? ':' + this.port : '');
|
688 | url += "" + (this.pathname === '/' ? '' : this.pathname) + this.search + this.hash;
|
689 | return url;
|
690 | },
|
691 | enumerable: false,
|
692 | configurable: true
|
693 | });
|
694 | Object.defineProperty(MockPlatformLocation.prototype, "url", {
|
695 | get: function () {
|
696 | return "" + this.pathname + this.search + this.hash;
|
697 | },
|
698 | enumerable: false,
|
699 | configurable: true
|
700 | });
|
701 | MockPlatformLocation.prototype.parseChanges = function (state, url, baseHref) {
|
702 | if (baseHref === void 0) { baseHref = ''; }
|
703 |
|
704 | state = JSON.parse(JSON.stringify(state));
|
705 | return Object.assign(Object.assign({}, parseUrl(url, baseHref)), { state: state });
|
706 | };
|
707 | MockPlatformLocation.prototype.replaceState = function (state, title, newUrl) {
|
708 | var _a = this.parseChanges(state, newUrl), pathname = _a.pathname, search = _a.search, parsedState = _a.state, hash = _a.hash;
|
709 | this.urlChanges[0] = Object.assign(Object.assign({}, this.urlChanges[0]), { pathname: pathname, search: search, hash: hash, state: parsedState });
|
710 | };
|
711 | MockPlatformLocation.prototype.pushState = function (state, title, newUrl) {
|
712 | var _a = this.parseChanges(state, newUrl), pathname = _a.pathname, search = _a.search, parsedState = _a.state, hash = _a.hash;
|
713 | this.urlChanges.unshift(Object.assign(Object.assign({}, this.urlChanges[0]), { pathname: pathname, search: search, hash: hash, state: parsedState }));
|
714 | };
|
715 | MockPlatformLocation.prototype.forward = function () {
|
716 | throw new Error('Not implemented');
|
717 | };
|
718 | MockPlatformLocation.prototype.back = function () {
|
719 | var _this = this;
|
720 | var oldUrl = this.url;
|
721 | var oldHash = this.hash;
|
722 | this.urlChanges.shift();
|
723 | var newHash = this.hash;
|
724 | if (oldHash !== newHash) {
|
725 | scheduleMicroTask(function () { return _this.hashUpdate.next({ type: 'hashchange', state: null, oldUrl: oldUrl, newUrl: _this.url }); });
|
726 | }
|
727 | };
|
728 | MockPlatformLocation.prototype.getState = function () {
|
729 | return this.state;
|
730 | };
|
731 | return MockPlatformLocation;
|
732 | }());
|
733 | MockPlatformLocation.decorators = [
|
734 | { type: core.Injectable }
|
735 | ];
|
736 | MockPlatformLocation.ctorParameters = function () { return [
|
737 | { type: undefined, decorators: [{ type: core.Inject, args: [MOCK_PLATFORM_LOCATION_CONFIG,] }, { type: core.Optional }] }
|
738 | ]; };
|
739 | function scheduleMicroTask(cb) {
|
740 | Promise.resolve(null).then(cb);
|
741 | }
|
742 |
|
743 | |
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 | |
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 | |
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 | |
769 |
|
770 |
|
771 |
|
772 | exports.MOCK_PLATFORM_LOCATION_CONFIG = MOCK_PLATFORM_LOCATION_CONFIG;
|
773 | exports.MockLocationStrategy = MockLocationStrategy;
|
774 | exports.MockPlatformLocation = MockPlatformLocation;
|
775 | exports.SpyLocation = SpyLocation;
|
776 |
|
777 | Object.defineProperty(exports, '__esModule', { value: true });
|
778 |
|
779 | })));
|
780 |
|