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