@@ -118,221 +118,3 @@ describe('boolean attr directives', function() {
118
118
} ) ) ;
119
119
} ) ;
120
120
} ) ;
121
-
122
-
123
- describe ( 'ngSrc' , function ( ) {
124
- it ( 'should interpolate the expression and bind to src with raw same-domain value' ,
125
- inject ( function ( $compile , $rootScope ) {
126
- var element = $compile ( '<img ng-src="{{id}}"></img>' ) ( $rootScope ) ;
127
-
128
- $rootScope . $digest ( ) ;
129
- expect ( element . attr ( 'src' ) ) . toBeUndefined ( ) ;
130
-
131
- $rootScope . $apply ( function ( ) {
132
- $rootScope . id = '/somewhere/here' ;
133
- } ) ;
134
- expect ( element . attr ( 'src' ) ) . toEqual ( '/somewhere/here' ) ;
135
-
136
- dealoc ( element ) ;
137
- } ) ) ;
138
-
139
-
140
- it ( 'should interpolate the expression and bind to src with a trusted value' , inject ( function ( $compile , $rootScope , $sce ) {
141
- var element = $compile ( '<iframe ng-src="{{id}}"></iframe>' ) ( $rootScope ) ;
142
-
143
- $rootScope . $digest ( ) ;
144
- expect ( element . attr ( 'src' ) ) . toBeUndefined ( ) ;
145
-
146
- $rootScope . $apply ( function ( ) {
147
- $rootScope . id = $sce . trustAsResourceUrl ( 'http://somewhere' ) ;
148
- } ) ;
149
- expect ( element . attr ( 'src' ) ) . toEqual ( 'http://somewhere' ) ;
150
-
151
- dealoc ( element ) ;
152
- } ) ) ;
153
-
154
-
155
- it ( 'should NOT interpolate a multi-part expression in a `src` attribute that requires a non-MEDIA_URL context' , inject ( function ( $compile , $rootScope ) {
156
- expect ( function ( ) {
157
- var element = $compile ( '<iframe ng-src="some/{{id}}"></iframe>' ) ( $rootScope ) ;
158
- $rootScope . $apply ( function ( ) {
159
- $rootScope . id = 1 ;
160
- } ) ;
161
- dealoc ( element ) ;
162
- } ) . toThrowMinErr (
163
- '$interpolate' , 'noconcat' , 'Error while interpolating: some/{{id}}\nStrict ' +
164
- 'Contextual Escaping disallows interpolations that concatenate multiple expressions ' +
165
- 'when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce' ) ;
166
- } ) ) ;
167
-
168
- it ( 'should interpolate a multi-part expression for img src attribute (which requires the MEDIA_URL context)' , inject ( function ( $compile , $rootScope ) {
169
- var element = $compile ( '<img ng-src="some/{{id}}"></img>' ) ( $rootScope ) ;
170
- expect ( element . attr ( 'src' ) ) . toBe ( undefined ) ; // URL concatenations are all-or-nothing
171
- $rootScope . $apply ( function ( ) {
172
- $rootScope . id = 1 ;
173
- } ) ;
174
- expect ( element . attr ( 'src' ) ) . toEqual ( 'some/1' ) ;
175
- } ) ) ;
176
-
177
-
178
- it ( 'should interpolate a multi-part expression for regular attributes' , inject ( function ( $compile , $rootScope ) {
179
- var element = $compile ( '<div foo="some/{{id}}"></div>' ) ( $rootScope ) ;
180
- $rootScope . $digest ( ) ;
181
- expect ( element . attr ( 'foo' ) ) . toBe ( 'some/' ) ;
182
- $rootScope . $apply ( function ( ) {
183
- $rootScope . id = 1 ;
184
- } ) ;
185
- expect ( element . attr ( 'foo' ) ) . toEqual ( 'some/1' ) ;
186
- } ) ) ;
187
-
188
-
189
- it ( 'should NOT interpolate a wrongly typed expression' , inject ( function ( $compile , $rootScope , $sce ) {
190
- expect ( function ( ) {
191
- var element = $compile ( '<iframe ng-src="{{id}}"></iframe>' ) ( $rootScope ) ;
192
- $rootScope . $apply ( function ( ) {
193
- $rootScope . id = $sce . trustAsUrl ( 'http://somewhere' ) ;
194
- } ) ;
195
- element . attr ( 'src' ) ;
196
- } ) . toThrowMinErr (
197
- '$interpolate' , 'interr' , 'Can\'t interpolate: {{id}}\nError: [$sce:insecurl] Blocked ' +
198
- 'loading resource from url not allowed by $sceDelegate policy. URL: http://somewhere' ) ;
199
- } ) ) ;
200
-
201
-
202
- // Support: IE 9-11 only
203
- if ( msie ) {
204
- it ( 'should update the element property as well as the attribute' , inject (
205
- function ( $compile , $rootScope , $sce ) {
206
- // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
207
- // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
208
- // to set the property as well to achieve the desired effect
209
-
210
- var element = $compile ( '<img ng-src="{{id}}"></img>' ) ( $rootScope ) ;
211
-
212
- $rootScope . $digest ( ) ;
213
- expect ( element . prop ( 'src' ) ) . toBe ( '' ) ;
214
- dealoc ( element ) ;
215
-
216
- element = $compile ( '<img ng-src="some/"></img>' ) ( $rootScope ) ;
217
-
218
- $rootScope . $digest ( ) ;
219
- expect ( element . prop ( 'src' ) ) . toMatch ( '/some/$' ) ;
220
- dealoc ( element ) ;
221
-
222
- element = $compile ( '<img ng-src="{{id}}"></img>' ) ( $rootScope ) ;
223
- $rootScope . $apply ( function ( ) {
224
- $rootScope . id = $sce . trustAsResourceUrl ( 'http://somewhere/abc' ) ;
225
- } ) ;
226
- expect ( element . prop ( 'src' ) ) . toEqual ( 'http://somewhere/abc' ) ;
227
-
228
- dealoc ( element ) ;
229
- } ) ) ;
230
- }
231
- } ) ;
232
-
233
-
234
- describe ( 'ngSrcset' , function ( ) {
235
- it ( 'should interpolate the expression and bind to srcset' , inject ( function ( $compile , $rootScope ) {
236
- var element = $compile ( '<img ng-srcset="some/{{id}} 2x"></div>' ) ( $rootScope ) ;
237
-
238
- $rootScope . $digest ( ) ;
239
- expect ( element . attr ( 'srcset' ) ) . toBeUndefined ( ) ;
240
-
241
- $rootScope . $apply ( function ( ) {
242
- $rootScope . id = 1 ;
243
- } ) ;
244
- expect ( element . attr ( 'srcset' ) ) . toEqual ( 'some/1 2x' ) ;
245
-
246
- dealoc ( element ) ;
247
- } ) ) ;
248
- } ) ;
249
-
250
-
251
- describe ( 'ngHref' , function ( ) {
252
- var element ;
253
-
254
- afterEach ( function ( ) {
255
- dealoc ( element ) ;
256
- } ) ;
257
-
258
-
259
- it ( 'should interpolate the expression and bind to href' , inject ( function ( $compile , $rootScope ) {
260
- element = $compile ( '<a ng-href="some/{{id}}"></div>' ) ( $rootScope ) ;
261
- $rootScope . $digest ( ) ;
262
- expect ( element . attr ( 'href' ) ) . toEqual ( 'some/' ) ;
263
-
264
- $rootScope . $apply ( function ( ) {
265
- $rootScope . id = 1 ;
266
- } ) ;
267
- expect ( element . attr ( 'href' ) ) . toEqual ( 'some/1' ) ;
268
- } ) ) ;
269
-
270
-
271
- it ( 'should bind href and merge with other attrs' , inject ( function ( $rootScope , $compile ) {
272
- element = $compile ( '<a ng-href="{{url}}" rel="{{rel}}"></a>' ) ( $rootScope ) ;
273
- $rootScope . url = 'http://server' ;
274
- $rootScope . rel = 'REL' ;
275
- $rootScope . $digest ( ) ;
276
- expect ( element . attr ( 'href' ) ) . toEqual ( 'http://server' ) ;
277
- expect ( element . attr ( 'rel' ) ) . toEqual ( 'REL' ) ;
278
- } ) ) ;
279
-
280
-
281
- it ( 'should bind href even if no interpolation' , inject ( function ( $rootScope , $compile ) {
282
- element = $compile ( '<a ng-href="http://server"></a>' ) ( $rootScope ) ;
283
- $rootScope . $digest ( ) ;
284
- expect ( element . attr ( 'href' ) ) . toEqual ( 'http://server' ) ;
285
- } ) ) ;
286
-
287
- it ( 'should not set the href if ng-href is empty' , inject ( function ( $rootScope , $compile ) {
288
- $rootScope . url = null ;
289
- element = $compile ( '<a ng-href="{{url}}">' ) ( $rootScope ) ;
290
- $rootScope . $digest ( ) ;
291
- expect ( element . attr ( 'href' ) ) . toEqual ( undefined ) ;
292
- } ) ) ;
293
-
294
- it ( 'should remove the href if ng-href changes to empty' , inject ( function ( $rootScope , $compile ) {
295
- $rootScope . url = 'http://www.google.com/' ;
296
- element = $compile ( '<a ng-href="{{url}}">' ) ( $rootScope ) ;
297
- $rootScope . $digest ( ) ;
298
-
299
- $rootScope . url = null ;
300
- $rootScope . $digest ( ) ;
301
- expect ( element . attr ( 'href' ) ) . toEqual ( undefined ) ;
302
- } ) ) ;
303
-
304
- // Support: IE 9-11 only, Edge 12-15+
305
- if ( msie || / \b E d g e \/ [ \d . ] + \b / . test ( window . navigator . userAgent ) ) {
306
- // IE/Edge fail when setting a href to a URL containing a % that isn't a valid escape sequence
307
- // See https://github.com/angular/angular.js/issues/13388
308
- it ( 'should throw error if ng-href contains a non-escaped percent symbol' , inject ( function ( $rootScope , $compile ) {
309
- expect ( function ( ) {
310
- element = $compile ( '<a ng-href="http://www.google.com/{{\'a%link\'}}">' ) ( $rootScope ) ;
311
- } ) . toThrow ( ) ;
312
- } ) ) ;
313
- }
314
-
315
- if ( isDefined ( window . SVGElement ) ) {
316
- describe ( 'SVGAElement' , function ( ) {
317
- it ( 'should interpolate the expression and bind to xlink:href' , inject ( function ( $compile , $rootScope ) {
318
- element = $compile ( '<svg><a ng-href="some/{{id}}"></a></svg>' ) ( $rootScope ) ;
319
- var child = element . children ( 'a' ) ;
320
- $rootScope . $digest ( ) ;
321
- expect ( child . attr ( 'xlink:href' ) ) . toEqual ( 'some/' ) ;
322
-
323
- $rootScope . $apply ( function ( ) {
324
- $rootScope . id = 1 ;
325
- } ) ;
326
- expect ( child . attr ( 'xlink:href' ) ) . toEqual ( 'some/1' ) ;
327
- } ) ) ;
328
-
329
-
330
- it ( 'should bind xlink:href even if no interpolation' , inject ( function ( $rootScope , $compile ) {
331
- element = $compile ( '<svg><a ng-href="http://server"></a></svg>' ) ( $rootScope ) ;
332
- var child = element . children ( 'a' ) ;
333
- $rootScope . $digest ( ) ;
334
- expect ( child . attr ( 'xlink:href' ) ) . toEqual ( 'http://server' ) ;
335
- } ) ) ;
336
- } ) ;
337
- }
338
- } ) ;
0 commit comments