@@ -440,30 +440,70 @@ describe('$compile', function() {
440
440
} ) ) ;
441
441
442
442
if ( supportsForeignObject ( ) ) {
443
+ // Supports: Chrome 53-57+
444
+ // Since Chrome 53-57+, the reported size of `<foreignObject>` elements and their descendants
445
+ // is affected by global display settings (e.g. font size) and browser settings (e.g. default
446
+ // zoom level). In order to avoid false negatives, we compare against the size of the
447
+ // equivalent, hand-written SVG instead of fixed widths/heights.
448
+ var HAND_WRITTEN_SVG =
449
+ '<svg width="400" height="400">' +
450
+ '<foreignObject width="100" height="100">' +
451
+ '<div style="position:absolute;width:20px;height:20px">test</div>' +
452
+ '</foreignObject>' +
453
+ '</svg>' ;
454
+
443
455
it ( 'should handle foreignObject' , inject ( function ( ) {
444
- element = jqLite ( '<div><svg-container>' +
445
- '<foreignObject width="100" height="100"><div class="test" style="position:absolute;width:20px;height:20px">test</div></foreignObject>' +
446
- '</svg-container></div>' ) ;
456
+ element = jqLite (
457
+ '<div>' +
458
+ // By hand (for reference)
459
+ HAND_WRITTEN_SVG +
460
+ // By directive
461
+ '<svg-container>' +
462
+ '<foreignObject width="100" height="100">' +
463
+ '<div style="position:absolute;width:20px;height:20px">test</div>' +
464
+ '</foreignObject>' +
465
+ '</svg-container>' +
466
+ '</div>' ) ;
447
467
$compile ( element . contents ( ) ) ( $rootScope ) ;
448
468
document . body . appendChild ( element [ 0 ] ) ;
449
469
450
- var testElem = element . find ( 'div' ) ;
451
- expect ( isHTMLElement ( testElem [ 0 ] ) ) . toBe ( true ) ;
452
- var bounds = testElem [ 0 ] . getBoundingClientRect ( ) ;
453
- expect ( bounds . width === 20 && bounds . height === 20 ) . toBe ( true ) ;
470
+ var referenceElem = element . find ( 'div' ) [ 0 ] ;
471
+ var testElem = element . find ( 'div' ) [ 1 ] ;
472
+ var referenceBounds = referenceElem . getBoundingClientRect ( ) ;
473
+ var testBounds = testElem . getBoundingClientRect ( ) ;
474
+
475
+ expect ( isHTMLElement ( testElem ) ) . toBe ( true ) ;
476
+ expect ( referenceBounds . width ) . toBeGreaterThan ( 0 ) ;
477
+ expect ( referenceBounds . height ) . toBeGreaterThan ( 0 ) ;
478
+ expect ( testBounds . width ) . toBe ( referenceBounds . width ) ;
479
+ expect ( testBounds . height ) . toBe ( referenceBounds . height ) ;
454
480
} ) ) ;
455
481
456
482
it ( 'should handle custom svg containers that transclude to foreignObject that transclude html' , inject ( function ( ) {
457
- element = jqLite ( '<div><svg-container>' +
458
- '<my-foreign-object><div class="test" style="width:20px;height:20px">test</div></my-foreign-object>' +
459
- '</svg-container></div>' ) ;
483
+ element = jqLite (
484
+ '<div>' +
485
+ // By hand (for reference)
486
+ HAND_WRITTEN_SVG +
487
+ // By directive
488
+ '<svg-container>' +
489
+ '<my-foreign-object>' +
490
+ '<div style="width:20px;height:20px">test</div>' +
491
+ '</my-foreign-object>' +
492
+ '</svg-container>' +
493
+ '</div>' ) ;
460
494
$compile ( element . contents ( ) ) ( $rootScope ) ;
461
495
document . body . appendChild ( element [ 0 ] ) ;
462
496
463
- var testElem = element . find ( 'div' ) ;
464
- expect ( isHTMLElement ( testElem [ 0 ] ) ) . toBe ( true ) ;
465
- var bounds = testElem [ 0 ] . getBoundingClientRect ( ) ;
466
- expect ( bounds . width === 20 && bounds . height === 20 ) . toBe ( true ) ;
497
+ var referenceElem = element . find ( 'div' ) [ 0 ] ;
498
+ var testElem = element . find ( 'div' ) [ 1 ] ;
499
+ var referenceBounds = referenceElem . getBoundingClientRect ( ) ;
500
+ var testBounds = testElem . getBoundingClientRect ( ) ;
501
+
502
+ expect ( isHTMLElement ( testElem ) ) . toBe ( true ) ;
503
+ expect ( referenceBounds . width ) . toBeGreaterThan ( 0 ) ;
504
+ expect ( referenceBounds . height ) . toBeGreaterThan ( 0 ) ;
505
+ expect ( testBounds . width ) . toBe ( referenceBounds . width ) ;
506
+ expect ( testBounds . height ) . toBe ( referenceBounds . height ) ;
467
507
} ) ) ;
468
508
469
509
// NOTE: This test may be redundant.
0 commit comments