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