@angular-wave/angular.ts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +29 -0
  3. package/.github/workflows/playwright.yml +27 -0
  4. package/CHANGELOG.md +17974 -0
  5. package/CODE_OF_CONDUCT.md +3 -0
  6. package/CONTRIBUTING.md +246 -0
  7. package/DEVELOPERS.md +488 -0
  8. package/LICENSE +22 -0
  9. package/Makefile +31 -0
  10. package/README.md +115 -0
  11. package/RELEASE.md +98 -0
  12. package/SECURITY.md +16 -0
  13. package/TRIAGING.md +135 -0
  14. package/css/angular.css +22 -0
  15. package/dist/angular-ts.cjs.js +36843 -0
  16. package/dist/angular-ts.esm.js +36841 -0
  17. package/dist/angular-ts.umd.js +36848 -0
  18. package/dist/build/angular-animate.js +4272 -0
  19. package/dist/build/angular-aria.js +426 -0
  20. package/dist/build/angular-message-format.js +1072 -0
  21. package/dist/build/angular-messages.js +829 -0
  22. package/dist/build/angular-mocks.js +3757 -0
  23. package/dist/build/angular-parse-ext.js +1275 -0
  24. package/dist/build/angular-resource.js +911 -0
  25. package/dist/build/angular-route.js +1266 -0
  26. package/dist/build/angular-sanitize.js +891 -0
  27. package/dist/build/angular-touch.js +368 -0
  28. package/dist/build/angular.js +36600 -0
  29. package/e2e/unit.spec.ts +15 -0
  30. package/images/android-chrome-192x192.png +0 -0
  31. package/images/android-chrome-512x512.png +0 -0
  32. package/images/apple-touch-icon.png +0 -0
  33. package/images/favicon-16x16.png +0 -0
  34. package/images/favicon-32x32.png +0 -0
  35. package/images/favicon.ico +0 -0
  36. package/images/site.webmanifest +1 -0
  37. package/index.html +104 -0
  38. package/package.json +47 -0
  39. package/playwright.config.ts +78 -0
  40. package/public/circle.html +1 -0
  41. package/public/my_child_directive.html +1 -0
  42. package/public/my_directive.html +1 -0
  43. package/public/my_other_directive.html +1 -0
  44. package/public/test.html +1 -0
  45. package/rollup.config.js +31 -0
  46. package/src/animations/animateCache.js +55 -0
  47. package/src/animations/animateChildrenDirective.js +105 -0
  48. package/src/animations/animateCss.js +1139 -0
  49. package/src/animations/animateCssDriver.js +291 -0
  50. package/src/animations/animateJs.js +367 -0
  51. package/src/animations/animateJsDriver.js +67 -0
  52. package/src/animations/animateQueue.js +851 -0
  53. package/src/animations/animation.js +506 -0
  54. package/src/animations/module.js +779 -0
  55. package/src/animations/ngAnimateSwap.js +119 -0
  56. package/src/animations/rafScheduler.js +50 -0
  57. package/src/animations/shared.js +378 -0
  58. package/src/constants.js +20 -0
  59. package/src/core/animate.js +845 -0
  60. package/src/core/animateCss.js +73 -0
  61. package/src/core/animateRunner.js +195 -0
  62. package/src/core/attributes.js +199 -0
  63. package/src/core/cache.js +45 -0
  64. package/src/core/compile.js +4727 -0
  65. package/src/core/controller.js +225 -0
  66. package/src/core/exceptionHandler.js +63 -0
  67. package/src/core/filter.js +146 -0
  68. package/src/core/interpolate.js +442 -0
  69. package/src/core/interval.js +188 -0
  70. package/src/core/intervalFactory.js +57 -0
  71. package/src/core/location.js +1086 -0
  72. package/src/core/parser/parse.js +2562 -0
  73. package/src/core/parser/parse.md +13 -0
  74. package/src/core/q.js +746 -0
  75. package/src/core/rootScope.js +1596 -0
  76. package/src/core/sanitizeUri.js +85 -0
  77. package/src/core/sce.js +1161 -0
  78. package/src/core/taskTrackerFactory.js +125 -0
  79. package/src/core/timeout.js +121 -0
  80. package/src/core/urlUtils.js +187 -0
  81. package/src/core/utils.js +1349 -0
  82. package/src/directive/a.js +37 -0
  83. package/src/directive/attrs.js +283 -0
  84. package/src/directive/bind.js +51 -0
  85. package/src/directive/bind.md +142 -0
  86. package/src/directive/change.js +12 -0
  87. package/src/directive/change.md +25 -0
  88. package/src/directive/cloak.js +12 -0
  89. package/src/directive/cloak.md +24 -0
  90. package/src/directive/events.js +75 -0
  91. package/src/directive/events.md +166 -0
  92. package/src/directive/form.js +725 -0
  93. package/src/directive/init.js +15 -0
  94. package/src/directive/init.md +41 -0
  95. package/src/directive/input.js +1783 -0
  96. package/src/directive/list.js +46 -0
  97. package/src/directive/list.md +22 -0
  98. package/src/directive/ngClass.js +249 -0
  99. package/src/directive/ngController.js +64 -0
  100. package/src/directive/ngCsp.js +82 -0
  101. package/src/directive/ngIf.js +134 -0
  102. package/src/directive/ngInclude.js +217 -0
  103. package/src/directive/ngModel.js +1356 -0
  104. package/src/directive/ngModelOptions.js +509 -0
  105. package/src/directive/ngOptions.js +670 -0
  106. package/src/directive/ngRef.js +90 -0
  107. package/src/directive/ngRepeat.js +650 -0
  108. package/src/directive/ngShowHide.js +255 -0
  109. package/src/directive/ngSwitch.js +178 -0
  110. package/src/directive/ngTransclude.js +98 -0
  111. package/src/directive/non-bindable.js +11 -0
  112. package/src/directive/non-bindable.md +17 -0
  113. package/src/directive/script.js +30 -0
  114. package/src/directive/select.js +624 -0
  115. package/src/directive/style.js +25 -0
  116. package/src/directive/style.md +23 -0
  117. package/src/directive/validators.js +329 -0
  118. package/src/exts/aria.js +544 -0
  119. package/src/exts/messages.js +852 -0
  120. package/src/filters/filter.js +207 -0
  121. package/src/filters/filter.md +69 -0
  122. package/src/filters/filters.js +239 -0
  123. package/src/filters/json.md +16 -0
  124. package/src/filters/limit-to.js +43 -0
  125. package/src/filters/limit-to.md +19 -0
  126. package/src/filters/order-by.js +183 -0
  127. package/src/filters/order-by.md +83 -0
  128. package/src/index.js +13 -0
  129. package/src/injector.js +1034 -0
  130. package/src/jqLite.js +1117 -0
  131. package/src/loader.js +1320 -0
  132. package/src/public.js +215 -0
  133. package/src/routeToRegExp.js +41 -0
  134. package/src/services/anchorScroll.js +135 -0
  135. package/src/services/browser.js +321 -0
  136. package/src/services/cacheFactory.js +398 -0
  137. package/src/services/cookieReader.js +72 -0
  138. package/src/services/document.js +64 -0
  139. package/src/services/http.js +1537 -0
  140. package/src/services/httpBackend.js +206 -0
  141. package/src/services/log.js +160 -0
  142. package/src/services/templateRequest.js +139 -0
  143. package/test/angular.spec.js +2153 -0
  144. package/test/aria/aria.spec.js +1245 -0
  145. package/test/binding.spec.js +504 -0
  146. package/test/build-test.html +14 -0
  147. package/test/injector.spec.js +2327 -0
  148. package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
  149. package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
  150. package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
  151. package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
  152. package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
  153. package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
  154. package/test/jasmine/jasmine-browser.json +17 -0
  155. package/test/jasmine/jasmine.json +9 -0
  156. package/test/jqlite.spec.js +2133 -0
  157. package/test/loader.spec.js +219 -0
  158. package/test/messages/messages.spec.js +1146 -0
  159. package/test/min-err.spec.js +174 -0
  160. package/test/mock-test.html +13 -0
  161. package/test/module-test.html +15 -0
  162. package/test/ng/anomate.spec.js +606 -0
  163. package/test/ng/cache-factor.spec.js +334 -0
  164. package/test/ng/compile.spec.js +17956 -0
  165. package/test/ng/controller-provider.spec.js +227 -0
  166. package/test/ng/cookie-reader.spec.js +98 -0
  167. package/test/ng/directive/a.spec.js +192 -0
  168. package/test/ng/directive/bind.spec.js +334 -0
  169. package/test/ng/directive/boolean.spec.js +136 -0
  170. package/test/ng/directive/change.spec.js +71 -0
  171. package/test/ng/directive/class.spec.js +858 -0
  172. package/test/ng/directive/click.spec.js +38 -0
  173. package/test/ng/directive/cloak.spec.js +44 -0
  174. package/test/ng/directive/constoller.spec.js +194 -0
  175. package/test/ng/directive/element-style.spec.js +92 -0
  176. package/test/ng/directive/event.spec.js +282 -0
  177. package/test/ng/directive/form.spec.js +1518 -0
  178. package/test/ng/directive/href.spec.js +143 -0
  179. package/test/ng/directive/if.spec.js +402 -0
  180. package/test/ng/directive/include.spec.js +828 -0
  181. package/test/ng/directive/init.spec.js +68 -0
  182. package/test/ng/directive/input.spec.js +3810 -0
  183. package/test/ng/directive/list.spec.js +170 -0
  184. package/test/ng/directive/model-options.spec.js +1008 -0
  185. package/test/ng/directive/model.spec.js +1905 -0
  186. package/test/ng/directive/non-bindable.spec.js +55 -0
  187. package/test/ng/directive/options.spec.js +3583 -0
  188. package/test/ng/directive/ref.spec.js +575 -0
  189. package/test/ng/directive/repeat.spec.js +1675 -0
  190. package/test/ng/directive/script.spec.js +52 -0
  191. package/test/ng/directive/scrset.spec.js +67 -0
  192. package/test/ng/directive/select.spec.js +2541 -0
  193. package/test/ng/directive/show-hide.spec.js +253 -0
  194. package/test/ng/directive/src.spec.js +157 -0
  195. package/test/ng/directive/style.spec.js +178 -0
  196. package/test/ng/directive/switch.spec.js +647 -0
  197. package/test/ng/directive/validators.spec.js +717 -0
  198. package/test/ng/document.spec.js +52 -0
  199. package/test/ng/filter/filter.spec.js +714 -0
  200. package/test/ng/filter/filters.spec.js +35 -0
  201. package/test/ng/filter/limit-to.spec.js +251 -0
  202. package/test/ng/filter/order-by.spec.js +891 -0
  203. package/test/ng/filter.spec.js +149 -0
  204. package/test/ng/http-backend.spec.js +398 -0
  205. package/test/ng/http.spec.js +4071 -0
  206. package/test/ng/interpolate.spec.js +642 -0
  207. package/test/ng/interval.spec.js +343 -0
  208. package/test/ng/location.spec.js +3488 -0
  209. package/test/ng/on.spec.js +229 -0
  210. package/test/ng/parse.spec.js +4655 -0
  211. package/test/ng/prop.spec.js +805 -0
  212. package/test/ng/q.spec.js +2904 -0
  213. package/test/ng/root-element.spec.js +16 -0
  214. package/test/ng/sanitize-uri.spec.js +249 -0
  215. package/test/ng/sce.spec.js +660 -0
  216. package/test/ng/scope.spec.js +3442 -0
  217. package/test/ng/template-request.spec.js +236 -0
  218. package/test/ng/timeout.spec.js +351 -0
  219. package/test/ng/url-utils.spec.js +156 -0
  220. package/test/ng/utils.spec.js +144 -0
  221. package/test/original-test.html +21 -0
  222. package/test/public.spec.js +34 -0
  223. package/test/sanitize/bing-html.spec.js +36 -0
  224. package/test/server/express.js +158 -0
  225. package/test/test-utils.js +11 -0
  226. package/tsconfig.json +17 -0
  227. package/types/angular.d.ts +138 -0
  228. package/types/global.d.ts +9 -0
  229. package/types/index.d.ts +2357 -0
  230. package/types/jqlite.d.ts +558 -0
  231. package/vite.config.js +14 -0
