@@ -1697,83 +1697,78 @@ describe('angular', function() {
1697
1697
dealoc ( appElement ) ;
1698
1698
} ) ;
1699
1699
1700
- it ( 'should bootstrap from an extension into an extension document for same-origin documents only' , function ( ) {
1701
- // IE does not support `document.currentScript` (nor extensions with protocol), so skip test.
1702
- if ( msie ) return ;
1703
-
1704
- // Extension URLs are browser-specific, so we must choose a scheme that is supported by the browser to make
1705
- // sure that the URL is properly parsed.
1706
- var extensionScheme ;
1707
- var userAgent = window . navigator . userAgent ;
1708
- if ( / F i r e f o x \/ / . test ( userAgent ) ) {
1709
- extensionScheme = 'moz-extension' ;
1710
- } else if ( / E d g e \/ / . test ( userAgent ) ) {
1711
- extensionScheme = 'ms-browser-extension' ;
1712
- } else if ( / C h r o m e \/ / . test ( userAgent ) ) {
1713
- extensionScheme = 'chrome-extension' ;
1714
- } else if ( / S a f a r i \/ / . test ( userAgent ) ) {
1715
- extensionScheme = 'safari-extension' ;
1716
- } else {
1717
- extensionScheme = 'browserext' ; // Upcoming standard scheme.
1718
- }
1700
+ // IE does not support `document.currentScript` (nor extensions with protocol), so skip tests.
1701
+ if ( ! msie ) {
1702
+ describe ( 'auto bootstrap restrictions' , function ( ) {
1719
1703
1720
- var src = extensionScheme + '://something' ;
1721
- // Fake a minimal document object (the actual document.currentScript is readonly).
1722
- var fakeDoc = {
1723
- currentScript : { getAttribute : function ( ) { return src ; } } ,
1724
- location : { protocol : extensionScheme + ':' , origin : extensionScheme + '://something' } ,
1725
- createElement : document . createElement . bind ( document )
1726
- } ;
1727
- expect ( allowAutoBootstrap ( fakeDoc ) ) . toBe ( true ) ;
1704
+ function createFakeDoc ( attrs , protocol , currentScript ) {
1728
1705
1729
- src = extensionScheme + '://something-else' ;
1730
- expect ( allowAutoBootstrap ( fakeDoc ) ) . toBe ( false ) ;
1731
- } ) ;
1706
+ protocol = protocol || 'http:' ;
1707
+ var origin = protocol + '//something' ;
1732
1708
1733
- it ( 'should bootstrap from a script with an empty or missing `src` attribute' , function ( ) {
1734
- // IE does not support `document.currentScript` (nor extensions with protocol), so skip test.
1735
- if ( msie ) return ;
1709
+ if ( currentScript === undefined ) {
1710
+ currentScript = document . createElement ( 'script' ) ;
1711
+ Object . keys ( attrs ) . forEach ( function ( key ) { currentScript . setAttribute ( key , attrs [ key ] ) ; } ) ;
1712
+ }
1736
1713
1737
- // Fake a minimal document object (the actual document.currentScript is readonly).
1738
- var src ;
1739
- var fakeDoc = {
1740
- createElement : document . createElement . bind ( document ) ,
1741
- currentScript : { getAttribute : function ( ) { return src ; } } ,
1742
- location : { origin : 'some-value' , protocol : 'http:' }
1743
- } ;
1714
+ // Fake a minimal document object (the actual document.currentScript is readonly).
1715
+ return {
1716
+ currentScript : currentScript ,
1717
+ location : { protocol : protocol , origin : origin } ,
1718
+ createElement : document . createElement . bind ( document )
1719
+ } ;
1720
+ }
1744
1721
1745
- src = null ;
1746
- expect ( allowAutoBootstrap ( fakeDoc ) ) . toBe ( true ) ;
1722
+ it ( 'should bootstrap from an extension into an extension document for same-origin documents only' , function ( ) {
1723
+
1724
+ // Extension URLs are browser-specific, so we must choose a scheme that is supported by the browser to make
1725
+ // sure that the URL is properly parsed.
1726
+ var protocol ;
1727
+ var userAgent = window . navigator . userAgent ;
1728
+ if ( / F i r e f o x \/ / . test ( userAgent ) ) {
1729
+ protocol = 'moz-extension:' ;
1730
+ } else if ( / E d g e \/ / . test ( userAgent ) ) {
1731
+ protocol = 'ms-browser-extension:' ;
1732
+ } else if ( / C h r o m e \/ / . test ( userAgent ) ) {
1733
+ protocol = 'chrome-extension:' ;
1734
+ } else if ( / S a f a r i \/ / . test ( userAgent ) ) {
1735
+ protocol = 'safari-extension:' ;
1736
+ } else {
1737
+ protocol = 'browserext:' ; // Upcoming standard scheme.
1738
+ }
1747
1739
1748
- src = '' ;
1749
- expect ( allowAutoBootstrap ( fakeDoc ) ) . toBe ( true ) ;
1750
- } ) ;
1740
+ expect ( allowAutoBootstrap ( createFakeDoc ( { src : protocol + '//something' } , protocol ) ) ) . toBe ( true ) ;
1741
+ expect ( allowAutoBootstrap ( createFakeDoc ( { src : protocol + '//something-else' } , protocol ) ) ) . toBe ( false ) ;
1742
+ } ) ;
1751
1743
1752
- it ( 'should not bootstrap from an extension into a non-extension document' , function ( ) {
1753
- // IE does not support `document.currentScript` (nor extensions with protocol), so skip test.
1754
- if ( msie ) return ;
1744
+ it ( 'should bootstrap from a script with empty or no source (e.g. src, href or xlink:href attributes)' , function ( ) {
1755
1745
1756
- var src = 'resource://something' ;
1757
- // Fake a minimal document object (the actual document.currentScript is readonly).
1758
- var fakeDoc = {
1759
- currentScript : { getAttribute : function ( ) { return src ; } } ,
1760
- location : { protocol : 'http:' } ,
1761
- createElement : document . createElement . bind ( document )
1762
- } ;
1763
- expect ( allowAutoBootstrap ( fakeDoc ) ) . toBe ( false ) ;
1746
+ expect ( allowAutoBootstrap ( createFakeDoc ( { src : null } ) ) ) . toBe ( true ) ;
1747
+ expect ( allowAutoBootstrap ( createFakeDoc ( { src : '' } ) ) ) . toBe ( true ) ;
1764
1748
1765
- src = 'file://whatever' ;
1766
- expect ( allowAutoBootstrap ( fakeDoc ) ) . toBe ( true ) ;
1767
- } ) ;
1749
+ expect ( allowAutoBootstrap ( createFakeDoc ( { href : null } ) ) ) . toBe ( true ) ;
1750
+ expect ( allowAutoBootstrap ( createFakeDoc ( { href : '' } ) ) ) . toBe ( true ) ;
1768
1751
1769
- it ( 'should not bootstrap if bootstrapping is disabled' , function ( ) {
1770
- isAutoBootstrapAllowed = false ;
1771
- angularInit ( jqLite ( '<div ng-app></div>' ) [ 0 ] , bootstrapSpy ) ;
1772
- expect ( bootstrapSpy ) . not . toHaveBeenCalled ( ) ;
1773
- isAutoBootstrapAllowed = true ;
1774
- } ) ;
1775
- } ) ;
1752
+ expect ( allowAutoBootstrap ( createFakeDoc ( { 'xlink:href' : null } ) ) ) . toBe ( true ) ;
1753
+ expect ( allowAutoBootstrap ( createFakeDoc ( { 'xlink:href' : '' } ) ) ) . toBe ( true ) ;
1754
+ } ) ;
1755
+
1756
+
1757
+ it ( 'should not bootstrap from an extension into a non-extension document' , function ( ) {
1776
1758
1759
+ expect ( allowAutoBootstrap ( createFakeDoc ( { src : 'resource://something' } ) ) ) . toBe ( false ) ;
1760
+ expect ( allowAutoBootstrap ( createFakeDoc ( { src : 'file://whatever' } ) ) ) . toBe ( true ) ;
1761
+ } ) ;
1762
+
1763
+ it ( 'should not bootstrap if bootstrapping is disabled' , function ( ) {
1764
+ isAutoBootstrapAllowed = false ;
1765
+ angularInit ( jqLite ( '<div ng-app></div>' ) [ 0 ] , bootstrapSpy ) ;
1766
+ expect ( bootstrapSpy ) . not . toHaveBeenCalled ( ) ;
1767
+ isAutoBootstrapAllowed = true ;
1768
+ } ) ;
1769
+ } ) ;
1770
+ }
1771
+ } ) ;
1777
1772
1778
1773
describe ( 'angular service' , function ( ) {
1779
1774
it ( 'should override services' , function ( ) {
0 commit comments