@@ -0,0 +1,3488 @@
1
+ import {
2
+ LocationHtml5Url,
3
+ LocationHashbangUrl,
4
+ $LocationProvider,
5
+ LocationHashbangInHtml5Url,
6
+ } from "../../src/core/location";
7
+ import { publishExternalAPI } from "../../src/public";
8
+ import { createInjector } from "../../src/injector";
9
+
10
+ describe("$location", () => {
11
+ let module;
12
+ beforeEach(() => {
13
+ publishExternalAPI();
14
+ module = window.angular.module("test1", ["ng"]);
15
+ });
16
+
17
+ // function initService(options) {
18
+ // module.config(($provide, $locationProvider) => {
19
+ // $locationProvider.html5Mode(options.html5Mode);
20
+ // $locationProvider.hashPrefix(options.hashPrefix);
21
+ // $provide.value("$sniffer", { history: options.supportHistory });
22
+ // });
23
+ // }
24
+
25
+ describe("defaults", () => {
26
+ it('should have hashPrefix of "!"', () => {
27
+ let provider = new $LocationProvider();
28
+ expect(provider.hashPrefix()).toBe("!");
29
+ });
30
+
31
+ it("should not be html5 mode", () => {
32
+ let provider = new $LocationProvider();
33
+ expect(provider.html5Mode().enabled).toBeFalse();
34
+ });
35
+ });
36
+
37
+ describe("File Protocol", () => {
38
+ /* global urlParsingNode: true */
39
+ let urlParsingNodePlaceholder;
40
+ let urlParsingNode;
41
+
42
+ beforeEach(() => {
43
+ urlParsingNodePlaceholder = urlParsingNode;
44
+
45
+ // temporarily overriding the DOM element
46
+ // with output from IE, if not in IE
47
+ urlParsingNode = {
48
+ hash: "#/C:/",
49
+ host: "",
50
+ hostname: "",
51
+ href: "file:///C:/base#!/C:/foo",
52
+ pathname: "/C:/foo",
53
+ port: "",
54
+ protocol: "file:",
55
+ search: "",
56
+ setAttribute: () => {},
57
+ };
58
+ });
59
+
60
+ afterEach(() => {
61
+ urlParsingNode = urlParsingNodePlaceholder;
62
+ });
63
+
64
+ it("should not include the drive name in path() on WIN", () => {
65
+ // See issue #4680 for details
66
+ const locationUrl = new LocationHashbangUrl(
67
+ "file:///base",
68
+ "file:///",
69
+ "#!",
70
+ );
71
+ locationUrl.$$parse("file:///base#!/foo?a=b&c#hash");
72
+
73
+ expect(locationUrl.path()).toBe("/foo");
74
+ });
75
+
76
+ it("should include the drive name if it was provided in the input url", () => {
77
+ const locationUrl = new LocationHashbangUrl(
78
+ "file:///base",
79
+ "file:///",
80
+ "#!",
81
+ );
82
+ locationUrl.$$parse("file:///base#!/C:/foo?a=b&c#hash");
83
+
84
+ expect(locationUrl.path()).toBe("/C:/foo");
85
+ });
86
+ });
87
+
88
+ describe("NewUrl", () => {
89
+ function createLocationHtml5Url() {
90
+ const locationUrl = new LocationHtml5Url(
91
+ "http://www.domain.com:9877/",
92
+ "http://www.domain.com:9877/",
93
+ );
94
+ locationUrl.$$parse(
95
+ "http://www.domain.com:9877/path/b?search=a&b=c&d#hash",
96
+ );
97
+ return locationUrl;
98
+ }
99
+
100
+ it("should provide common getters", () => {
101
+ const locationUrl = createLocationHtml5Url();
102
+ expect(locationUrl.absUrl()).toBe(
103
+ "http://www.domain.com:9877/path/b?search=a&b=c&d#hash",
104
+ );
105
+ expect(locationUrl.protocol()).toBe("http");
106
+ expect(locationUrl.host()).toBe("www.domain.com");
107
+ expect(locationUrl.port()).toBe(9877);
108
+ expect(locationUrl.path()).toBe("/path/b");
109
+ expect(locationUrl.search()).toEqual({ search: "a", b: "c", d: true });
110
+ expect(locationUrl.hash()).toBe("hash");
111
+ expect(locationUrl.url()).toBe("/path/b?search=a&b=c&d#hash");
112
+ });
113
+
114
+ it("path() should change path", () => {
115
+ const locationUrl = createLocationHtml5Url();
116
+ locationUrl.path("/new/path");
117
+ expect(locationUrl.path()).toBe("/new/path");
118
+ expect(locationUrl.absUrl()).toBe(
119
+ "http://www.domain.com:9877/new/path?search=a&b=c&d#hash",
120
+ );
121
+ });
122
+
123
+ it("path() should not break on numeric values", () => {
124
+ const locationUrl = createLocationHtml5Url();
125
+ locationUrl.path(1);
126
+ expect(locationUrl.path()).toBe("/1");
127
+ expect(locationUrl.absUrl()).toBe(
128
+ "http://www.domain.com:9877/1?search=a&b=c&d#hash",
129
+ );
130
+ });
131
+
132
+ it("path() should allow using 0 as path", () => {
133
+ const locationUrl = createLocationHtml5Url();
134
+ locationUrl.path(0);
135
+ expect(locationUrl.path()).toBe("/0");
136
+ expect(locationUrl.absUrl()).toBe(
137
+ "http://www.domain.com:9877/0?search=a&b=c&d#hash",
138
+ );
139
+ });
140
+
141
+ it("path() should set to empty path on null value", () => {
142
+ const locationUrl = createLocationHtml5Url();
143
+ locationUrl.path("/foo");
144
+ expect(locationUrl.path()).toBe("/foo");
145
+ locationUrl.path(null);
146
+ expect(locationUrl.path()).toBe("/");
147
+ });
148
+
149
+ it("search() should accept string", () => {
150
+ const locationUrl = createLocationHtml5Url();
151
+ locationUrl.search("x=y&c");
152
+ expect(locationUrl.search()).toEqual({ x: "y", c: true });
153
+ expect(locationUrl.absUrl()).toBe(
154
+ "http://www.domain.com:9877/path/b?x=y&c#hash",
155
+ );
156
+ });
157
+
158
+ it("search() should accept object", () => {
159
+ const locationUrl = createLocationHtml5Url();
160
+ locationUrl.search({ one: 1, two: true });
161
+ expect(locationUrl.search()).toEqual({ one: 1, two: true });
162
+ expect(locationUrl.absUrl()).toBe(
163
+ "http://www.domain.com:9877/path/b?one=1&two#hash",
164
+ );
165
+ });
166
+
167
+ it("search() should copy object", () => {
168
+ const locationUrl = createLocationHtml5Url();
169
+ const obj = { one: 1, two: true, three: null };
170
+ locationUrl.search(obj);
171
+ expect(obj).toEqual({ one: 1, two: true, three: null });
172
+ obj.one = "changed";
173
+ expect(locationUrl.search()).toEqual({ one: 1, two: true });
174
+ expect(locationUrl.absUrl()).toBe(
175
+ "http://www.domain.com:9877/path/b?one=1&two#hash",
176
+ );
177
+ });
178
+
179
+ it("search() should change single parameter", () => {
180
+ const locationUrl = createLocationHtml5Url();
181
+ locationUrl.search({ id: "old", preserved: true });
182
+ locationUrl.search("id", "new");
183
+
184
+ expect(locationUrl.search()).toEqual({ id: "new", preserved: true });
185
+ });
186
+
187
+ it("search() should remove single parameter", () => {
188
+ const locationUrl = createLocationHtml5Url();
189
+ locationUrl.search({ id: "old", preserved: true });
190
+ locationUrl.search("id", null);
191
+
192
+ expect(locationUrl.search()).toEqual({ preserved: true });
193
+ });
194
+
195
+ it("search() should remove multiple parameters", () => {
196
+ const locationUrl = createLocationHtml5Url();
197
+ locationUrl.search({ one: 1, two: true });
198
+ expect(locationUrl.search()).toEqual({ one: 1, two: true });
199
+ locationUrl.search({ one: null, two: null });
200
+ expect(locationUrl.search()).toEqual({});
201
+ expect(locationUrl.absUrl()).toBe(
202
+ "http://www.domain.com:9877/path/b#hash",
203
+ );
204
+ });
205
+
206
+ it("search() should accept numeric keys", () => {
207
+ const locationUrl = createLocationHtml5Url();
208
+ locationUrl.search({ 1: "one", 2: "two" });
209
+ expect(locationUrl.search()).toEqual({ 1: "one", 2: "two" });
210
+ expect(locationUrl.absUrl()).toBe(
211
+ "http://www.domain.com:9877/path/b?1=one&2=two#hash",
212
+ );
213
+ });
214
+
215
+ it("search() should handle multiple value", () => {
216
+ const locationUrl = createLocationHtml5Url();
217
+ locationUrl.search("a&b");
218
+ expect(locationUrl.search()).toEqual({ a: true, b: true });
219
+
220
+ locationUrl.search("a", null);
221
+
222
+ expect(locationUrl.search()).toEqual({ b: true });
223
+
224
+ locationUrl.search("b", undefined);
225
+ expect(locationUrl.search()).toEqual({});
226
+ });
227
+
228
+ it("search() should handle single value", () => {
229
+ const locationUrl = createLocationHtml5Url();
230
+ locationUrl.search("ignore");
231
+ expect(locationUrl.search()).toEqual({ ignore: true });
232
+ locationUrl.search(1);
233
+ expect(locationUrl.search()).toEqual({ 1: true });
234
+ });
235
+
236
+ it("search() should throw error an incorrect argument", () => {
237
+ const locationUrl = createLocationHtml5Url();
238
+ expect(() => {
239
+ locationUrl.search(null);
240
+ }).toThrowError(/isrcharg/);
241
+ expect(() => {
242
+ locationUrl.search(undefined);
243
+ }).toThrowError(/isrcharg/);
244
+ });
245
+
246
+ it("hash() should change hash fragment", () => {
247
+ const locationUrl = createLocationHtml5Url();
248
+ locationUrl.hash("new-hash");
249
+ expect(locationUrl.hash()).toBe("new-hash");
250
+ expect(locationUrl.absUrl()).toBe(
251
+ "http://www.domain.com:9877/path/b?search=a&b=c&d#new-hash",
252
+ );
253
+ });
254
+
255
+ it("hash() should accept numeric parameter", () => {
256
+ const locationUrl = createLocationHtml5Url();
257
+ locationUrl.hash(5);
258
+ expect(locationUrl.hash()).toBe("5");
259
+ expect(locationUrl.absUrl()).toBe(
260
+ "http://www.domain.com:9877/path/b?search=a&b=c&d#5",
261
+ );
262
+ });
263
+
264
+ it("hash() should allow using 0", () => {
265
+ const locationUrl = createLocationHtml5Url();
266
+ locationUrl.hash(0);
267
+ expect(locationUrl.hash()).toBe("0");
268
+ expect(locationUrl.absUrl()).toBe(
269
+ "http://www.domain.com:9877/path/b?search=a&b=c&d#0",
270
+ );
271
+ });
272
+
273
+ it("hash() should accept null parameter", () => {
274
+ const locationUrl = createLocationHtml5Url();
275
+ locationUrl.hash(null);
276
+ expect(locationUrl.hash()).toBe("");
277
+ expect(locationUrl.absUrl()).toBe(
278
+ "http://www.domain.com:9877/path/b?search=a&b=c&d",
279
+ );
280
+ });
281
+
282
+ it("url() should change the path, search and hash", () => {
283
+ const locationUrl = createLocationHtml5Url();
284
+ locationUrl.url("/some/path?a=b&c=d#hhh");
285
+ expect(locationUrl.url()).toBe("/some/path?a=b&c=d#hhh");
286
+ expect(locationUrl.absUrl()).toBe(
287
+ "http://www.domain.com:9877/some/path?a=b&c=d#hhh",
288
+ );
289
+ expect(locationUrl.path()).toBe("/some/path");
290
+ expect(locationUrl.search()).toEqual({ a: "b", c: "d" });
291
+ expect(locationUrl.hash()).toBe("hhh");
292
+ });
293
+
294
+ it("url() should change only hash when no search and path specified", () => {
295
+ const locationUrl = createLocationHtml5Url();
296
+ locationUrl.url("#some-hash");
297
+
298
+ expect(locationUrl.hash()).toBe("some-hash");
299
+ expect(locationUrl.url()).toBe("/path/b?search=a&b=c&d#some-hash");
300
+ expect(locationUrl.absUrl()).toBe(
301
+ "http://www.domain.com:9877/path/b?search=a&b=c&d#some-hash",
302
+ );
303
+ });
304
+
305
+ it("url() should change only search and hash when no path specified", () => {
306
+ const locationUrl = createLocationHtml5Url();
307
+ locationUrl.url("?a=b");
308
+
309
+ expect(locationUrl.search()).toEqual({ a: "b" });
310
+ expect(locationUrl.hash()).toBe("");
311
+ expect(locationUrl.path()).toBe("/path/b");
312
+ });
313
+
314
+ it("url() should reset search and hash when only path specified", () => {
315
+ const locationUrl = createLocationHtml5Url();
316
+ locationUrl.url("/new/path");
317
+
318
+ expect(locationUrl.path()).toBe("/new/path");
319
+ expect(locationUrl.search()).toEqual({});
320
+ expect(locationUrl.hash()).toBe("");
321
+ });
322
+
323
+ it("url() should change path when empty string specified", () => {
324
+ const locationUrl = createLocationHtml5Url();
325
+ locationUrl.url("");
326
+
327
+ expect(locationUrl.path()).toBe("/");
328
+ expect(locationUrl.search()).toEqual({});
329
+ expect(locationUrl.hash()).toBe("");
330
+ });
331
+
332
+ it("replace should set $$replace flag and return itself", () => {
333
+ const locationUrl = createLocationHtml5Url();
334
+ expect(locationUrl.$$replace).toBe(false);
335
+
336
+ locationUrl.replace();
337
+ expect(locationUrl.$$replace).toBe(true);
338
+ expect(locationUrl.replace()).toBe(locationUrl);
339
+ });
340
+
341
+ it("should parse new url", () => {
342
+ let locationUrl = new LocationHtml5Url(
343
+ "http://host.com/",
344
+ "http://host.com/",
345
+ );
346
+ locationUrl.$$parse("http://host.com/base");
347
+ expect(locationUrl.path()).toBe("/base");
348
+
349
+ locationUrl = new LocationHtml5Url(
350
+ "http://host.com/",
351
+ "http://host.com/",
352
+ );
353
+ locationUrl.$$parse("http://host.com/base#");
354
+ expect(locationUrl.path()).toBe("/base");
355
+ });
356
+
357
+ it("should prefix path with forward-slash", () => {
358
+ const locationUrl = new LocationHtml5Url(
359
+ "http://server/",
360
+ "http://server/",
361
+ );
362
+ locationUrl.path("b");
363
+
364
+ expect(locationUrl.path()).toBe("/b");
365
+ expect(locationUrl.absUrl()).toBe("http://server/b");
366
+ });
367
+
368
+ it("should set path to forward-slash when empty", () => {
369
+ const locationUrl = new LocationHtml5Url(
370
+ "http://server/",
371
+ "http://server/",
372
+ );
373
+ locationUrl.$$parse("http://server/");
374
+ expect(locationUrl.path()).toBe("/");
375
+ expect(locationUrl.absUrl()).toBe("http://server/");
376
+ });
377
+
378
+ it("setters should return Url object to allow chaining", () => {
379
+ const locationUrl = createLocationHtml5Url();
380
+ expect(locationUrl.path("/any")).toBe(locationUrl);
381
+ expect(locationUrl.search("")).toBe(locationUrl);
382
+ expect(locationUrl.hash("aaa")).toBe(locationUrl);
383
+ expect(locationUrl.url("/some")).toBe(locationUrl);
384
+ });
385
+
386
+ it("should not preserve old properties when parsing new url", () => {
387
+ const locationUrl = createLocationHtml5Url();
388
+ locationUrl.$$parse("http://www.domain.com:9877/a");
389
+
390
+ expect(locationUrl.path()).toBe("/a");
391
+ expect(locationUrl.search()).toEqual({});
392
+ expect(locationUrl.hash()).toBe("");
393
+ expect(locationUrl.absUrl()).toBe("http://www.domain.com:9877/a");
394
+ });
395
+
396
+ // it("should not rewrite when hashbang url is not given", () => {
397
+ // initService({ html5Mode: true, hashPrefix: "!", supportHistory: true });
398
+ // initBrowser({ url: "http://domain.com/base/a/b", basePath: "/base" });
399
+ // expect($browser.url()).toBe("http://domain.com/base/a/b");
400
+ // });
401
+
402
+ it("should prepend path with basePath", () => {
403
+ const locationUrl = new LocationHtml5Url(
404
+ "http://server/base/",
405
+ "http://server/base/",
406
+ );
407
+ locationUrl.$$parse("http://server/base/abc?a");
408
+ expect(locationUrl.path()).toBe("/abc");
409
+ expect(locationUrl.search()).toEqual({ a: true });
410
+
411
+ locationUrl.path("/new/path");
412
+ expect(locationUrl.absUrl()).toBe("http://server/base/new/path?a");
413
+ });
414
+
415
+ it("should throw error when invalid server url given", () => {
416
+ const locationUrl = new LocationHtml5Url(
417
+ "http://server.org/base/abc",
418
+ "http://server.org/base/",
419
+ );
420
+
421
+ expect(() => {
422
+ locationUrl.$$parse("http://other.server.org/path#/path");
423
+ }).toThrowError(/ipthprfx/);
424
+ });
425
+
426
+ it("should throw error when invalid base url given", () => {
427
+ const locationUrl = new LocationHtml5Url(
428
+ "http://server.org/base/abc",
429
+ "http://server.org/base/",
430
+ );
431
+
432
+ expect(() => {
433
+ locationUrl.$$parse("http://server.org/path#/path");
434
+ }).toThrowError(/ipthprfx/);
435
+ });
436
+
437
+ describe("state", () => {
438
+ it("should set $$state and return itself", () => {
439
+ const locationUrl = createLocationHtml5Url();
440
+ expect(locationUrl.$$state).toEqual(undefined);
441
+
442
+ const returned = locationUrl.state({ a: 2 });
443
+ expect(locationUrl.$$state).toEqual({ a: 2 });
444
+ expect(returned).toBe(locationUrl);
445
+ });
446
+
447
+ it("should set state", () => {
448
+ const locationUrl = createLocationHtml5Url();
449
+ locationUrl.state({ a: 2 });
450
+ expect(locationUrl.state()).toEqual({ a: 2 });
451
+ });
452
+
453
+ it("should allow to set both URL and state", () => {
454
+ const locationUrl = createLocationHtml5Url();
455
+ locationUrl.url("/foo").state({ a: 2 });
456
+ expect(locationUrl.url()).toEqual("/foo");
457
+ expect(locationUrl.state()).toEqual({ a: 2 });
458
+ });
459
+
460
+ it("should allow to mix state and various URL functions", () => {
461
+ const locationUrl = createLocationHtml5Url();
462
+ locationUrl
463
+ .path("/foo")
464
+ .hash("abcd")
465
+ .state({ a: 2 })
466
+ .search("bar", "baz");
467
+ expect(locationUrl.path()).toEqual("/foo");
468
+ expect(locationUrl.state()).toEqual({ a: 2 });
469
+ expect(locationUrl.search() && locationUrl.search().bar).toBe("baz");
470
+ expect(locationUrl.hash()).toEqual("abcd");
471
+ });
472
+ });
473
+
474
+ describe("encoding", () => {
475
+ it("should encode special characters", () => {
476
+ const locationUrl = createLocationHtml5Url();
477
+ locationUrl.path("/a <>#");
478
+ locationUrl.search({ "i j": "<>#" });
479
+ locationUrl.hash("<>#");
480
+
481
+ expect(locationUrl.path()).toBe("/a <>#");
482
+ expect(locationUrl.search()).toEqual({ "i j": "<>#" });
483
+ expect(locationUrl.hash()).toBe("<>#");
484
+ expect(locationUrl.absUrl()).toBe(
485
+ "http://www.domain.com:9877/a%20%3C%3E%23?i%20j=%3C%3E%23#%3C%3E%23",
486
+ );
487
+ });
488
+
489
+ it("should not encode !$:@", () => {
490
+ const locationUrl = createLocationHtml5Url();
491
+ locationUrl.path("/!$:@");
492
+ locationUrl.search("");
493
+ locationUrl.hash("!$:@");
494
+
495
+ expect(locationUrl.absUrl()).toBe(
496
+ "http://www.domain.com:9877/!$:@#!$:@",
497
+ );
498
+ });
499
+
500
+ it("should decode special characters", () => {
501
+ const locationUrl = new LocationHtml5Url(
502
+ "http://host.com/",
503
+ "http://host.com/",
504
+ );
505
+ locationUrl.$$parse(
506
+ "http://host.com/a%20%3C%3E%23?i%20j=%3C%3E%23#x%20%3C%3E%23",
507
+ );
508
+ expect(locationUrl.path()).toBe("/a <>#");
509
+ expect(locationUrl.search()).toEqual({ "i j": "<>#" });
510
+ expect(locationUrl.hash()).toBe("x <>#");
511
+ });
512
+
513
+ it("should not decode encoded forward slashes in the path", () => {
514
+ const locationUrl = new LocationHtml5Url(
515
+ "http://host.com/base/",
516
+ "http://host.com/base/",
517
+ );
518
+ locationUrl.$$parse("http://host.com/base/a/ng2;path=%2Fsome%2Fpath");
519
+ expect(locationUrl.path()).toBe("/a/ng2;path=%2Fsome%2Fpath");
520
+ expect(locationUrl.search()).toEqual({});
521
+ expect(locationUrl.hash()).toBe("");
522
+ expect(locationUrl.url()).toBe("/a/ng2;path=%2Fsome%2Fpath");
523
+ expect(locationUrl.absUrl()).toBe(
524
+ "http://host.com/base/a/ng2;path=%2Fsome%2Fpath",
525
+ );
526
+ });
527
+
528
+ it("should decode pluses as spaces in urls", () => {
529
+ const locationUrl = new LocationHtml5Url(
530
+ "http://host.com/",
531
+ "http://host.com/",
532
+ );
533
+ locationUrl.$$parse("http://host.com/?a+b=c+d");
534
+ expect(locationUrl.search()).toEqual({ "a b": "c d" });
535
+ });
536
+
537
+ it("should retain pluses when setting search queries", () => {
538
+ const locationUrl = createLocationHtml5Url();
539
+ locationUrl.search({ "a+b": "c+d" });
540
+ expect(locationUrl.search()).toEqual({ "a+b": "c+d" });
541
+ });
542
+ });
543
+ });
544
+
545
+ describe("HashbangUrl", () => {
546
+ function createHashbangUrl() {
547
+ const locationUrl = new LocationHashbangUrl(
548
+ "http://www.server.org:1234/base",
549
+ "http://www.server.org:1234/",
550
+ "#!",
551
+ );
552
+ locationUrl.$$parse("http://www.server.org:1234/base#!/path?a=b&c#hash");
553
+ return locationUrl;
554
+ }
555
+
556
+ it("should parse hashbang url into path and search", () => {
557
+ const locationUrl = createHashbangUrl();
558
+ expect(locationUrl.protocol()).toBe("http");
559
+ expect(locationUrl.host()).toBe("www.server.org");
560
+ expect(locationUrl.port()).toBe(1234);
561
+ expect(locationUrl.path()).toBe("/path");
562
+ expect(locationUrl.search()).toEqual({ a: "b", c: true });
563
+ expect(locationUrl.hash()).toBe("hash");
564
+ });
565
+
566
+ it("absUrl() should return hashbang url", () => {
567
+ const locationUrl = createHashbangUrl();
568
+ expect(locationUrl.absUrl()).toBe(
569
+ "http://www.server.org:1234/base#!/path?a=b&c#hash",
570
+ );
571
+
572
+ locationUrl.path("/new/path");
573
+ locationUrl.search({ one: 1 });
574
+ locationUrl.hash("hhh");
575
+ expect(locationUrl.absUrl()).toBe(
576
+ "http://www.server.org:1234/base#!/new/path?one=1#hhh",
577
+ );
578
+ });
579
+
580
+ it("should preserve query params in base", () => {
581
+ const locationUrl = new LocationHashbangUrl(
582
+ "http://www.server.org:1234/base?base=param",
583
+ "http://www.server.org:1234/",
584
+ "#",
585
+ );
586
+ locationUrl.$$parse(
587
+ "http://www.server.org:1234/base?base=param#/path?a=b&c#hash",
588
+ );
589
+ expect(locationUrl.absUrl()).toBe(
590
+ "http://www.server.org:1234/base?base=param#/path?a=b&c#hash",
591
+ );
592
+
593
+ locationUrl.path("/new/path");
594
+ locationUrl.search({ one: 1 });
595
+ locationUrl.hash("hhh");
596
+ expect(locationUrl.absUrl()).toBe(
597
+ "http://www.server.org:1234/base?base=param#/new/path?one=1#hhh",
598
+ );
599
+ });
600
+
601
+ it("should prefix path with forward-slash", () => {
602
+ const locationUrl = new LocationHashbangUrl(
603
+ "http://host.com/base",
604
+ "http://host.com/",
605
+ "#",
606
+ );
607
+ locationUrl.$$parse("http://host.com/base#path");
608
+ expect(locationUrl.path()).toBe("/path");
609
+ expect(locationUrl.absUrl()).toBe("http://host.com/base#/path");
610
+
611
+ locationUrl.path("wrong");
612
+ expect(locationUrl.path()).toBe("/wrong");
613
+ expect(locationUrl.absUrl()).toBe("http://host.com/base#/wrong");
614
+ });
615
+
616
+ it("should set path to forward-slash when empty", () => {
617
+ const locationUrl = new LocationHashbangUrl(
618
+ "http://server/base",
619
+ "http://server/",
620
+ "#!",
621
+ );
622
+ locationUrl.$$parse("http://server/base");
623
+ locationUrl.path("aaa");
624
+
625
+ expect(locationUrl.path()).toBe("/aaa");
626
+ expect(locationUrl.absUrl()).toBe("http://server/base#!/aaa");
627
+ });
628
+
629
+ it("should not preserve old properties when parsing new url", () => {
630
+ const locationUrl = createHashbangUrl();
631
+ locationUrl.$$parse("http://www.server.org:1234/base#!/");
632
+
633
+ expect(locationUrl.path()).toBe("/");
634
+ expect(locationUrl.search()).toEqual({});
635
+ expect(locationUrl.hash()).toBe("");
636
+ expect(locationUrl.absUrl()).toBe("http://www.server.org:1234/base#!/");
637
+ });
638
+
639
+ it("should insert default hashbang if a hash is given with no hashbang prefix", () => {
640
+ const locationUrl = createHashbangUrl();
641
+
642
+ locationUrl.$$parse("http://www.server.org:1234/base#/path");
643
+ expect(locationUrl.absUrl()).toBe(
644
+ "http://www.server.org:1234/base#!#%2Fpath",
645
+ );
646
+ expect(locationUrl.hash()).toBe("/path");
647
+ expect(locationUrl.path()).toBe("");
648
+
649
+ locationUrl.$$parse("http://www.server.org:1234/base#");
650
+ expect(locationUrl.absUrl()).toBe("http://www.server.org:1234/base");
651
+ expect(locationUrl.hash()).toBe("");
652
+ expect(locationUrl.path()).toBe("");
653
+ });
654
+
655
+ it("should ignore extra path segments if no hashbang is given", () => {
656
+ const locationUrl = createHashbangUrl();
657
+ locationUrl.$$parse("http://www.server.org:1234/base/extra/path");
658
+ expect(locationUrl.absUrl()).toBe("http://www.server.org:1234/base");
659
+ expect(locationUrl.path()).toBe("");
660
+ expect(locationUrl.hash()).toBe("");
661
+ });
662
+
663
+ describe("encoding", () => {
664
+ it("should encode special characters", () => {
665
+ const locationUrl = createHashbangUrl();
666
+ locationUrl.path("/a <>#");
667
+ locationUrl.search({ "i j": "<>#" });
668
+ locationUrl.hash("<>#");
669
+
670
+ expect(locationUrl.path()).toBe("/a <>#");
671
+ expect(locationUrl.search()).toEqual({ "i j": "<>#" });
672
+ expect(locationUrl.hash()).toBe("<>#");
673
+ expect(locationUrl.absUrl()).toBe(
674
+ "http://www.server.org:1234/base#!/a%20%3C%3E%23?i%20j=%3C%3E%23#%3C%3E%23",
675
+ );
676
+ });
677
+
678
+ it("should not encode !$:@", () => {
679
+ const locationUrl = createHashbangUrl();
680
+ locationUrl.path("/!$:@");
681
+ locationUrl.search("");
682
+ locationUrl.hash("!$:@");
683
+
684
+ expect(locationUrl.absUrl()).toBe(
685
+ "http://www.server.org:1234/base#!/!$:@#!$:@",
686
+ );
687
+ });
688
+
689
+ it("should decode special characters", () => {
690
+ const locationUrl = new LocationHashbangUrl(
691
+ "http://host.com/a",
692
+ "http://host.com/",
693
+ "#",
694
+ );
695
+ locationUrl.$$parse(
696
+ "http://host.com/a#/%20%3C%3E%23?i%20j=%3C%3E%23#x%20%3C%3E%23",
697
+ );
698
+ expect(locationUrl.path()).toBe("/ <>#");
699
+ expect(locationUrl.search()).toEqual({ "i j": "<>#" });
700
+ expect(locationUrl.hash()).toBe("x <>#");
701
+ });
702
+
703
+ it("should return decoded characters for search specified in URL", () => {
704
+ const locationUrl = new LocationHtml5Url(
705
+ "http://host.com/",
706
+ "http://host.com/",
707
+ );
708
+ locationUrl.$$parse("http://host.com/?q=1%2F2%203");
709
+ expect(locationUrl.search()).toEqual({ q: "1/2 3" });
710
+ });
711
+
712
+ it("should return decoded characters for search specified with setter", () => {
713
+ const locationUrl = new LocationHtml5Url(
714
+ "http://host.com/",
715
+ "http://host.com/",
716
+ );
717
+ locationUrl.$$parse("http://host.com/");
718
+ locationUrl.search("q", "1/2 3");
719
+ expect(locationUrl.search()).toEqual({ q: "1/2 3" });
720
+ });
721
+
722
+ it("should return an array for duplicate params", () => {
723
+ const locationUrl = new LocationHtml5Url(
724
+ "http://host.com",
725
+ "http://host.com",
726
+ );
727
+ locationUrl.$$parse("http://host.com");
728
+ locationUrl.search("q", ["1/2 3", "4/5 6"]);
729
+ expect(locationUrl.search()).toEqual({ q: ["1/2 3", "4/5 6"] });
730
+ });
731
+
732
+ it("should encode an array correctly from search and add to url", () => {
733
+ const locationUrl = new LocationHtml5Url(
734
+ "http://host.com",
735
+ "http://host.com",
736
+ );
737
+ locationUrl.$$parse("http://host.com");
738
+ locationUrl.search({ q: ["1/2 3", "4/5 6"] });
739
+ expect(locationUrl.absUrl()).toEqual(
740
+ "http://host.com?q=1%2F2%203&q=4%2F5%206",
741
+ );
742
+ });
743
+
744
+ it("should rewrite params when specifying a single param in search", () => {
745
+ const locationUrl = new LocationHtml5Url(
746
+ "http://host.com",
747
+ "http://host.com",
748
+ );
749
+ locationUrl.$$parse("http://host.com");
750
+ locationUrl.search({ q: "1/2 3" });
751
+ expect(locationUrl.absUrl()).toEqual("http://host.com?q=1%2F2%203");
752
+ locationUrl.search({ q: "4/5 6" });
753
+ expect(locationUrl.absUrl()).toEqual("http://host.com?q=4%2F5%206");
754
+ });
755
+
756
+ it("url() should decode non-component special characters in hashbang mode", () => {
757
+ const locationUrl = new LocationHashbangUrl(
758
+ "http://host.com",
759
+ "http://host.com",
760
+ );
761
+ locationUrl.$$parse("http://host.com");
762
+ locationUrl.url("/foo%3Abar");
763
+ expect(locationUrl.path()).toEqual("/foo:bar");
764
+ });
765
+
766
+ it("url() should decode non-component special characters in html5 mode", () => {
767
+ const locationUrl = new LocationHtml5Url(
768
+ "http://host.com",
769
+ "http://host.com",
770
+ );
771
+ locationUrl.$$parse("http://host.com");
772
+ locationUrl.url("/foo%3Abar");
773
+ expect(locationUrl.path()).toEqual("/foo:bar");
774
+ });
775
+ });
776
+ });
777
+
778
+ // describe("location watch", () => {
779
+ // it("should not update browser if only the empty hash fragment is cleared", () => {
780
+ // initService({ supportHistory: true });
781
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#", baseHref: "/base/" });
782
+ // inject(($browser, $rootScope) => {
783
+ // $browser.url("http://new.com/a/b");
784
+ // const $browserUrl = spyOnlyCallsWithArgs(
785
+ // $browser,
786
+ // "url",
787
+ // ).and.callThrough();
788
+ // $rootScope.$digest();
789
+ // expect($browserUrl).not.toHaveBeenCalled();
790
+ // });
791
+ // });
792
+
793
+ // it("should not replace browser url if only the empty hash fragment is cleared", () => {
794
+ // initService({ html5Mode: true, supportHistory: true });
795
+ // mockUpBrowser({ initialUrl: "http://new.com/#", baseHref: "/" });
796
+ // inject(($browser, $location, $window) => {
797
+ // expect($browser.url()).toBe("http://new.com/");
798
+ // expect($location.absUrl()).toBe("http://new.com/");
799
+ // expect($window.location.href).toBe("http://new.com/#");
800
+ // });
801
+ // });
802
+
803
+ // it("should not get caught in infinite digest when replacing path in locationChangeSuccess handler", () => {
804
+ // initService({ html5Mode: true, supportHistory: false });
805
+ // mockUpBrowser({
806
+ // initialUrl: "http://server/base/home",
807
+ // baseHref: "/base/",
808
+ // });
809
+ // inject(($browser, $location, $rootScope, $window) => {
810
+ // let handlerCalled = false;
811
+ // $rootScope.$on("$locationChangeSuccess", () => {
812
+ // handlerCalled = true;
813
+ // if ($location.path() !== "/") {
814
+ // $location.path("/").replace();
815
+ // }
816
+ // });
817
+ // expect($browser.url()).toEqual("http://server/base/#!/home");
818
+ // $rootScope.$digest();
819
+ // expect(handlerCalled).toEqual(true);
820
+ // expect($browser.url()).toEqual("http://server/base/#!/");
821
+ // });
822
+ // });
823
+
824
+ // it("should not infinitely digest when using a semicolon in initial path", () => {
825
+ // initService({ html5Mode: true, supportHistory: true });
826
+ // mockUpBrowser({
827
+ // initialUrl: "http://localhost:9876/;jsessionid=foo",
828
+ // baseHref: "/",
829
+ // });
830
+ // inject(($location, $browser, $rootScope) => {
831
+ // expect(() => {
832
+ // $rootScope.$digest();
833
+ // }).not.toThrow();
834
+ // });
835
+ // });
836
+
837
+ // // https://github.com/angular/angular.js/issues/16592
838
+ // it("should not infinitely digest when initial params contain a quote", () => {
839
+ // initService({ html5Mode: true, supportHistory: true });
840
+ // mockUpBrowser({
841
+ // initialUrl: "http://localhost:9876/?q='",
842
+ // baseHref: "/",
843
+ // });
844
+ // inject(($location, $browser, $rootScope) => {
845
+ // expect(() => {
846
+ // $rootScope.$digest();
847
+ // }).not.toThrow();
848
+ // });
849
+ // });
850
+
851
+ // // https://github.com/angular/angular.js/issues/16592
852
+ // it("should not infinitely digest when initial params contain an escaped quote", () => {
853
+ // initService({ html5Mode: true, supportHistory: true });
854
+ // mockUpBrowser({
855
+ // initialUrl: "http://localhost:9876/?q=%27",
856
+ // baseHref: "/",
857
+ // });
858
+ // inject(($location, $browser, $rootScope) => {
859
+ // expect(() => {
860
+ // $rootScope.$digest();
861
+ // }).not.toThrow();
862
+ // });
863
+ // });
864
+
865
+ // // https://github.com/angular/angular.js/issues/16592
866
+ // it("should not infinitely digest when updating params containing a quote (via $browser.url)", () => {
867
+ // initService({ html5Mode: true, supportHistory: true });
868
+ // mockUpBrowser({ initialUrl: "http://localhost:9876/", baseHref: "/" });
869
+ // inject(($location, $browser, $rootScope) => {
870
+ // $rootScope.$digest();
871
+ // $browser.url("http://localhost:9876/?q='");
872
+ // expect(() => {
873
+ // $rootScope.$digest();
874
+ // }).not.toThrow();
875
+ // });
876
+ // });
877
+
878
+ // // https://github.com/angular/angular.js/issues/16592
879
+ // it("should not infinitely digest when updating params containing a quote (via window.location + popstate)", () => {
880
+ // initService({ html5Mode: true, supportHistory: true });
881
+ // mockUpBrowser({ initialUrl: "http://localhost:9876/", baseHref: "/" });
882
+ // inject(($window, $location, $browser, $rootScope) => {
883
+ // $rootScope.$digest();
884
+ // $window.location.href = "http://localhost:9876/?q='";
885
+ // expect(() => {
886
+ // jqLite($window).triggerHandler("popstate");
887
+ // }).not.toThrow();
888
+ // });
889
+ // });
890
+
891
+ // describe("when changing the browser URL/history directly during a `$digest`", () => {
892
+ // beforeEach(() => {
893
+ // initService({ supportHistory: true });
894
+ // mockUpBrowser({ initialUrl: "http://foo.bar/", baseHref: "/" });
895
+ // });
896
+
897
+ // it("should correctly update `$location` from history and not digest infinitely", inject((
898
+ // $browser,
899
+ // $location,
900
+ // $rootScope,
901
+ // $window,
902
+ // ) => {
903
+ // $location.url("baz");
904
+ // $rootScope.$digest();
905
+
906
+ // const originalUrl = $window.location.href;
907
+
908
+ // $rootScope.$apply(() => {
909
+ // $rootScope.$evalAsync(() => {
910
+ // $window.history.pushState({}, null, `${originalUrl}/qux`);
911
+ // });
912
+ // });
913
+
914
+ // expect($browser.url()).toBe("http://foo.bar/#!/baz/qux");
915
+ // expect($location.absUrl()).toBe("http://foo.bar/#!/baz/qux");
916
+
917
+ // $rootScope.$apply(() => {
918
+ // $rootScope.$evalAsync(() => {
919
+ // $window.history.replaceState({}, null, `${originalUrl}/quux`);
920
+ // });
921
+ // });
922
+
923
+ // expect($browser.url()).toBe("http://foo.bar/#!/baz/quux");
924
+ // expect($location.absUrl()).toBe("http://foo.bar/#!/baz/quux");
925
+ // }));
926
+
927
+ // it("should correctly update `$location` from URL and not digest infinitely", inject((
928
+ // $browser,
929
+ // $location,
930
+ // $rootScope,
931
+ // $window,
932
+ // ) => {
933
+ // $location.url("baz");
934
+ // $rootScope.$digest();
935
+
936
+ // $rootScope.$apply(() => {
937
+ // $rootScope.$evalAsync(() => {
938
+ // $window.location.href += "/qux";
939
+ // });
940
+ // });
941
+
942
+ // jqLite($window).triggerHandler("hashchange");
943
+
944
+ // expect($browser.url()).toBe("http://foo.bar/#!/baz/qux");
945
+ // expect($location.absUrl()).toBe("http://foo.bar/#!/baz/qux");
946
+ // }));
947
+ // });
948
+
949
+ // function updatePathOnLocationChangeSuccessTo(newPath, newParams) {
950
+ // inject(($rootScope, $location) => {
951
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
952
+ // $location.path(newPath);
953
+ // if (newParams) {
954
+ // $location.search(newParams);
955
+ // }
956
+ // });
957
+ // });
958
+ // }
959
+
960
+ // describe("location watch for hashbang browsers", () => {
961
+ // it("should not infinite $digest when going to base URL without trailing slash when $locationChangeSuccess watcher changes path to /Home", () => {
962
+ // initService({ html5Mode: true, supportHistory: false });
963
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
964
+ // inject(($rootScope, $location, $browser) => {
965
+ // const $browserUrl = spyOnlyCallsWithArgs(
966
+ // $browser,
967
+ // "url",
968
+ // ).and.callThrough();
969
+
970
+ // updatePathOnLocationChangeSuccessTo("/Home");
971
+
972
+ // $rootScope.$digest();
973
+
974
+ // expect($browser.url()).toEqual("http://server/app/#!/Home");
975
+ // expect($location.path()).toEqual("/Home");
976
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
977
+ // });
978
+ // });
979
+
980
+ // it("should not infinite $digest when going to base URL without trailing slash when $locationChangeSuccess watcher changes path to /", () => {
981
+ // initService({ html5Mode: true, supportHistory: false });
982
+ // mockUpBrowser({
983
+ // initialUrl: "http://server/app/Home",
984
+ // baseHref: "/app/",
985
+ // });
986
+ // inject(($rootScope, $location, $browser, $window) => {
987
+ // const $browserUrl = spyOnlyCallsWithArgs(
988
+ // $browser,
989
+ // "url",
990
+ // ).and.callThrough();
991
+
992
+ // updatePathOnLocationChangeSuccessTo("/");
993
+
994
+ // $rootScope.$digest();
995
+
996
+ // expect($browser.url()).toEqual("http://server/app/#!/");
997
+ // expect($location.path()).toEqual("/");
998
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
999
+ // expect($browserUrl.calls.argsFor(0)).toEqual([
1000
+ // "http://server/app/#!/",
1001
+ // false,
1002
+ // null,
1003
+ // ]);
1004
+ // });
1005
+ // });
1006
+
1007
+ // it("should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes path to /Home", () => {
1008
+ // initService({ html5Mode: true, supportHistory: false });
1009
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1010
+ // inject(($rootScope, $location, $browser) => {
1011
+ // const $browserUrl = spyOnlyCallsWithArgs(
1012
+ // $browser,
1013
+ // "url",
1014
+ // ).and.callThrough();
1015
+
1016
+ // updatePathOnLocationChangeSuccessTo("/Home");
1017
+ // $rootScope.$digest();
1018
+
1019
+ // expect($browser.url()).toEqual("http://server/app/#!/Home");
1020
+ // expect($location.path()).toEqual("/Home");
1021
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
1022
+ // expect($browserUrl.calls.argsFor(0)).toEqual([
1023
+ // "http://server/app/#!/Home",
1024
+ // false,
1025
+ // null,
1026
+ // ]);
1027
+ // });
1028
+ // });
1029
+
1030
+ // it("should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes path to /", () => {
1031
+ // initService({ html5Mode: true, supportHistory: false });
1032
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1033
+ // inject(($rootScope, $location, $browser) => {
1034
+ // const $browserUrl = spyOnlyCallsWithArgs(
1035
+ // $browser,
1036
+ // "url",
1037
+ // ).and.callThrough();
1038
+
1039
+ // updatePathOnLocationChangeSuccessTo("/");
1040
+ // $rootScope.$digest();
1041
+
1042
+ // expect($browser.url()).toEqual("http://server/app/#!/");
1043
+ // expect($location.path()).toEqual("/");
1044
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
1045
+ // });
1046
+ // });
1047
+ // });
1048
+
1049
+ // describe("location watch for HTML5 browsers", () => {
1050
+ // it("should not infinite $digest when going to base URL without trailing slash when $locationChangeSuccess watcher changes path to /Home", () => {
1051
+ // initService({ html5Mode: true, supportHistory: true });
1052
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1053
+ // inject(($rootScope, $injector, $browser) => {
1054
+ // const $browserUrl = spyOnlyCallsWithArgs(
1055
+ // $browser,
1056
+ // "url",
1057
+ // ).and.callThrough();
1058
+
1059
+ // const $location = $injector.get("$location");
1060
+ // updatePathOnLocationChangeSuccessTo("/Home");
1061
+
1062
+ // $rootScope.$digest();
1063
+
1064
+ // expect($browser.url()).toEqual("http://server/app/Home");
1065
+ // expect($location.path()).toEqual("/Home");
1066
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
1067
+ // });
1068
+ // });
1069
+
1070
+ // it("should not infinite $digest when going to base URL without trailing slash when $locationChangeSuccess watcher changes path to /", () => {
1071
+ // initService({ html5Mode: true, supportHistory: true });
1072
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1073
+ // inject(($rootScope, $injector, $browser) => {
1074
+ // const $browserUrl = spyOnlyCallsWithArgs(
1075
+ // $browser,
1076
+ // "url",
1077
+ // ).and.callThrough();
1078
+
1079
+ // const $location = $injector.get("$location");
1080
+ // updatePathOnLocationChangeSuccessTo("/");
1081
+
1082
+ // $rootScope.$digest();
1083
+
1084
+ // expect($browser.url()).toEqual("http://server/app/");
1085
+ // expect($location.path()).toEqual("/");
1086
+ // expect($browserUrl).not.toHaveBeenCalled();
1087
+ // });
1088
+ // });
1089
+
1090
+ // it("should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes path to /Home", () => {
1091
+ // initService({ html5Mode: true, supportHistory: true });
1092
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1093
+ // inject(($rootScope, $injector, $browser) => {
1094
+ // const $browserUrl = spyOnlyCallsWithArgs(
1095
+ // $browser,
1096
+ // "url",
1097
+ // ).and.callThrough();
1098
+
1099
+ // const $location = $injector.get("$location");
1100
+ // updatePathOnLocationChangeSuccessTo("/Home");
1101
+
1102
+ // $rootScope.$digest();
1103
+
1104
+ // expect($browser.url()).toEqual("http://server/app/Home");
1105
+ // expect($location.path()).toEqual("/Home");
1106
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
1107
+ // });
1108
+ // });
1109
+
1110
+ // it("should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes path to /", () => {
1111
+ // initService({ html5Mode: true, supportHistory: true });
1112
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1113
+ // inject(($rootScope, $injector, $browser) => {
1114
+ // const $browserUrl = spyOnlyCallsWithArgs(
1115
+ // $browser,
1116
+ // "url",
1117
+ // ).and.callThrough();
1118
+
1119
+ // const $location = $injector.get("$location");
1120
+ // updatePathOnLocationChangeSuccessTo("/");
1121
+
1122
+ // $rootScope.$digest();
1123
+
1124
+ // expect($browser.url()).toEqual("http://server/app/");
1125
+ // expect($location.path()).toEqual("/");
1126
+ // expect($browserUrl).not.toHaveBeenCalled();
1127
+ // });
1128
+ // });
1129
+
1130
+ // // https://github.com/angular/angular.js/issues/16592
1131
+ // it("should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes query params to contain quote", () => {
1132
+ // initService({ html5Mode: true, supportHistory: true });
1133
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1134
+ // inject(($rootScope, $injector, $browser) => {
1135
+ // const $browserUrl = spyOnlyCallsWithArgs(
1136
+ // $browser,
1137
+ // "url",
1138
+ // ).and.callThrough();
1139
+
1140
+ // const $location = $injector.get("$location");
1141
+ // updatePathOnLocationChangeSuccessTo("/", { q: "'" });
1142
+
1143
+ // $rootScope.$digest();
1144
+
1145
+ // expect($location.path()).toEqual("/");
1146
+ // expect($location.search()).toEqual({ q: "'" });
1147
+ // expect($browserUrl).toHaveBeenCalledTimes(1);
1148
+ // });
1149
+ // });
1150
+ // });
1151
+ // });
1152
+
1153
+ // describe("wiring", () => {
1154
+ // it("should update $location when browser url changes", () => {
1155
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1156
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1157
+ // inject(($window, $browser, $location, $rootScope) => {
1158
+ // spyOn($location, "$$parse").and.callThrough();
1159
+ // $window.location.href = "http://new.com/a/b#!/aaa";
1160
+ // $browser.$$checkUrlChange();
1161
+ // expect($location.absUrl()).toBe("http://new.com/a/b#!/aaa");
1162
+ // expect($location.path()).toBe("/aaa");
1163
+ // expect($location.$$parse).toHaveBeenCalled();
1164
+ // });
1165
+ // });
1166
+
1167
+ // // location.href = '...' fires hashchange event synchronously, so it might happen inside $apply
1168
+ // it("should not $apply when browser url changed inside $apply", () => {
1169
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1170
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1171
+ // inject(($rootScope, $browser, $location, $window) => {
1172
+ // const OLD_URL = $browser.url();
1173
+ // const NEW_URL = "http://new.com/a/b#!/new";
1174
+
1175
+ // $rootScope.$apply(() => {
1176
+ // $window.location.href = NEW_URL;
1177
+ // $browser.$$checkUrlChange(); // simulate firing event from browser
1178
+ // expect($location.absUrl()).toBe(OLD_URL); // should be async
1179
+ // });
1180
+
1181
+ // expect($location.absUrl()).toBe(NEW_URL);
1182
+ // });
1183
+ // });
1184
+
1185
+ // // location.href = '...' fires hashchange event synchronously, so it might happen inside $digest
1186
+ // it("should not $apply when browser url changed inside $digest", () => {
1187
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1188
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1189
+ // inject(($rootScope, $browser, $location, $window) => {
1190
+ // const OLD_URL = $browser.url();
1191
+ // const NEW_URL = "http://new.com/a/b#!/new";
1192
+ // let notRunYet = true;
1193
+
1194
+ // $rootScope.$watch(() => {
1195
+ // if (notRunYet) {
1196
+ // notRunYet = false;
1197
+ // $window.location.href = NEW_URL;
1198
+ // $browser.$$checkUrlChange(); // simulate firing event from browser
1199
+ // expect($location.absUrl()).toBe(OLD_URL); // should be async
1200
+ // }
1201
+ // });
1202
+
1203
+ // $rootScope.$digest();
1204
+ // expect($location.absUrl()).toBe(NEW_URL);
1205
+ // });
1206
+ // });
1207
+
1208
+ // it("should update browser when $location changes", () => {
1209
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1210
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1211
+ // inject(($rootScope, $browser, $location) => {
1212
+ // const $browserUrl = spyOnlyCallsWithArgs(
1213
+ // $browser,
1214
+ // "url",
1215
+ // ).and.callThrough();
1216
+ // $location.path("/new/path");
1217
+ // expect($browserUrl).not.toHaveBeenCalled();
1218
+ // $rootScope.$apply();
1219
+
1220
+ // expect($browserUrl).toHaveBeenCalled();
1221
+ // expect($browser.url()).toBe("http://new.com/a/b#!/new/path");
1222
+ // });
1223
+ // });
1224
+
1225
+ // it("should update browser only once per $apply cycle", () => {
1226
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1227
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1228
+ // inject(($rootScope, $browser, $location) => {
1229
+ // const $browserUrl = spyOnlyCallsWithArgs(
1230
+ // $browser,
1231
+ // "url",
1232
+ // ).and.callThrough();
1233
+ // $location.path("/new/path");
1234
+
1235
+ // $rootScope.$watch(() => {
1236
+ // $location.search("a=b");
1237
+ // });
1238
+
1239
+ // $rootScope.$apply();
1240
+ // expect($browserUrl).toHaveBeenCalled();
1241
+ // expect($browser.url()).toBe("http://new.com/a/b#!/new/path?a=b");
1242
+ // });
1243
+ // });
1244
+
1245
+ // it("should replace browser url when url was replaced at least once", () => {
1246
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1247
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1248
+ // inject(($rootScope, $browser, $location) => {
1249
+ // const $browserUrl = spyOnlyCallsWithArgs(
1250
+ // $browser,
1251
+ // "url",
1252
+ // ).and.callThrough();
1253
+ // $location.path("/n/url").replace();
1254
+ // $rootScope.$apply();
1255
+
1256
+ // expect($browserUrl).toHaveBeenCalled();
1257
+ // expect($browserUrl.calls.mostRecent().args).toEqual([
1258
+ // "http://new.com/a/b#!/n/url",
1259
+ // true,
1260
+ // null,
1261
+ // ]);
1262
+ // expect($location.$$replace).toBe(false);
1263
+ // });
1264
+ // });
1265
+
1266
+ // it("should always reset replace flag after running watch", () => {
1267
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1268
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1269
+ // inject(($rootScope, $browser, $location) => {
1270
+ // // init watches
1271
+ // $location.url("/initUrl");
1272
+ // $rootScope.$apply();
1273
+
1274
+ // // changes url but resets it before digest
1275
+ // $location.url("/newUrl").replace().url("/initUrl");
1276
+ // $rootScope.$apply();
1277
+ // expect($location.$$replace).toBe(false);
1278
+
1279
+ // // set the url to the old value
1280
+ // $location.url("/newUrl").replace();
1281
+ // $rootScope.$apply();
1282
+ // expect($location.$$replace).toBe(false);
1283
+
1284
+ // // doesn't even change url only calls replace()
1285
+ // $location.replace();
1286
+ // $rootScope.$apply();
1287
+ // expect($location.$$replace).toBe(false);
1288
+ // });
1289
+ // });
1290
+
1291
+ // it("should update the browser if changed from within a watcher", () => {
1292
+ // initService({ html5Mode: false, hashPrefix: "!", supportHistory: true });
1293
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b#!", baseHref: "/a/b" });
1294
+ // inject(($rootScope, $browser, $location) => {
1295
+ // $rootScope.$watch(
1296
+ // () => true,
1297
+ // () => {
1298
+ // $location.path("/changed");
1299
+ // },
1300
+ // );
1301
+
1302
+ // $rootScope.$digest();
1303
+ // expect($browser.url()).toBe("http://new.com/a/b#!/changed");
1304
+ // });
1305
+ // });
1306
+
1307
+ // it("should not infinitely digest if hash is set when there is no hashPrefix", () => {
1308
+ // initService({ html5Mode: false, hashPrefix: "", supportHistory: true });
1309
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b", baseHref: "/a/b" });
1310
+ // inject(($rootScope, $browser, $location) => {
1311
+ // $location.hash("test");
1312
+
1313
+ // $rootScope.$digest();
1314
+ // expect($browser.url()).toBe("http://new.com/a/b##test");
1315
+ // });
1316
+ // });
1317
+ // });
1318
+
1319
+ // describe("wiring in html5 mode", () => {
1320
+ // it("should initialize state to initial state from the browser", () => {
1321
+ // initService({ html5Mode: true, supportHistory: true });
1322
+ // mockUpBrowser({
1323
+ // initialUrl: "http://new.com/a/b/",
1324
+ // baseHref: "/a/b/",
1325
+ // state: { a: 2 },
1326
+ // });
1327
+ // inject(($location) => {
1328
+ // expect($location.state()).toEqual({ a: 2 });
1329
+ // });
1330
+ // });
1331
+
1332
+ // it("should update $location when browser state changes", () => {
1333
+ // initService({ html5Mode: true, supportHistory: true });
1334
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1335
+ // inject(($location, $rootScope, $window) => {
1336
+ // $window.history.pushState({ b: 3 });
1337
+ // $rootScope.$digest();
1338
+
1339
+ // expect($location.state()).toEqual({ b: 3 });
1340
+
1341
+ // $window.history.pushState(
1342
+ // { b: 4 },
1343
+ // null,
1344
+ // `${$window.location.href}c?d=e#f`,
1345
+ // );
1346
+ // $rootScope.$digest();
1347
+
1348
+ // expect($location.path()).toBe("/c");
1349
+ // expect($location.search()).toEqual({ d: "e" });
1350
+ // expect($location.hash()).toBe("f");
1351
+ // expect($location.state()).toEqual({ b: 4 });
1352
+ // });
1353
+ // });
1354
+
1355
+ // // https://github.com/angular/angular.js/issues/16592
1356
+ // it("should not infinite $digest on pushState() with quote in param", () => {
1357
+ // initService({ html5Mode: true, supportHistory: true });
1358
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1359
+ // inject(($rootScope, $injector, $window) => {
1360
+ // const $location = $injector.get("$location");
1361
+ // $rootScope.$digest(); // allow $location initialization to finish
1362
+
1363
+ // $window.history.pushState({}, null, "http://server/app/Home?q='");
1364
+ // $rootScope.$digest();
1365
+
1366
+ // expect($location.absUrl()).toEqual("http://server/app/Home?q='");
1367
+ // expect($location.path()).toEqual("/Home");
1368
+ // expect($location.search()).toEqual({ q: "'" });
1369
+ // });
1370
+ // });
1371
+
1372
+ // // https://github.com/angular/angular.js/issues/16592
1373
+ // it("should not infinite $digest on popstate event with quote in param", () => {
1374
+ // initService({ html5Mode: true, supportHistory: true });
1375
+ // mockUpBrowser({ initialUrl: "http://server/app/", baseHref: "/app/" });
1376
+ // inject(($rootScope, $injector, $window) => {
1377
+ // const $location = $injector.get("$location");
1378
+ // $rootScope.$digest(); // allow $location initialization to finish
1379
+
1380
+ // $window.location.href = "http://server/app/Home?q='";
1381
+ // jqLite($window).triggerHandler("popstate");
1382
+
1383
+ // expect($location.absUrl()).toEqual("http://server/app/Home?q='");
1384
+ // expect($location.path()).toEqual("/Home");
1385
+ // expect($location.search()).toEqual({ q: "'" });
1386
+ // });
1387
+ // });
1388
+
1389
+ // it("should replace browser url & state when replace() was called at least once", () => {
1390
+ // initService({ html5Mode: true, supportHistory: true });
1391
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1392
+ // inject(($rootScope, $location, $browser) => {
1393
+ // const $browserUrl = spyOnlyCallsWithArgs(
1394
+ // $browser,
1395
+ // "url",
1396
+ // ).and.callThrough();
1397
+ // $location.path("/n/url").state({ a: 2 }).replace();
1398
+ // $rootScope.$apply();
1399
+
1400
+ // expect($browserUrl).toHaveBeenCalled();
1401
+ // expect($browserUrl.calls.mostRecent().args).toEqual([
1402
+ // "http://new.com/a/b/n/url",
1403
+ // true,
1404
+ // { a: 2 },
1405
+ // ]);
1406
+ // expect($location.$$replace).toBe(false);
1407
+ // expect($location.$$state).toEqual({ a: 2 });
1408
+ // });
1409
+ // });
1410
+
1411
+ // it("should use only the most recent url & state definition", () => {
1412
+ // initService({ html5Mode: true, supportHistory: true });
1413
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1414
+
1415
+ // inject(($rootScope, $location, $browser) => {
1416
+ // const $browserUrl = spyOnlyCallsWithArgs(
1417
+ // $browser,
1418
+ // "url",
1419
+ // ).and.callThrough();
1420
+ // $location
1421
+ // .path("/n/url")
1422
+ // .state({ a: 2 })
1423
+ // .replace()
1424
+ // .state({ b: 3 })
1425
+ // .path("/o/url");
1426
+ // $rootScope.$apply();
1427
+
1428
+ // expect($browserUrl).toHaveBeenCalled();
1429
+ // expect($browserUrl.calls.mostRecent().args).toEqual([
1430
+ // "http://new.com/a/b/o/url",
1431
+ // true,
1432
+ // { b: 3 },
1433
+ // ]);
1434
+ // expect($location.$$replace).toBe(false);
1435
+ // expect($location.$$state).toEqual({ b: 3 });
1436
+ // });
1437
+ // });
1438
+
1439
+ // it("should allow to set state without touching the URL", () => {
1440
+ // initService({ html5Mode: true, supportHistory: true });
1441
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1442
+
1443
+ // inject(($rootScope, $location, $browser) => {
1444
+ // const $browserUrl = spyOnlyCallsWithArgs(
1445
+ // $browser,
1446
+ // "url",
1447
+ // ).and.callThrough();
1448
+ // $location.state({ a: 2 }).replace().state({ b: 3 });
1449
+ // $rootScope.$apply();
1450
+
1451
+ // expect($browserUrl).toHaveBeenCalled();
1452
+ // expect($browserUrl.calls.mostRecent().args).toEqual([
1453
+ // "http://new.com/a/b/",
1454
+ // true,
1455
+ // { b: 3 },
1456
+ // ]);
1457
+ // expect($location.$$replace).toBe(false);
1458
+ // expect($location.$$state).toEqual({ b: 3 });
1459
+ // });
1460
+ // });
1461
+
1462
+ // it("should always reset replace flag after running watch", () => {
1463
+ // initService({ html5Mode: true, supportHistory: true });
1464
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1465
+
1466
+ // inject(($rootScope, $location) => {
1467
+ // // init watches
1468
+ // $location.url("/initUrl").state({ a: 2 });
1469
+ // $rootScope.$apply();
1470
+
1471
+ // // changes url & state but resets them before digest
1472
+ // $location
1473
+ // .url("/newUrl")
1474
+ // .state({ a: 2 })
1475
+ // .replace()
1476
+ // .state({ b: 3 })
1477
+ // .url("/initUrl");
1478
+ // $rootScope.$apply();
1479
+ // expect($location.$$replace).toBe(false);
1480
+
1481
+ // // set the url to the old value
1482
+ // $location.url("/newUrl").state({ a: 2 }).replace();
1483
+ // $rootScope.$apply();
1484
+ // expect($location.$$replace).toBe(false);
1485
+
1486
+ // // doesn't even change url only calls replace()
1487
+ // $location.replace();
1488
+ // $rootScope.$apply();
1489
+ // expect($location.$$replace).toBe(false);
1490
+ // });
1491
+ // });
1492
+
1493
+ // it("should allow to modify state only before digest", () => {
1494
+ // initService({ html5Mode: true, supportHistory: true });
1495
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1496
+
1497
+ // inject(($rootScope, $location, $browser) => {
1498
+ // const o = { a: 2 };
1499
+ // $location.state(o);
1500
+ // o.a = 3;
1501
+ // $rootScope.$apply();
1502
+ // expect($browser.state()).toEqual({ a: 3 });
1503
+
1504
+ // o.a = 4;
1505
+ // $rootScope.$apply();
1506
+ // expect($browser.state()).toEqual({ a: 3 });
1507
+ // });
1508
+ // });
1509
+
1510
+ // it("should make $location.state() referencially identical with $browser.state() after digest", () => {
1511
+ // initService({ html5Mode: true, supportHistory: true });
1512
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1513
+
1514
+ // inject(($rootScope, $location, $browser) => {
1515
+ // $location.state({ a: 2 });
1516
+ // $rootScope.$apply();
1517
+ // expect($location.state()).toBe($browser.state());
1518
+ // });
1519
+ // });
1520
+
1521
+ // it("should allow to query the state after digest", () => {
1522
+ // initService({ html5Mode: true, supportHistory: true });
1523
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1524
+
1525
+ // inject(($rootScope, $location) => {
1526
+ // $location.url("/foo").state({ a: 2 });
1527
+ // $rootScope.$apply();
1528
+ // expect($location.state()).toEqual({ a: 2 });
1529
+ // });
1530
+ // });
1531
+
1532
+ // it("should reset the state on .url() after digest", () => {
1533
+ // initService({ html5Mode: true, supportHistory: true });
1534
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1535
+
1536
+ // inject(($rootScope, $location, $browser) => {
1537
+ // $location.url("/foo").state({ a: 2 });
1538
+ // $rootScope.$apply();
1539
+
1540
+ // const $browserUrl = spyOnlyCallsWithArgs(
1541
+ // $browser,
1542
+ // "url",
1543
+ // ).and.callThrough();
1544
+ // $location.url("/bar");
1545
+ // $rootScope.$apply();
1546
+
1547
+ // expect($browserUrl).toHaveBeenCalled();
1548
+ // expect($browserUrl.calls.mostRecent().args).toEqual([
1549
+ // "http://new.com/a/b/bar",
1550
+ // false,
1551
+ // null,
1552
+ // ]);
1553
+ // });
1554
+ // });
1555
+
1556
+ // it("should force a page reload if navigating outside of the application base href", () => {
1557
+ // initService({ html5Mode: true, supportHistory: true });
1558
+ // mockUpBrowser({ initialUrl: "http://new.com/a/b/", baseHref: "/a/b/" });
1559
+
1560
+ // inject(($window, $browser, $location) => {
1561
+ // $window.location.href = "http://new.com/a/outside.html";
1562
+ // spyOn($window.location, "$$setHref");
1563
+ // expect($window.location.$$setHref).not.toHaveBeenCalled();
1564
+ // $browser.$$checkUrlChange();
1565
+ // expect($window.location.$$setHref).toHaveBeenCalledWith(
1566
+ // "http://new.com/a/outside.html",
1567
+ // );
1568
+ // });
1569
+ // });
1570
+ // });
1571
+
1572
+ // TODO MOVE TO PLAYWRIGHT
1573
+ // html5 history is disabled
1574
+ // describe("disabled history", () => {
1575
+ // it("should use hashbang url with hash prefix", () => {
1576
+ // initService({ html5Mode: false, hashPrefix: "!" });
1577
+ // mockUpBrowser({
1578
+ // initialUrl: "http://domain.com/base/index.html#!/a/b",
1579
+ // baseHref: "/base/index.html",
1580
+ // });
1581
+ // inject(($rootScope, $location, $browser) => {
1582
+ // expect($browser.url()).toBe("http://domain.com/base/index.html#!/a/b");
1583
+ // $location.path("/new");
1584
+ // $location.search({ a: true });
1585
+ // $rootScope.$apply();
1586
+ // expect($browser.url()).toBe(
1587
+ // "http://domain.com/base/index.html#!/new?a",
1588
+ // );
1589
+ // });
1590
+ // });
1591
+
1592
+ // it("should use hashbang url without hash prefix", () => {
1593
+ // initService({ html5Mode: false, hashPrefix: "" });
1594
+ // mockUpBrowser({
1595
+ // initialUrl: "http://domain.com/base/index.html#/a/b",
1596
+ // baseHref: "/base/index.html",
1597
+ // });
1598
+ // inject(($rootScope, $location, $browser) => {
1599
+ // expect($browser.url()).toBe("http://domain.com/base/index.html#/a/b");
1600
+ // $location.path("/new");
1601
+ // $location.search({ a: true });
1602
+ // $rootScope.$apply();
1603
+ // expect($browser.url()).toBe("http://domain.com/base/index.html#/new?a");
1604
+ // });
1605
+ // });
1606
+ // });
1607
+
1608
+ // TODO MOVE TO PLAYWRIGHT
1609
+ // html5 history enabled, but not supported by browser
1610
+ // describe("history on old browser", () => {
1611
+ // it("should use hashbang url with hash prefix", () => {
1612
+ // initService({ html5Mode: true, hashPrefix: "!!", supportHistory: false });
1613
+ // inject(
1614
+ // initBrowser({
1615
+ // url: "http://domain.com/base/index.html#!!/a/b",
1616
+ // basePath: "/base/index.html",
1617
+ // }),
1618
+ // ($rootScope, $location, $browser) => {
1619
+ // expect($browser.url()).toBe(
1620
+ // "http://domain.com/base/index.html#!!/a/b",
1621
+ // );
1622
+ // $location.path("/new");
1623
+ // $location.search({ a: true });
1624
+ // $rootScope.$apply();
1625
+ // expect($browser.url()).toBe(
1626
+ // "http://domain.com/base/index.html#!!/new?a",
1627
+ // );
1628
+ // },
1629
+ // );
1630
+ // });
1631
+
1632
+ // it("should redirect to hashbang url when new url given", () => {
1633
+ // initService({ html5Mode: true, hashPrefix: "!" });
1634
+ // inject(
1635
+ // initBrowser({
1636
+ // url: "http://domain.com/base/new-path/index.html",
1637
+ // basePath: "/base/index.html",
1638
+ // }),
1639
+ // ($browser, $location) => {
1640
+ // expect($browser.url()).toBe(
1641
+ // "http://domain.com/base/index.html#!/new-path/index.html",
1642
+ // );
1643
+ // },
1644
+ // );
1645
+ // });
1646
+
1647
+ // it("should correctly convert html5 url with path matching basepath to hashbang url", () => {
1648
+ // initService({ html5Mode: true, hashPrefix: "!", supportHistory: false });
1649
+ // inject(
1650
+ // initBrowser({
1651
+ // url: "http://domain.com/base/index.html",
1652
+ // basePath: "/base/index.html",
1653
+ // }),
1654
+ // ($browser, $location) => {
1655
+ // expect($browser.url()).toBe(
1656
+ // "http://domain.com/base/index.html#!/index.html",
1657
+ // );
1658
+ // },
1659
+ // );
1660
+ // });
1661
+ // });
1662
+
1663
+ // TODO MOVE TO PLAYWRIGHT
1664
+ // html5 history enabled and supported by browser
1665
+ // describe("history on new browser", () => {
1666
+ // it("should use new url", () => {
1667
+ // initService({ html5Mode: true, hashPrefix: "", supportHistory: true });
1668
+ // mockUpBrowser({
1669
+ // initialUrl: "http://domain.com/base/old/index.html#a",
1670
+ // baseHref: "/base/index.html",
1671
+ // });
1672
+ // inject(($rootScope, $location, $browser) => {
1673
+ // expect($browser.url()).toBe("http://domain.com/base/old/index.html#a");
1674
+ // $location.path("/new");
1675
+ // $location.search({ a: true });
1676
+ // $rootScope.$apply();
1677
+ // expect($browser.url()).toBe("http://domain.com/base/new?a#a");
1678
+ // });
1679
+ // });
1680
+
1681
+ // it("should rewrite when hashbang url given", () => {
1682
+ // initService({ html5Mode: true, hashPrefix: "!", supportHistory: true });
1683
+ // mockUpBrowser({
1684
+ // initialUrl: "http://domain.com/base/index.html#!/a/b",
1685
+ // baseHref: "/base/index.html",
1686
+ // });
1687
+ // inject(($rootScope, $location, $browser) => {
1688
+ // expect($browser.url()).toBe("http://domain.com/base/a/b");
1689
+ // $location.path("/new");
1690
+ // $location.hash("abc");
1691
+ // $rootScope.$apply();
1692
+ // expect($browser.url()).toBe("http://domain.com/base/new#abc");
1693
+ // expect($location.path()).toBe("/new");
1694
+ // });
1695
+ // });
1696
+
1697
+ // it("should rewrite when hashbang url given (without hash prefix)", () => {
1698
+ // initService({ html5Mode: true, hashPrefix: "", supportHistory: true });
1699
+ // mockUpBrowser({
1700
+ // initialUrl: "http://domain.com/base/index.html#/a/b",
1701
+ // baseHref: "/base/index.html",
1702
+ // });
1703
+ // inject(($rootScope, $location, $browser) => {
1704
+ // expect($browser.url()).toBe("http://domain.com/base/a/b");
1705
+ // expect($location.path()).toBe("/a/b");
1706
+ // });
1707
+ // });
1708
+ // });
1709
+
1710
+ // describe("PATH_MATCH", () => {
1711
+ // it("should parse just path", () => {
1712
+ // const match = PATH_MATCH.exec("/path");
1713
+ // expect(match[1]).toBe("/path");
1714
+ // });
1715
+
1716
+ // it("should parse path with search", () => {
1717
+ // const match = PATH_MATCH.exec("/ppp/a?a=b&c");
1718
+ // expect(match[1]).toBe("/ppp/a");
1719
+ // expect(match[3]).toBe("a=b&c");
1720
+ // });
1721
+
1722
+ // it("should parse path with hash", () => {
1723
+ // const match = PATH_MATCH.exec("/ppp/a#abc?");
1724
+ // expect(match[1]).toBe("/ppp/a");
1725
+ // expect(match[5]).toBe("abc?");
1726
+ // });
1727
+
1728
+ // it("should parse path with both search and hash", () => {
1729
+ // const match = PATH_MATCH.exec("/ppp/a?a=b&c#abc/d?");
1730
+ // expect(match[3]).toBe("a=b&c");
1731
+ // });
1732
+ // });
1733
+
1734
+ // TODO MOVE TO PLAYWRIGHT
1735
+ // describe("link rewriting", () => {
1736
+ // let root;
1737
+ // let link;
1738
+ // let originalBrowser;
1739
+ // let lastEventPreventDefault;
1740
+
1741
+ // function configureTestLink(options) {
1742
+ // let { linkHref } = options;
1743
+ // const { relLink } = options;
1744
+ // let { attrs } = options;
1745
+ // const { content } = options;
1746
+
1747
+ // attrs = attrs ? ` ${attrs} ` : "";
1748
+
1749
+ // if (typeof linkHref === "string" && !relLink) {
1750
+ // if (linkHref[0] === "/") {
1751
+ // linkHref = `http://host.com${linkHref}`;
1752
+ // } else if (!linkHref.match(/:\/\//)) {
1753
+ // // fake the behavior of <base> tag
1754
+ // linkHref = `http://host.com/base/${linkHref}`;
1755
+ // }
1756
+ // }
1757
+
1758
+ // if (linkHref) {
1759
+ // link = jqLite(`<a href="${linkHref}"${attrs}>${content}</a>`)[0];
1760
+ // } else {
1761
+ // link = jqLite(`<a ${attrs}>${content}</a>`)[0];
1762
+ // }
1763
+
1764
+ // module(
1765
+ // ($provide) =>
1766
+ // function ($rootElement, $document) {
1767
+ // $rootElement.append(link);
1768
+ // root = $rootElement[0];
1769
+ // // we need to do this otherwise we can't simulate events
1770
+ // $document.find("body").append($rootElement);
1771
+ // },
1772
+ // );
1773
+ // }
1774
+
1775
+ // function setupRewriteChecks() {
1776
+ // return function ($browser, $location, $rootElement) {
1777
+ // originalBrowser = $browser.url();
1778
+ // // we have to prevent the default operation, as we need to test absolute links (http://...)
1779
+ // // and navigating to these links would kill jstd
1780
+ // $rootElement.on("click", (e) => {
1781
+ // lastEventPreventDefault = e.isDefaultPrevented();
1782
+ // e.preventDefault();
1783
+ // });
1784
+ // };
1785
+ // }
1786
+
1787
+ // function expectRewriteTo($browser, url) {
1788
+ // expect(lastEventPreventDefault).toBe(true);
1789
+ // expect($browser.url()).toBe(url);
1790
+ // }
1791
+
1792
+ // function expectNoRewrite($browser) {
1793
+ // expect(lastEventPreventDefault).toBe(false);
1794
+ // expect($browser.url()).toBe(originalBrowser);
1795
+ // }
1796
+
1797
+ // afterEach(() => {
1798
+ // dealoc(root);
1799
+ // dealoc(window.document.body);
1800
+ // });
1801
+
1802
+ // it("should rewrite rel link to new url when history enabled on new browser", () => {
1803
+ // configureTestLink({ linkHref: "link?a#b" });
1804
+ // initService({ html5Mode: true, supportHistory: true });
1805
+ // inject(
1806
+ // initBrowser({
1807
+ // url: "http://host.com/base/index.html",
1808
+ // basePath: "/base/index.html",
1809
+ // }),
1810
+ // setupRewriteChecks(),
1811
+ // ($browser) => {
1812
+ // browserTrigger(link, "click");
1813
+ // expectRewriteTo($browser, "http://host.com/base/link?a#b");
1814
+ // },
1815
+ // );
1816
+ // });
1817
+
1818
+ // it("should do nothing if already on the same URL", () => {
1819
+ // configureTestLink({ linkHref: "/base/" });
1820
+ // initService({ html5Mode: true, supportHistory: true });
1821
+ // inject(
1822
+ // initBrowser({
1823
+ // url: "http://host.com/base/index.html",
1824
+ // basePath: "/base/index.html",
1825
+ // }),
1826
+ // setupRewriteChecks(),
1827
+ // ($browser) => {
1828
+ // browserTrigger(link, "click");
1829
+ // expectRewriteTo($browser, "http://host.com/base/");
1830
+
1831
+ // jqLite(link).attr("href", "http://host.com/base/foo");
1832
+ // browserTrigger(link, "click");
1833
+ // expectRewriteTo($browser, "http://host.com/base/foo");
1834
+
1835
+ // jqLite(link).attr("href", "http://host.com/base/");
1836
+ // browserTrigger(link, "click");
1837
+ // expectRewriteTo($browser, "http://host.com/base/");
1838
+
1839
+ // jqLite(link)
1840
+ // .attr("href", "http://host.com/base/foo")
1841
+ // .on("click", (e) => {
1842
+ // e.preventDefault();
1843
+ // });
1844
+ // browserTrigger(link, "click");
1845
+ // expect($browser.url()).toBe("http://host.com/base/");
1846
+ // },
1847
+ // );
1848
+ // });
1849
+
1850
+ // it("should rewrite abs link to new url when history enabled on new browser", () => {
1851
+ // configureTestLink({ linkHref: "/base/link?a#b" });
1852
+ // initService({ html5Mode: true, supportHistory: true });
1853
+ // inject(
1854
+ // initBrowser({
1855
+ // url: "http://host.com/base/index.html",
1856
+ // basePath: "/base/index.html",
1857
+ // }),
1858
+ // setupRewriteChecks(),
1859
+ // ($browser) => {
1860
+ // browserTrigger(link, "click");
1861
+ // expectRewriteTo($browser, "http://host.com/base/link?a#b");
1862
+ // },
1863
+ // );
1864
+ // });
1865
+
1866
+ // it("should rewrite rel link to hashbang url when history enabled on old browser", () => {
1867
+ // configureTestLink({ linkHref: "link?a#b" });
1868
+ // initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
1869
+ // inject(
1870
+ // initBrowser({
1871
+ // url: "http://host.com/base/index.html",
1872
+ // basePath: "/base/index.html",
1873
+ // }),
1874
+ // setupRewriteChecks(),
1875
+ // ($browser) => {
1876
+ // browserTrigger(link, "click");
1877
+ // expectRewriteTo(
1878
+ // $browser,
1879
+ // "http://host.com/base/index.html#!/link?a#b",
1880
+ // );
1881
+ // },
1882
+ // );
1883
+ // });
1884
+
1885
+ // // Regression (gh-7721)
1886
+ // it("should not throw when clicking anchor with no href attribute when history enabled on old browser", () => {
1887
+ // configureTestLink({ linkHref: null });
1888
+ // initService({ html5Mode: true, supportHistory: false });
1889
+ // inject(
1890
+ // initBrowser({
1891
+ // url: "http://host.com/base/index.html",
1892
+ // basePath: "/base/index.html",
1893
+ // }),
1894
+ // setupRewriteChecks(),
1895
+ // ($browser) => {
1896
+ // browserTrigger(link, "click");
1897
+ // expectNoRewrite($browser);
1898
+ // },
1899
+ // );
1900
+ // });
1901
+
1902
+ // it('should produce relative paths correctly when $location.path() is "/" when history enabled on old browser', () => {
1903
+ // configureTestLink({ linkHref: "partial1" });
1904
+ // initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
1905
+ // inject(
1906
+ // initBrowser({
1907
+ // url: "http://host.com/base/index.html",
1908
+ // basePath: "/base/index.html",
1909
+ // }),
1910
+ // setupRewriteChecks(),
1911
+ // ($browser, $location, $rootScope) => {
1912
+ // $rootScope.$apply(() => {
1913
+ // $location.path("/");
1914
+ // });
1915
+ // browserTrigger(link, "click");
1916
+ // expectRewriteTo(
1917
+ // $browser,
1918
+ // "http://host.com/base/index.html#!/partial1",
1919
+ // );
1920
+ // },
1921
+ // );
1922
+ // });
1923
+
1924
+ // it("should rewrite abs link to hashbang url when history enabled on old browser", () => {
1925
+ // configureTestLink({ linkHref: "/base/link?a#b" });
1926
+ // initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
1927
+ // inject(
1928
+ // initBrowser({
1929
+ // url: "http://host.com/base/index.html",
1930
+ // basePath: "/base/index.html",
1931
+ // }),
1932
+ // setupRewriteChecks(),
1933
+ // ($browser) => {
1934
+ // browserTrigger(link, "click");
1935
+ // expectRewriteTo(
1936
+ // $browser,
1937
+ // "http://host.com/base/index.html#!/link?a#b",
1938
+ // );
1939
+ // },
1940
+ // );
1941
+ // });
1942
+
1943
+ // it("should not rewrite full url links to different domain", () => {
1944
+ // configureTestLink({ linkHref: "http://www.dot.abc/a?b=c" });
1945
+ // initService({ html5Mode: true });
1946
+ // inject(
1947
+ // initBrowser({
1948
+ // url: "http://host.com/base/index.html",
1949
+ // basePath: "/base/index.html",
1950
+ // }),
1951
+ // setupRewriteChecks(),
1952
+ // ($browser) => {
1953
+ // browserTrigger(link, "click");
1954
+ // expectNoRewrite($browser);
1955
+ // },
1956
+ // );
1957
+ // });
1958
+
1959
+ // it('should not rewrite links with target="_blank"', () => {
1960
+ // configureTestLink({ linkHref: "base/a?b=c", attrs: 'target="_blank"' });
1961
+ // initService({ html5Mode: true, supportHistory: true });
1962
+ // inject(
1963
+ // initBrowser({
1964
+ // url: "http://host.com/base/index.html",
1965
+ // basePath: "/base/index.html",
1966
+ // }),
1967
+ // setupRewriteChecks(),
1968
+ // ($browser) => {
1969
+ // browserTrigger(link, "click");
1970
+ // expectNoRewrite($browser);
1971
+ // },
1972
+ // );
1973
+ // });
1974
+
1975
+ // it("should not rewrite links with target specified", () => {
1976
+ // configureTestLink({
1977
+ // linkHref: "base/a?b=c",
1978
+ // attrs: 'target="some-frame"',
1979
+ // });
1980
+ // initService({ html5Mode: true, supportHistory: true });
1981
+ // inject(
1982
+ // initBrowser({
1983
+ // url: "http://host.com/base/index.html",
1984
+ // basePath: "/base/index.html",
1985
+ // }),
1986
+ // setupRewriteChecks(),
1987
+ // ($browser) => {
1988
+ // browserTrigger(link, "click");
1989
+ // expectNoRewrite($browser);
1990
+ // },
1991
+ // );
1992
+ // });
1993
+
1994
+ // it("should not rewrite links with `javascript:` URI", () => {
1995
+ // configureTestLink({
1996
+ // linkHref: ' jAvAsCrIpT:throw new Error("Boom!")',
1997
+ // relLink: true,
1998
+ // });
1999
+ // initService({ html5Mode: true, supportHistory: true });
2000
+ // inject(
2001
+ // initBrowser({
2002
+ // url: "http://host.com/base/index.html",
2003
+ // basePath: "/base/index.html",
2004
+ // }),
2005
+ // setupRewriteChecks(),
2006
+ // ($browser) => {
2007
+ // browserTrigger(link, "click");
2008
+ // expectNoRewrite($browser);
2009
+ // },
2010
+ // );
2011
+ // });
2012
+
2013
+ // it("should not rewrite links with `mailto:` URI", () => {
2014
+ // configureTestLink({ linkHref: " mAiLtO:foo@bar.com", relLink: true });
2015
+ // initService({ html5Mode: true, supportHistory: true });
2016
+ // inject(
2017
+ // initBrowser({
2018
+ // url: "http://host.com/base/index.html",
2019
+ // basePath: "/base/index.html",
2020
+ // }),
2021
+ // setupRewriteChecks(),
2022
+ // ($browser) => {
2023
+ // browserTrigger(link, "click");
2024
+ // expectNoRewrite($browser);
2025
+ // },
2026
+ // );
2027
+ // });
2028
+
2029
+ // it("should not rewrite links when rewriting links is disabled", () => {
2030
+ // configureTestLink({ linkHref: "link?a#b" });
2031
+ // initService({
2032
+ // html5Mode: { enabled: true, rewriteLinks: false },
2033
+ // supportHistory: true,
2034
+ // });
2035
+ // inject(
2036
+ // initBrowser({
2037
+ // url: "http://host.com/base/index.html",
2038
+ // basePath: "/base/index.html",
2039
+ // }),
2040
+ // setupRewriteChecks(),
2041
+ // ($browser) => {
2042
+ // browserTrigger(link, "click");
2043
+ // expectNoRewrite($browser);
2044
+ // },
2045
+ // );
2046
+ // });
2047
+
2048
+ // it("should rewrite links when the specified rewriteLinks attr is present", () => {
2049
+ // configureTestLink({ linkHref: "link?a#b", attrs: "do-rewrite" });
2050
+ // initService({
2051
+ // html5Mode: { enabled: true, rewriteLinks: "do-rewrite" },
2052
+ // supportHistory: true,
2053
+ // });
2054
+ // inject(
2055
+ // initBrowser({
2056
+ // url: "http://host.com/base/index.html",
2057
+ // basePath: "/base/index.html",
2058
+ // }),
2059
+ // setupRewriteChecks(),
2060
+ // ($browser) => {
2061
+ // browserTrigger(link, "click");
2062
+ // expectRewriteTo($browser, "http://host.com/base/link?a#b");
2063
+ // },
2064
+ // );
2065
+ // });
2066
+
2067
+ // it("should not rewrite links when the specified rewriteLinks attr is not present", () => {
2068
+ // configureTestLink({ linkHref: "link?a#b" });
2069
+ // initService({
2070
+ // html5Mode: { enabled: true, rewriteLinks: "do-rewrite" },
2071
+ // supportHistory: true,
2072
+ // });
2073
+ // inject(
2074
+ // initBrowser({
2075
+ // url: "http://host.com/base/index.html",
2076
+ // basePath: "/base/index.html",
2077
+ // }),
2078
+ // setupRewriteChecks(),
2079
+ // ($browser) => {
2080
+ // browserTrigger(link, "click");
2081
+ // expectNoRewrite($browser);
2082
+ // },
2083
+ // );
2084
+ // });
2085
+
2086
+ // it("should rewrite full url links to same domain and base path", () => {
2087
+ // configureTestLink({ linkHref: "http://host.com/base/new" });
2088
+ // initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
2089
+ // inject(
2090
+ // initBrowser({
2091
+ // url: "http://host.com/base/index.html",
2092
+ // basePath: "/base/index.html",
2093
+ // }),
2094
+ // setupRewriteChecks(),
2095
+ // ($browser) => {
2096
+ // browserTrigger(link, "click");
2097
+ // expectRewriteTo($browser, "http://host.com/base/index.html#!/new");
2098
+ // },
2099
+ // );
2100
+ // });
2101
+
2102
+ // it("should rewrite when clicked span inside link", () => {
2103
+ // configureTestLink({
2104
+ // linkHref: "some/link",
2105
+ // attrs: "",
2106
+ // content: "<span>link</span>",
2107
+ // });
2108
+ // initService({ html5Mode: true, supportHistory: true });
2109
+ // inject(
2110
+ // initBrowser({
2111
+ // url: "http://host.com/base/index.html",
2112
+ // basePath: "/base/index.html",
2113
+ // }),
2114
+ // setupRewriteChecks(),
2115
+ // ($browser) => {
2116
+ // const span = jqLite(link).find("span");
2117
+
2118
+ // browserTrigger(span, "click");
2119
+ // expectRewriteTo($browser, "http://host.com/base/some/link");
2120
+ // },
2121
+ // );
2122
+ // });
2123
+
2124
+ // it("should not rewrite when link to different base path when history enabled on new browser", () => {
2125
+ // configureTestLink({ linkHref: "/other_base/link" });
2126
+ // initService({ html5Mode: true, supportHistory: true });
2127
+ // inject(
2128
+ // initBrowser({
2129
+ // url: "http://host.com/base/index.html",
2130
+ // basePath: "/base/index.html",
2131
+ // }),
2132
+ // setupRewriteChecks(),
2133
+ // ($browser) => {
2134
+ // browserTrigger(link, "click");
2135
+ // expectNoRewrite($browser);
2136
+ // },
2137
+ // );
2138
+ // });
2139
+
2140
+ // it("should not rewrite when link to different base path when history enabled on old browser", () => {
2141
+ // configureTestLink({ linkHref: "/other_base/link" });
2142
+ // initService({ html5Mode: true, supportHistory: true });
2143
+ // inject(
2144
+ // initBrowser({
2145
+ // url: "http://host.com/base/index.html",
2146
+ // basePath: "/base/index.html",
2147
+ // }),
2148
+ // setupRewriteChecks(),
2149
+ // ($browser) => {
2150
+ // browserTrigger(link, "click");
2151
+ // expectNoRewrite($browser);
2152
+ // },
2153
+ // );
2154
+ // });
2155
+
2156
+ // it("should not rewrite when link to different base path when history disabled", () => {
2157
+ // configureTestLink({ linkHref: "/other_base/link" });
2158
+ // initService({ html5Mode: false });
2159
+ // inject(
2160
+ // initBrowser({
2161
+ // url: "http://host.com/base/index.html",
2162
+ // basePath: "/base/index.html",
2163
+ // }),
2164
+ // setupRewriteChecks(),
2165
+ // ($browser) => {
2166
+ // browserTrigger(link, "click");
2167
+ // expectNoRewrite($browser);
2168
+ // },
2169
+ // );
2170
+ // });
2171
+
2172
+ // it("should not rewrite when full link to different base path when history enabled on new browser", () => {
2173
+ // configureTestLink({ linkHref: "http://host.com/other_base/link" });
2174
+ // initService({ html5Mode: true, supportHistory: true });
2175
+ // inject(
2176
+ // initBrowser({
2177
+ // url: "http://host.com/base/index.html",
2178
+ // basePath: "/base/index.html",
2179
+ // }),
2180
+ // setupRewriteChecks(),
2181
+ // ($browser) => {
2182
+ // browserTrigger(link, "click");
2183
+ // expectNoRewrite($browser);
2184
+ // },
2185
+ // );
2186
+ // });
2187
+
2188
+ // it("should not rewrite when full link to different base path when history enabled on old browser", () => {
2189
+ // configureTestLink({ linkHref: "http://host.com/other_base/link" });
2190
+ // inject(
2191
+ // initBrowser({
2192
+ // url: "http://host.com/base/index.html",
2193
+ // basePath: "/base/index.html",
2194
+ // }),
2195
+ // setupRewriteChecks(),
2196
+ // ($browser) => {
2197
+ // browserTrigger(link, "click");
2198
+ // expectNoRewrite($browser);
2199
+ // },
2200
+ // );
2201
+ // });
2202
+
2203
+ // it("should not rewrite when full link to different base path when history disabled", () => {
2204
+ // configureTestLink({ linkHref: "http://host.com/other_base/link" });
2205
+ // initService({ html5Mode: false });
2206
+ // inject(
2207
+ // initBrowser({
2208
+ // url: "http://host.com/base/index.html",
2209
+ // basePath: "/base/index.html",
2210
+ // }),
2211
+ // setupRewriteChecks(),
2212
+ // ($browser) => {
2213
+ // browserTrigger(link, "click");
2214
+ // expectNoRewrite($browser);
2215
+ // },
2216
+ // );
2217
+ // });
2218
+
2219
+ // it('should replace current hash fragment when link begins with "#" history disabled', () => {
2220
+ // configureTestLink({ linkHref: "#link", relLink: true });
2221
+ // initService({ html5Mode: true, supportHistory: false, hashPrefix: "!" });
2222
+ // inject(
2223
+ // initBrowser({
2224
+ // url: "http://host.com/base/index.html",
2225
+ // basePath: "/base/index.html",
2226
+ // }),
2227
+ // setupRewriteChecks(),
2228
+ // ($browser, $location, $rootScope) => {
2229
+ // $rootScope.$apply(() => {
2230
+ // $location.path("/some");
2231
+ // $location.hash("foo");
2232
+ // });
2233
+ // browserTrigger(link, "click");
2234
+ // expect($location.hash()).toBe("link");
2235
+ // expectRewriteTo(
2236
+ // $browser,
2237
+ // "http://host.com/base/index.html#!/some#link",
2238
+ // );
2239
+ // },
2240
+ // );
2241
+ // });
2242
+
2243
+ // it('should replace current hash fragment when link begins with "#" history enabled', () => {
2244
+ // configureTestLink({ linkHref: "#link", relLink: true });
2245
+ // initService({ html5Mode: true, supportHistory: true });
2246
+ // inject(
2247
+ // initBrowser({
2248
+ // url: "http://host.com/base/index.html",
2249
+ // basePath: "/base/index.html",
2250
+ // }),
2251
+ // setupRewriteChecks(),
2252
+ // ($browser, $location, $rootScope) => {
2253
+ // $rootScope.$apply(() => {
2254
+ // $location.path("/some");
2255
+ // $location.hash("foo");
2256
+ // });
2257
+ // browserTrigger(link, "click");
2258
+ // expect($location.hash()).toBe("link");
2259
+ // expectRewriteTo($browser, "http://host.com/base/some#link");
2260
+ // },
2261
+ // );
2262
+ // });
2263
+
2264
+ // it("should not rewrite when clicked with ctrl pressed", () => {
2265
+ // configureTestLink({ linkHref: "base/a?b=c" });
2266
+ // initService({ html5Mode: true, supportHistory: true });
2267
+ // inject(
2268
+ // initBrowser({
2269
+ // url: "http://host.com/base/index.html",
2270
+ // basePath: "/base/index.html",
2271
+ // }),
2272
+ // setupRewriteChecks(),
2273
+ // ($browser) => {
2274
+ // browserTrigger(link, "click", { keys: ["ctrl"] });
2275
+ // expectNoRewrite($browser);
2276
+ // },
2277
+ // );
2278
+ // });
2279
+
2280
+ // it("should not rewrite when clicked with meta pressed", () => {
2281
+ // configureTestLink({ linkHref: "base/a?b=c" });
2282
+ // initService({ html5Mode: true, supportHistory: true });
2283
+ // inject(
2284
+ // initBrowser({
2285
+ // url: "http://host.com/base/index.html",
2286
+ // basePath: "/base/index.html",
2287
+ // }),
2288
+ // setupRewriteChecks(),
2289
+ // ($browser) => {
2290
+ // browserTrigger(link, "click", { keys: ["meta"] });
2291
+ // expectNoRewrite($browser);
2292
+ // },
2293
+ // );
2294
+ // });
2295
+
2296
+ // it("should not rewrite when right click pressed", () => {
2297
+ // configureTestLink({ linkHref: "base/a?b=c" });
2298
+ // initService({ html5Mode: true, supportHistory: true });
2299
+ // inject(
2300
+ // initBrowser({
2301
+ // url: "http://host.com/base/index.html",
2302
+ // basePath: "/base/index.html",
2303
+ // }),
2304
+ // setupRewriteChecks(),
2305
+ // ($browser) => {
2306
+ // const rightClick = window.document.createEvent("MouseEvents");
2307
+ // rightClick.initMouseEvent(
2308
+ // "click",
2309
+ // true,
2310
+ // true,
2311
+ // window,
2312
+ // 1,
2313
+ // 10,
2314
+ // 10,
2315
+ // 10,
2316
+ // 10,
2317
+ // false,
2318
+ // false,
2319
+ // false,
2320
+ // false,
2321
+ // 2,
2322
+ // null,
2323
+ // );
2324
+
2325
+ // link.dispatchEvent(rightClick);
2326
+ // expectNoRewrite($browser);
2327
+ // },
2328
+ // );
2329
+ // });
2330
+
2331
+ // it("should not rewrite when clicked with shift pressed", () => {
2332
+ // configureTestLink({ linkHref: "base/a?b=c" });
2333
+ // initService({ html5Mode: true, supportHistory: true });
2334
+ // inject(
2335
+ // initBrowser({
2336
+ // url: "http://host.com/base/index.html",
2337
+ // basePath: "/base/index.html",
2338
+ // }),
2339
+ // setupRewriteChecks(),
2340
+ // ($browser) => {
2341
+ // browserTrigger(link, "click", { keys: ["shift"] });
2342
+ // expectNoRewrite($browser);
2343
+ // },
2344
+ // );
2345
+ // });
2346
+
2347
+ // it("should not mess up hash urls when clicking on links in hashbang mode", () => {
2348
+ // let base;
2349
+ // module(
2350
+ // () =>
2351
+ // function ($browser) {
2352
+ // window.location.hash = "someHash";
2353
+ // base = window.location.href;
2354
+ // $browser.url(base);
2355
+ // base = base.split("#")[0];
2356
+ // },
2357
+ // );
2358
+ // inject(
2359
+ // (
2360
+ // $rootScope,
2361
+ // $compile,
2362
+ // $browser,
2363
+ // $rootElement,
2364
+ // $document,
2365
+ // $location,
2366
+ // ) => {
2367
+ // // we need to do this otherwise we can't simulate events
2368
+ // $document.find("body").append($rootElement);
2369
+
2370
+ // const element = $compile(
2371
+ // '<a href="#!/view1">v1</a><a href="#!/view2">v2</a>',
2372
+ // )($rootScope);
2373
+ // $rootElement.append(element);
2374
+ // const av1 = $rootElement.find("a").eq(0);
2375
+ // const av2 = $rootElement.find("a").eq(1);
2376
+
2377
+ // browserTrigger(av1, "click");
2378
+ // expect($browser.url()).toEqual(`${base}#!/view1`);
2379
+
2380
+ // browserTrigger(av2, "click");
2381
+ // expect($browser.url()).toEqual(`${base}#!/view2`);
2382
+
2383
+ // $rootElement.remove();
2384
+ // },
2385
+ // );
2386
+ // });
2387
+
2388
+ // it("should not mess up hash urls when clicking on links in hashbang mode with a prefix", () => {
2389
+ // let base;
2390
+ // module(
2391
+ // ($locationProvider) =>
2392
+ // function ($browser) {
2393
+ // window.location.hash = "!!someHash";
2394
+ // $browser.url((base = window.location.href));
2395
+ // base = base.split("#")[0];
2396
+ // $locationProvider.hashPrefix("!!");
2397
+ // },
2398
+ // );
2399
+ // inject(
2400
+ // (
2401
+ // $rootScope,
2402
+ // $compile,
2403
+ // $browser,
2404
+ // $rootElement,
2405
+ // $document,
2406
+ // $location,
2407
+ // ) => {
2408
+ // // we need to do this otherwise we can't simulate events
2409
+ // $document.find("body").append($rootElement);
2410
+
2411
+ // const element = $compile(
2412
+ // '<a href="#!!/view1">v1</a><a href="#!!/view2">v2</a>',
2413
+ // )($rootScope);
2414
+ // $rootElement.append(element);
2415
+ // const av1 = $rootElement.find("a").eq(0);
2416
+ // const av2 = $rootElement.find("a").eq(1);
2417
+
2418
+ // browserTrigger(av1, "click");
2419
+ // expect($browser.url()).toEqual(`${base}#!!/view1`);
2420
+
2421
+ // browserTrigger(av2, "click");
2422
+ // expect($browser.url()).toEqual(`${base}#!!/view2`);
2423
+ // },
2424
+ // );
2425
+ // });
2426
+
2427
+ // it("should not intercept clicks outside the current hash prefix", () => {
2428
+ // let base;
2429
+ // let clickHandler;
2430
+ // module(($provide) => {
2431
+ // $provide.value("$rootElement", {
2432
+ // on(event, handler) {
2433
+ // expect(event).toEqual("click");
2434
+ // clickHandler = handler;
2435
+ // },
2436
+ // off: () => {},
2437
+ // });
2438
+ // return function ($browser) {
2439
+ // $browser.url((base = "http://server/"));
2440
+ // };
2441
+ // });
2442
+ // inject(($location) => {
2443
+ // // make IE happy
2444
+ // jqLite(window.document.body).html(
2445
+ // '<a href="http://server/test.html">link</a>',
2446
+ // );
2447
+
2448
+ // const event = {
2449
+ // target: jqLite(window.document.body).find("a")[0],
2450
+ // preventDefault: jasmine.createSpy("preventDefault"),
2451
+ // isDefaultPrevented: jasmine.createSpy().and.returnValue(false),
2452
+ // };
2453
+
2454
+ // clickHandler(event);
2455
+ // expect(event.preventDefault).not.toHaveBeenCalled();
2456
+ // });
2457
+ // });
2458
+
2459
+ // it("should not intercept hash link clicks outside the app base url space", () => {
2460
+ // let base;
2461
+ // let clickHandler;
2462
+ // module(($provide) => {
2463
+ // $provide.value("$rootElement", {
2464
+ // on(event, handler) {
2465
+ // expect(event).toEqual("click");
2466
+ // clickHandler = handler;
2467
+ // },
2468
+ // off: () => {},
2469
+ // });
2470
+ // return function ($browser) {
2471
+ // $browser.url((base = "http://server/"));
2472
+ // };
2473
+ // });
2474
+ // inject(
2475
+ // (
2476
+ // $rootScope,
2477
+ // $compile,
2478
+ // $browser,
2479
+ // $rootElement,
2480
+ // $document,
2481
+ // $location,
2482
+ // ) => {
2483
+ // // make IE happy
2484
+ // jqLite(window.document.body).html(
2485
+ // '<a href="http://server/index.html#test">link</a>',
2486
+ // );
2487
+
2488
+ // const event = {
2489
+ // target: jqLite(window.document.body).find("a")[0],
2490
+ // preventDefault: jasmine.createSpy("preventDefault"),
2491
+ // isDefaultPrevented: jasmine.createSpy().and.returnValue(false),
2492
+ // };
2493
+
2494
+ // clickHandler(event);
2495
+ // expect(event.preventDefault).not.toHaveBeenCalled();
2496
+ // },
2497
+ // );
2498
+ // });
2499
+
2500
+ // // regression https://github.com/angular/angular.js/issues/1058
2501
+ // it("should not throw if element was removed", inject((
2502
+ // $document,
2503
+ // $rootElement,
2504
+ // $location,
2505
+ // ) => {
2506
+ // // we need to do this otherwise we can't simulate events
2507
+ // $document.find("body").append($rootElement);
2508
+
2509
+ // $rootElement.html("<button></button>");
2510
+ // const button = $rootElement.find("button");
2511
+
2512
+ // button.on("click", () => {
2513
+ // button.remove();
2514
+ // });
2515
+ // browserTrigger(button, "click");
2516
+ // }));
2517
+
2518
+ // it("should not throw when clicking an SVGAElement link", () => {
2519
+ // let base;
2520
+ // module(
2521
+ // ($locationProvider) =>
2522
+ // function ($browser) {
2523
+ // window.location.hash = "!someHash";
2524
+ // $browser.url((base = window.location.href));
2525
+ // base = base.split("#")[0];
2526
+ // $locationProvider.hashPrefix("!");
2527
+ // },
2528
+ // );
2529
+ // inject(
2530
+ // (
2531
+ // $rootScope,
2532
+ // $compile,
2533
+ // $browser,
2534
+ // $rootElement,
2535
+ // $document,
2536
+ // $location,
2537
+ // ) => {
2538
+ // // we need to do this otherwise we can't simulate events
2539
+ // $document.find("body").append($rootElement);
2540
+ // const template =
2541
+ // '<svg><g><a xlink:href="#!/view1"><circle r="50"></circle></a></g></svg>';
2542
+ // const element = $compile(template)($rootScope);
2543
+
2544
+ // $rootElement.append(element);
2545
+ // const av1 = $rootElement.find("a").eq(0);
2546
+ // expect(() => {
2547
+ // browserTrigger(av1, "click");
2548
+ // }).not.toThrow();
2549
+ // },
2550
+ // );
2551
+ // });
2552
+ // });
2553
+
2554
+ // describe("location cancellation", () => {
2555
+ // it("should fire $before/afterLocationChange event", inject((
2556
+ // $location,
2557
+ // $browser,
2558
+ // $rootScope,
2559
+ // $log,
2560
+ // ) => {
2561
+ // expect($browser.url()).toEqual("http://server/");
2562
+
2563
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2564
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2565
+ // });
2566
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2567
+ // $log.info("after", newUrl, oldUrl, $browser.url());
2568
+ // });
2569
+
2570
+ // expect($location.url()).toEqual("");
2571
+ // $location.url("/somePath");
2572
+ // expect($location.url()).toEqual("/somePath");
2573
+ // expect($browser.url()).toEqual("http://server/");
2574
+ // expect($log.info.logs).toEqual([]);
2575
+
2576
+ // $rootScope.$apply();
2577
+
2578
+ // expect($log.info.logs.shift()).toEqual([
2579
+ // "before",
2580
+ // "http://server/#!/somePath",
2581
+ // "http://server/",
2582
+ // "http://server/",
2583
+ // ]);
2584
+ // expect($log.info.logs.shift()).toEqual([
2585
+ // "after",
2586
+ // "http://server/#!/somePath",
2587
+ // "http://server/",
2588
+ // "http://server/#!/somePath",
2589
+ // ]);
2590
+ // expect($location.url()).toEqual("/somePath");
2591
+ // expect($browser.url()).toEqual("http://server/#!/somePath");
2592
+ // }));
2593
+
2594
+ // it("should allow $locationChangeStart event cancellation", inject((
2595
+ // $location,
2596
+ // $browser,
2597
+ // $rootScope,
2598
+ // $log,
2599
+ // ) => {
2600
+ // expect($browser.url()).toEqual("http://server/");
2601
+ // expect($location.url()).toEqual("");
2602
+
2603
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2604
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2605
+ // event.preventDefault();
2606
+ // });
2607
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2608
+ // throw new Error("location should have been canceled");
2609
+ // });
2610
+
2611
+ // expect($location.url()).toEqual("");
2612
+ // $location.url("/somePath");
2613
+ // expect($location.url()).toEqual("/somePath");
2614
+ // expect($browser.url()).toEqual("http://server/");
2615
+ // expect($log.info.logs).toEqual([]);
2616
+
2617
+ // $rootScope.$apply();
2618
+
2619
+ // expect($log.info.logs.shift()).toEqual([
2620
+ // "before",
2621
+ // "http://server/#!/somePath",
2622
+ // "http://server/",
2623
+ // "http://server/",
2624
+ // ]);
2625
+ // expect($log.info.logs[1]).toBeUndefined();
2626
+ // expect($location.url()).toEqual("");
2627
+ // expect($browser.url()).toEqual("http://server/");
2628
+ // }));
2629
+
2630
+ // it("should allow redirect during $locationChangeStart", inject((
2631
+ // $location,
2632
+ // $browser,
2633
+ // $rootScope,
2634
+ // $log,
2635
+ // ) => {
2636
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2637
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2638
+ // if (newUrl === "http://server/#!/somePath") {
2639
+ // $location.url("/redirectPath");
2640
+ // }
2641
+ // });
2642
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2643
+ // $log.info("after", newUrl, oldUrl, $browser.url());
2644
+ // });
2645
+
2646
+ // $location.url("/somePath");
2647
+ // $rootScope.$apply();
2648
+
2649
+ // expect($log.info.logs.shift()).toEqual([
2650
+ // "before",
2651
+ // "http://server/#!/somePath",
2652
+ // "http://server/",
2653
+ // "http://server/",
2654
+ // ]);
2655
+ // expect($log.info.logs.shift()).toEqual([
2656
+ // "before",
2657
+ // "http://server/#!/redirectPath",
2658
+ // "http://server/",
2659
+ // "http://server/",
2660
+ // ]);
2661
+ // expect($log.info.logs.shift()).toEqual([
2662
+ // "after",
2663
+ // "http://server/#!/redirectPath",
2664
+ // "http://server/",
2665
+ // "http://server/#!/redirectPath",
2666
+ // ]);
2667
+
2668
+ // expect($location.url()).toEqual("/redirectPath");
2669
+ // expect($browser.url()).toEqual("http://server/#!/redirectPath");
2670
+ // }));
2671
+
2672
+ // it("should allow redirect during $locationChangeStart even if default prevented", inject((
2673
+ // $location,
2674
+ // $browser,
2675
+ // $rootScope,
2676
+ // $log,
2677
+ // ) => {
2678
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2679
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2680
+ // if (newUrl === "http://server/#!/somePath") {
2681
+ // event.preventDefault();
2682
+ // $location.url("/redirectPath");
2683
+ // }
2684
+ // });
2685
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2686
+ // $log.info("after", newUrl, oldUrl, $browser.url());
2687
+ // });
2688
+
2689
+ // $location.url("/somePath");
2690
+ // $rootScope.$apply();
2691
+
2692
+ // expect($log.info.logs.shift()).toEqual([
2693
+ // "before",
2694
+ // "http://server/#!/somePath",
2695
+ // "http://server/",
2696
+ // "http://server/",
2697
+ // ]);
2698
+ // expect($log.info.logs.shift()).toEqual([
2699
+ // "before",
2700
+ // "http://server/#!/redirectPath",
2701
+ // "http://server/",
2702
+ // "http://server/",
2703
+ // ]);
2704
+ // expect($log.info.logs.shift()).toEqual([
2705
+ // "after",
2706
+ // "http://server/#!/redirectPath",
2707
+ // "http://server/",
2708
+ // "http://server/#!/redirectPath",
2709
+ // ]);
2710
+
2711
+ // expect($location.url()).toEqual("/redirectPath");
2712
+ // expect($browser.url()).toEqual("http://server/#!/redirectPath");
2713
+ // }));
2714
+
2715
+ // it("should allow multiple redirect during $locationChangeStart", inject((
2716
+ // $location,
2717
+ // $browser,
2718
+ // $rootScope,
2719
+ // $log,
2720
+ // ) => {
2721
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2722
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2723
+ // if (newUrl === "http://server/#!/somePath") {
2724
+ // $location.url("/redirectPath");
2725
+ // } else if (newUrl === "http://server/#!/redirectPath") {
2726
+ // $location.url("/redirectPath2");
2727
+ // }
2728
+ // });
2729
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2730
+ // $log.info("after", newUrl, oldUrl, $browser.url());
2731
+ // });
2732
+
2733
+ // $location.url("/somePath");
2734
+ // $rootScope.$apply();
2735
+
2736
+ // expect($log.info.logs.shift()).toEqual([
2737
+ // "before",
2738
+ // "http://server/#!/somePath",
2739
+ // "http://server/",
2740
+ // "http://server/",
2741
+ // ]);
2742
+ // expect($log.info.logs.shift()).toEqual([
2743
+ // "before",
2744
+ // "http://server/#!/redirectPath",
2745
+ // "http://server/",
2746
+ // "http://server/",
2747
+ // ]);
2748
+ // expect($log.info.logs.shift()).toEqual([
2749
+ // "before",
2750
+ // "http://server/#!/redirectPath2",
2751
+ // "http://server/",
2752
+ // "http://server/",
2753
+ // ]);
2754
+ // expect($log.info.logs.shift()).toEqual([
2755
+ // "after",
2756
+ // "http://server/#!/redirectPath2",
2757
+ // "http://server/",
2758
+ // "http://server/#!/redirectPath2",
2759
+ // ]);
2760
+
2761
+ // expect($location.url()).toEqual("/redirectPath2");
2762
+ // expect($browser.url()).toEqual("http://server/#!/redirectPath2");
2763
+ // }));
2764
+
2765
+ // it("should fire $locationChangeSuccess event when change from browser location bar", inject((
2766
+ // $log,
2767
+ // $location,
2768
+ // $browser,
2769
+ // $rootScope,
2770
+ // ) => {
2771
+ // $rootScope.$apply(); // clear initial $locationChangeStart
2772
+
2773
+ // expect($browser.url()).toEqual("http://server/");
2774
+ // expect($location.url()).toEqual("");
2775
+
2776
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2777
+ // $log.info("start", newUrl, oldUrl);
2778
+ // });
2779
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2780
+ // $log.info("after", newUrl, oldUrl);
2781
+ // });
2782
+
2783
+ // $browser.url("http://server/#!/somePath");
2784
+ // $browser.poll();
2785
+
2786
+ // expect($log.info.logs.shift()).toEqual([
2787
+ // "start",
2788
+ // "http://server/#!/somePath",
2789
+ // "http://server/",
2790
+ // ]);
2791
+ // expect($log.info.logs.shift()).toEqual([
2792
+ // "after",
2793
+ // "http://server/#!/somePath",
2794
+ // "http://server/",
2795
+ // ]);
2796
+ // }));
2797
+
2798
+ // it("should fire $locationChangeSuccess when browser location changes to URL which ends with #", inject((
2799
+ // $location,
2800
+ // $browser,
2801
+ // $rootScope,
2802
+ // $log,
2803
+ // ) => {
2804
+ // $location.url("/somepath");
2805
+ // $rootScope.$apply();
2806
+
2807
+ // expect($browser.url()).toEqual("http://server/#!/somepath");
2808
+ // expect($location.url()).toEqual("/somepath");
2809
+
2810
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2811
+ // $log.info("start", newUrl, oldUrl);
2812
+ // });
2813
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2814
+ // $log.info("after", newUrl, oldUrl);
2815
+ // });
2816
+
2817
+ // $browser.url("http://server/#");
2818
+ // $browser.poll();
2819
+
2820
+ // expect($log.info.logs.shift()).toEqual([
2821
+ // "start",
2822
+ // "http://server/",
2823
+ // "http://server/#!/somepath",
2824
+ // ]);
2825
+ // expect($log.info.logs.shift()).toEqual([
2826
+ // "after",
2827
+ // "http://server/",
2828
+ // "http://server/#!/somepath",
2829
+ // ]);
2830
+ // }));
2831
+
2832
+ // it("should allow redirect during browser url change", inject((
2833
+ // $location,
2834
+ // $browser,
2835
+ // $rootScope,
2836
+ // $log,
2837
+ // ) => {
2838
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2839
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2840
+ // if (newUrl === "http://server/#!/somePath") {
2841
+ // $location.url("/redirectPath");
2842
+ // }
2843
+ // });
2844
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2845
+ // $log.info("after", newUrl, oldUrl, $browser.url());
2846
+ // });
2847
+
2848
+ // $browser.url("http://server/#!/somePath");
2849
+ // $browser.poll();
2850
+
2851
+ // expect($log.info.logs.shift()).toEqual([
2852
+ // "before",
2853
+ // "http://server/#!/somePath",
2854
+ // "http://server/",
2855
+ // "http://server/#!/somePath",
2856
+ // ]);
2857
+ // expect($log.info.logs.shift()).toEqual([
2858
+ // "before",
2859
+ // "http://server/#!/redirectPath",
2860
+ // "http://server/#!/somePath",
2861
+ // "http://server/#!/somePath",
2862
+ // ]);
2863
+ // expect($log.info.logs.shift()).toEqual([
2864
+ // "after",
2865
+ // "http://server/#!/redirectPath",
2866
+ // "http://server/#!/somePath",
2867
+ // "http://server/#!/redirectPath",
2868
+ // ]);
2869
+
2870
+ // expect($location.url()).toEqual("/redirectPath");
2871
+ // expect($browser.url()).toEqual("http://server/#!/redirectPath");
2872
+ // }));
2873
+
2874
+ // it("should allow redirect during browser url change even if default prevented", inject((
2875
+ // $location,
2876
+ // $browser,
2877
+ // $rootScope,
2878
+ // $log,
2879
+ // ) => {
2880
+ // $rootScope.$on("$locationChangeStart", (event, newUrl, oldUrl) => {
2881
+ // $log.info("before", newUrl, oldUrl, $browser.url());
2882
+ // if (newUrl === "http://server/#!/somePath") {
2883
+ // event.preventDefault();
2884
+ // $location.url("/redirectPath");
2885
+ // }
2886
+ // });
2887
+ // $rootScope.$on("$locationChangeSuccess", (event, newUrl, oldUrl) => {
2888
+ // $log.info("after", newUrl, oldUrl, $browser.url());
2889
+ // });
2890
+
2891
+ // $browser.url("http://server/#!/somePath");
2892
+ // $browser.poll();
2893
+
2894
+ // expect($log.info.logs.shift()).toEqual([
2895
+ // "before",
2896
+ // "http://server/#!/somePath",
2897
+ // "http://server/",
2898
+ // "http://server/#!/somePath",
2899
+ // ]);
2900
+ // expect($log.info.logs.shift()).toEqual([
2901
+ // "before",
2902
+ // "http://server/#!/redirectPath",
2903
+ // "http://server/#!/somePath",
2904
+ // "http://server/#!/somePath",
2905
+ // ]);
2906
+ // expect($log.info.logs.shift()).toEqual([
2907
+ // "after",
2908
+ // "http://server/#!/redirectPath",
2909
+ // "http://server/#!/somePath",
2910
+ // "http://server/#!/redirectPath",
2911
+ // ]);
2912
+
2913
+ // expect($location.url()).toEqual("/redirectPath");
2914
+ // expect($browser.url()).toEqual("http://server/#!/redirectPath");
2915
+ // }));
2916
+
2917
+ // it("should listen on click events on href and prevent browser default in hashbang mode", () => {
2918
+ // module(
2919
+ // () =>
2920
+ // function ($rootElement, $compile, $rootScope) {
2921
+ // $rootElement.html('<a href="http://server/#!/somePath">link</a>');
2922
+ // $compile($rootElement)($rootScope);
2923
+ // jqLite(window.document.body).append($rootElement);
2924
+ // },
2925
+ // );
2926
+
2927
+ // inject(($location, $rootScope, $browser, $rootElement) => {
2928
+ // let log = "";
2929
+ // const link = $rootElement.find("a");
2930
+
2931
+ // $rootScope.$on("$locationChangeStart", (event) => {
2932
+ // event.preventDefault();
2933
+ // log += "$locationChangeStart";
2934
+ // });
2935
+ // $rootScope.$on("$locationChangeSuccess", () => {
2936
+ // throw new Error("after cancellation in hashbang mode");
2937
+ // });
2938
+
2939
+ // browserTrigger(link, "click");
2940
+
2941
+ // expect(log).toEqual("$locationChangeStart");
2942
+ // expect($browser.url()).toEqual("http://server/");
2943
+
2944
+ // dealoc($rootElement);
2945
+ // });
2946
+ // });
2947
+
2948
+ // it("should listen on click events on href and prevent browser default in html5 mode", () => {
2949
+ // module(($locationProvider, $provide) => {
2950
+ // $locationProvider.html5Mode(true);
2951
+ // return function ($rootElement, $compile, $rootScope) {
2952
+ // $rootElement.html('<a href="http://server/somePath">link</a>');
2953
+ // $compile($rootElement)($rootScope);
2954
+ // jqLite(window.document.body).append($rootElement);
2955
+ // };
2956
+ // });
2957
+
2958
+ // inject(($location, $rootScope, $browser, $rootElement) => {
2959
+ // let log = "";
2960
+ // const link = $rootElement.find("a");
2961
+ // const browserUrlBefore = $browser.url();
2962
+
2963
+ // $rootScope.$on("$locationChangeStart", (event) => {
2964
+ // event.preventDefault();
2965
+ // log += "$locationChangeStart";
2966
+ // });
2967
+ // $rootScope.$on("$locationChangeSuccess", () => {
2968
+ // throw new Error("after cancellation in html5 mode");
2969
+ // });
2970
+
2971
+ // browserTrigger(link, "click");
2972
+
2973
+ // expect(log).toEqual("$locationChangeStart");
2974
+ // expect($browser.url()).toBe(browserUrlBefore);
2975
+
2976
+ // dealoc($rootElement);
2977
+ // });
2978
+ // });
2979
+
2980
+ // it("should always return the new url value via path() when $locationChangeStart event occurs regardless of cause", inject((
2981
+ // $location,
2982
+ // $rootScope,
2983
+ // $browser,
2984
+ // log,
2985
+ // ) => {
2986
+ // const base = $browser.url();
2987
+
2988
+ // $rootScope.$on("$locationChangeStart", () => {
2989
+ // log($location.path());
2990
+ // });
2991
+
2992
+ // // change through $location service
2993
+ // $rootScope.$apply(() => {
2994
+ // $location.path("/myNewPath");
2995
+ // });
2996
+
2997
+ // // reset location
2998
+ // $rootScope.$apply(() => {
2999
+ // $location.path("");
3000
+ // });
3001
+
3002
+ // // change through $browser
3003
+ // $browser.url(`${base}#!/myNewPath`);
3004
+ // $browser.poll();
3005
+
3006
+ // expect(log).toEqual(["/myNewPath", "/", "/myNewPath"]);
3007
+ // }));
3008
+ // });
3009
+
3010
+ describe("$locationProvider", () => {
3011
+ describe("html5Mode", () => {
3012
+ it("should set enabled, requireBase and rewriteLinks when called with object", () => {
3013
+ module.config(($locationProvider) => {
3014
+ $locationProvider.html5Mode({
3015
+ enabled: true,
3016
+ requireBase: false,
3017
+ rewriteLinks: false,
3018
+ });
3019
+ expect($locationProvider.html5Mode()).toEqual({
3020
+ enabled: true,
3021
+ requireBase: false,
3022
+ rewriteLinks: false,
3023
+ });
3024
+ });
3025
+ createInjector(["test1"]);
3026
+ });
3027
+
3028
+ it("should only overwrite existing properties if values are of the correct type", () => {
3029
+ module.config(($locationProvider) => {
3030
+ $locationProvider.html5Mode({
3031
+ enabled: "duh",
3032
+ requireBase: "probably",
3033
+ rewriteLinks: 0,
3034
+ });
3035
+
3036
+ expect($locationProvider.html5Mode()).toEqual({
3037
+ enabled: false,
3038
+ requireBase: true,
3039
+ rewriteLinks: true,
3040
+ });
3041
+ });
3042
+
3043
+ createInjector(["test1"]);
3044
+ });
3045
+
3046
+ it("should support setting rewriteLinks to a string", () => {
3047
+ module.config(($locationProvider) => {
3048
+ $locationProvider.html5Mode({
3049
+ rewriteLinks: "yes-rewrite",
3050
+ });
3051
+
3052
+ expect($locationProvider.html5Mode().rewriteLinks).toEqual(
3053
+ "yes-rewrite",
3054
+ );
3055
+ });
3056
+
3057
+ createInjector(["test1"]);
3058
+ });
3059
+
3060
+ it("should not set unknown input properties to html5Mode object", () => {
3061
+ module.config(($locationProvider) => {
3062
+ $locationProvider.html5Mode({
3063
+ someProp: "foo",
3064
+ });
3065
+
3066
+ expect($locationProvider.html5Mode()).toEqual({
3067
+ enabled: false,
3068
+ requireBase: true,
3069
+ rewriteLinks: true,
3070
+ });
3071
+ });
3072
+
3073
+ createInjector(["test1"]);
3074
+ });
3075
+
3076
+ it("should default to enabled:false, requireBase:true and rewriteLinks:true", () => {
3077
+ module.config(($locationProvider) => {
3078
+ expect($locationProvider.html5Mode()).toEqual({
3079
+ enabled: false,
3080
+ requireBase: true,
3081
+ rewriteLinks: true,
3082
+ });
3083
+ });
3084
+
3085
+ createInjector(["test1"]);
3086
+ });
3087
+ });
3088
+ });
3089
+
3090
+ describe("LocationHtml5Url", () => {
3091
+ let locationUrl;
3092
+ let locationUmlautUrl;
3093
+ let locationIndexUrl;
3094
+
3095
+ beforeEach(() => {
3096
+ locationUrl = new LocationHtml5Url(
3097
+ "http://server/pre/",
3098
+ "http://server/pre/",
3099
+ );
3100
+ locationUmlautUrl = new LocationHtml5Url(
3101
+ "http://särver/pre/",
3102
+ "http://särver/pre/",
3103
+ );
3104
+ locationIndexUrl = new LocationHtml5Url(
3105
+ "http://server/pre/index.html",
3106
+ "http://server/pre/",
3107
+ );
3108
+ });
3109
+
3110
+ it("should rewrite URL", () => {
3111
+ expect(parseLinkAndReturn(locationUrl, "http://other")).toEqual(
3112
+ undefined,
3113
+ );
3114
+ expect(parseLinkAndReturn(locationUrl, "http://server/pre")).toEqual(
3115
+ "http://server/pre/",
3116
+ );
3117
+ expect(parseLinkAndReturn(locationUrl, "http://server/pre/")).toEqual(
3118
+ "http://server/pre/",
3119
+ );
3120
+ expect(
3121
+ parseLinkAndReturn(locationUrl, "http://server/pre/otherPath"),
3122
+ ).toEqual("http://server/pre/otherPath");
3123
+ // Note: relies on the previous state!
3124
+ expect(
3125
+ parseLinkAndReturn(locationUrl, "someIgnoredAbsoluteHref", "#test"),
3126
+ ).toEqual("http://server/pre/otherPath#test");
3127
+
3128
+ expect(parseLinkAndReturn(locationUmlautUrl, "http://other")).toEqual(
3129
+ undefined,
3130
+ );
3131
+ expect(
3132
+ parseLinkAndReturn(locationUmlautUrl, "http://särver/pre"),
3133
+ ).toEqual("http://särver/pre/");
3134
+ expect(
3135
+ parseLinkAndReturn(locationUmlautUrl, "http://särver/pre/"),
3136
+ ).toEqual("http://särver/pre/");
3137
+ expect(
3138
+ parseLinkAndReturn(locationUmlautUrl, "http://särver/pre/otherPath"),
3139
+ ).toEqual("http://särver/pre/otherPath");
3140
+ // Note: relies on the previous state!
3141
+ expect(
3142
+ parseLinkAndReturn(
3143
+ locationUmlautUrl,
3144
+ "someIgnoredAbsoluteHref",
3145
+ "#test",
3146
+ ),
3147
+ ).toEqual("http://särver/pre/otherPath#test");
3148
+
3149
+ expect(parseLinkAndReturn(locationIndexUrl, "http://server/pre")).toEqual(
3150
+ "http://server/pre/",
3151
+ );
3152
+ expect(
3153
+ parseLinkAndReturn(locationIndexUrl, "http://server/pre/"),
3154
+ ).toEqual("http://server/pre/");
3155
+ expect(
3156
+ parseLinkAndReturn(locationIndexUrl, "http://server/pre/otherPath"),
3157
+ ).toEqual("http://server/pre/otherPath");
3158
+ // Note: relies on the previous state!
3159
+ expect(
3160
+ parseLinkAndReturn(locationUrl, "someIgnoredAbsoluteHref", "#test"),
3161
+ ).toEqual("http://server/pre/otherPath#test");
3162
+ });
3163
+
3164
+ it("should complain if the path starts with double slashes", () => {
3165
+ expect(() => {
3166
+ parseLinkAndReturn(locationUrl, "http://server/pre///other/path");
3167
+ }).toThrowError(/badpath/);
3168
+
3169
+ expect(() => {
3170
+ parseLinkAndReturn(locationUrl, "http://server/pre/\\\\other/path");
3171
+ }).toThrowError(/badpath/);
3172
+
3173
+ expect(() => {
3174
+ parseLinkAndReturn(locationUrl, "http://server/pre//\\//other/path");
3175
+ }).toThrowError(/badpath/);
3176
+ });
3177
+
3178
+ // it("should complain if no base tag present", () => {
3179
+ // let module = window.angular.module("test1", ["ng"]);
3180
+ // module.config((_$locationProvider_) => {
3181
+ // $locationProvider.html5Mode(true);
3182
+ // });
3183
+
3184
+ // createInjector(["test1"]).invoke(($browser, $injector) => {
3185
+ // $browser.$$baseHref = undefined;
3186
+ // expect(() => {
3187
+ // $injector.get("$location");
3188
+ // }).toThrowError(/nobase/);
3189
+ // });
3190
+ // });
3191
+
3192
+ // it("should not complain if baseOptOut set to true in html5Mode", () => {
3193
+ // module.config(($locationProvider) => {
3194
+ // $locationProvider.html5Mode({
3195
+ // enabled: true,
3196
+ // requireBase: false,
3197
+ // });
3198
+ // });
3199
+
3200
+ // inject(($browser, $injector) => {
3201
+ // $browser.$$baseHref = undefined;
3202
+ // expect(() => {
3203
+ // $injector.get("$location");
3204
+ // }).not.toThrow(
3205
+ // "$location",
3206
+ // "nobase",
3207
+ // "$location in HTML5 mode requires a <base> tag to be present!",
3208
+ // );
3209
+ // });
3210
+ // });
3211
+
3212
+ it("should support state", () => {
3213
+ expect(locationUrl.state({ a: 2 }).state()).toEqual({ a: 2 });
3214
+ });
3215
+ });
3216
+
3217
+ describe("LocationHashbangUrl", () => {
3218
+ let locationUrl;
3219
+
3220
+ it("should rewrite URL", () => {
3221
+ locationUrl = new LocationHashbangUrl(
3222
+ "http://server/pre/",
3223
+ "http://server/pre/",
3224
+ "#",
3225
+ );
3226
+
3227
+ expect(parseLinkAndReturn(locationUrl, "http://other")).toEqual(
3228
+ undefined,
3229
+ );
3230
+ expect(parseLinkAndReturn(locationUrl, "http://server/pre/")).toEqual(
3231
+ "http://server/pre/",
3232
+ );
3233
+ expect(
3234
+ parseLinkAndReturn(locationUrl, "http://server/pre/#otherPath"),
3235
+ ).toEqual("http://server/pre/#/otherPath");
3236
+ // eslint-disable-next-line no-script-url
3237
+ expect(parseLinkAndReturn(locationUrl, "javascript:void(0)")).toEqual(
3238
+ undefined,
3239
+ );
3240
+ });
3241
+
3242
+ it("should not set hash if one was not originally specified", () => {
3243
+ locationUrl = new LocationHashbangUrl(
3244
+ "http://server/pre/index.html",
3245
+ "http://server/pre/",
3246
+ "#",
3247
+ );
3248
+
3249
+ locationUrl.$$parse("http://server/pre/index.html");
3250
+ expect(locationUrl.url()).toBe("");
3251
+ expect(locationUrl.absUrl()).toBe("http://server/pre/index.html");
3252
+ });
3253
+
3254
+ it("should parse hash if one was specified", () => {
3255
+ locationUrl = new LocationHashbangUrl(
3256
+ "http://server/pre/index.html",
3257
+ "http://server/pre/",
3258
+ "#",
3259
+ );
3260
+
3261
+ locationUrl.$$parse("http://server/pre/index.html#/foo/bar");
3262
+ expect(locationUrl.url()).toBe("/foo/bar");
3263
+ expect(locationUrl.absUrl()).toBe(
3264
+ "http://server/pre/index.html#/foo/bar",
3265
+ );
3266
+ });
3267
+
3268
+ it("should prefix hash url with / if one was originally missing", () => {
3269
+ locationUrl = new LocationHashbangUrl(
3270
+ "http://server/pre/index.html",
3271
+ "http://server/pre/",
3272
+ "#",
3273
+ );
3274
+
3275
+ locationUrl.$$parse(
3276
+ "http://server/pre/index.html#not-starting-with-slash",
3277
+ );
3278
+ expect(locationUrl.url()).toBe("/not-starting-with-slash");
3279
+ expect(locationUrl.absUrl()).toBe(
3280
+ "http://server/pre/index.html#/not-starting-with-slash",
3281
+ );
3282
+ });
3283
+
3284
+ it("should not strip stuff from path just because it looks like Windows drive when it's not", () => {
3285
+ locationUrl = new LocationHashbangUrl(
3286
+ "http://server/pre/index.html",
3287
+ "http://server/pre/",
3288
+ "#",
3289
+ );
3290
+
3291
+ locationUrl.$$parse(
3292
+ "http://server/pre/index.html#http%3A%2F%2Fexample.com%2F",
3293
+ );
3294
+ expect(locationUrl.url()).toBe("/http://example.com/");
3295
+ expect(locationUrl.absUrl()).toBe(
3296
+ "http://server/pre/index.html#/http://example.com/",
3297
+ );
3298
+ });
3299
+
3300
+ it("should throw on url(urlString, stateObject)", () => {
3301
+ expectThrowOnStateChange(locationUrl);
3302
+ });
3303
+
3304
+ it("should allow navigating outside the original base URL", () => {
3305
+ locationUrl = new LocationHashbangUrl(
3306
+ "http://server/pre/index.html",
3307
+ "http://server/pre/",
3308
+ "#",
3309
+ );
3310
+
3311
+ locationUrl.$$parse("http://server/next/index.html");
3312
+ expect(locationUrl.url()).toBe("");
3313
+ expect(locationUrl.absUrl()).toBe("http://server/next/index.html");
3314
+ });
3315
+ });
3316
+
3317
+ describe("LocationHashbangInHtml5Url", () => {
3318
+ /* global LocationHashbangInHtml5Url: false */
3319
+ let locationUrl;
3320
+ let locationIndexUrl;
3321
+
3322
+ beforeEach(() => {
3323
+ locationUrl = new LocationHashbangInHtml5Url(
3324
+ "http://server/pre/",
3325
+ "http://server/pre/",
3326
+ "#!",
3327
+ );
3328
+ locationIndexUrl = new LocationHashbangInHtml5Url(
3329
+ "http://server/pre/index.html",
3330
+ "http://server/pre/",
3331
+ "#!",
3332
+ );
3333
+ });
3334
+
3335
+ it("should rewrite URL", () => {
3336
+ expect(parseLinkAndReturn(locationUrl, "http://other")).toEqual(
3337
+ undefined,
3338
+ );
3339
+ expect(parseLinkAndReturn(locationUrl, "http://server/pre")).toEqual(
3340
+ "http://server/pre/#!",
3341
+ );
3342
+ expect(parseLinkAndReturn(locationUrl, "http://server/pre/")).toEqual(
3343
+ "http://server/pre/#!",
3344
+ );
3345
+ expect(
3346
+ parseLinkAndReturn(locationUrl, "http://server/pre/otherPath"),
3347
+ ).toEqual("http://server/pre/#!/otherPath");
3348
+ // Note: relies on the previous state!
3349
+ expect(
3350
+ parseLinkAndReturn(locationUrl, "someIgnoredAbsoluteHref", "#test"),
3351
+ ).toEqual("http://server/pre/#!/otherPath#test");
3352
+
3353
+ expect(parseLinkAndReturn(locationIndexUrl, "http://server/pre")).toEqual(
3354
+ "http://server/pre/index.html#!",
3355
+ );
3356
+ expect(
3357
+ parseLinkAndReturn(locationIndexUrl, "http://server/pre/"),
3358
+ ).toEqual(undefined);
3359
+ expect(
3360
+ parseLinkAndReturn(locationIndexUrl, "http://server/pre/otherPath"),
3361
+ ).toEqual("http://server/pre/index.html#!/otherPath");
3362
+ // Note: relies on the previous state!
3363
+ expect(
3364
+ parseLinkAndReturn(
3365
+ locationIndexUrl,
3366
+ "someIgnoredAbsoluteHref",
3367
+ "#test",
3368
+ ),
3369
+ ).toEqual("http://server/pre/index.html#!/otherPath#test");
3370
+ });
3371
+
3372
+ it("should throw on url(urlString, stateObject)", () => {
3373
+ expectThrowOnStateChange(locationUrl);
3374
+ });
3375
+
3376
+ // it("should not throw when base path is another domain", () => {
3377
+ // initService({ html5Mode: true, hashPrefix: "!", supportHistory: true });
3378
+ // inject(
3379
+ // initBrowser({
3380
+ // url: "http://domain.com/base/",
3381
+ // basePath: "http://otherdomain.com/base/",
3382
+ // }),
3383
+ // ($location) => {
3384
+ // expect(() => {
3385
+ // $location.absUrl();
3386
+ // }).not.toThrow();
3387
+ // },
3388
+ // );
3389
+ // });
3390
+ });
3391
+
3392
+ // function mockUpBrowser(options) {
3393
+ // module(($windowProvider, $browserProvider) => {
3394
+ // let browser;
3395
+ // const parser = window.document.createElement("a");
3396
+ // parser.href = options.initialUrl;
3397
+
3398
+ // $windowProvider.$get = function () {
3399
+ // const win = {};
3400
+ // angular.extend(win, window);
3401
+ // // Ensure `window` is a reference to the mock global object, so that
3402
+ // // jqLite does the right thing.
3403
+ // win.window = win;
3404
+ // win.history = {
3405
+ // state: options.state || null,
3406
+ // replaceState(state, title, url) {
3407
+ // win.history.state = copy(state);
3408
+ // if (url) win.location.href = url;
3409
+ // },
3410
+ // pushState(state, title, url) {
3411
+ // win.history.state = copy(state);
3412
+ // if (url) win.location.href = url;
3413
+ // },
3414
+ // };
3415
+ // win.addEventListener = () => {};
3416
+ // win.removeEventListener = () => {};
3417
+ // win.location = {
3418
+ // get href() {
3419
+ // return this.$$getHref();
3420
+ // },
3421
+ // $$getHref() {
3422
+ // return parser.href;
3423
+ // },
3424
+ // set href(val) {
3425
+ // this.$$setHref(val);
3426
+ // },
3427
+ // $$setHref(val) {
3428
+ // parser.href = val;
3429
+ // },
3430
+ // get hash() {
3431
+ // return parser.hash;
3432
+ // },
3433
+ // // The parser correctly strips on a single preceding hash character if necessary
3434
+ // // before joining the fragment onto the href by a new hash character
3435
+ // // See hash setter spec: https://url.spec.whatwg.org/#urlutils-and-urlutilsreadonly-members
3436
+ // set hash(val) {
3437
+ // parser.hash = val;
3438
+ // },
3439
+
3440
+ // replace(val) {
3441
+ // win.location.href = val;
3442
+ // },
3443
+ // };
3444
+ // return win;
3445
+ // };
3446
+ // $browserProvider.$get = function (
3447
+ // $document,
3448
+ // $window,
3449
+ // $log,
3450
+ // $sniffer,
3451
+ // $$taskTrackerFactory,
3452
+ // ) {
3453
+ // /* global Browser: false */
3454
+ // browser = new Browser(
3455
+ // $window,
3456
+ // $document,
3457
+ // $log,
3458
+ // $sniffer,
3459
+ // $$taskTrackerFactory,
3460
+ // );
3461
+ // browser.baseHref = function () {
3462
+ // return options.baseHref;
3463
+ // };
3464
+ // return browser;
3465
+ // };
3466
+ // });
3467
+ // }
3468
+
3469
+ function initBrowser(options) {
3470
+ return function ($browser) {
3471
+ $browser.url(options.url);
3472
+ $browser.$$baseHref = options.basePath;
3473
+ };
3474
+ }
3475
+
3476
+ function expectThrowOnStateChange(location) {
3477
+ expect(() => {
3478
+ location.state({ a: 2 });
3479
+ }).toThrowError(/nostate/);
3480
+ }
3481
+
3482
+ function parseLinkAndReturn(location, url, relHref) {
3483
+ if (location.$$parseLinkUrl(url, relHref)) {
3484
+ return location.absUrl();
3485
+ }
3486
+ return undefined;
3487
+ }
3488
+ });