@@ -26,6 +26,8 @@ import {
2626} from './load_js' ;
2727import { _createError } from '../core/util/assert' ;
2828import { AuthErrorCode } from '../core/errors' ;
29+ import { TrustedResourceUrl , trustedResourceUrl , unwrapResourceUrl } from 'safevalues' ;
30+ import { setScriptSrc } from 'safevalues/dom' ;
2931
3032use ( sinonChai ) ;
3133
@@ -41,10 +43,10 @@ describe('platform-browser/load_js', () => {
4143 describe ( '_loadJS' , ( ) => {
4244 it ( 'sets the appropriate properties' , ( ) => {
4345 _setExternalJSProvider ( {
44- loadJS ( url : string ) : Promise < Event > {
46+ loadJS ( url : TrustedResourceUrl ) : Promise < Event > {
4547 return new Promise ( ( resolve , reject ) => {
4648 const el = document . createElement ( 'script' ) ;
47- el . setAttribute ( 'src' , url ) ;
49+ setScriptSrc ( el , url ) ;
4850 el . onload = resolve ;
4951 el . onerror = e => {
5052 const error = _createError ( AuthErrorCode . INTERNAL_ERROR ) ;
@@ -55,20 +57,18 @@ describe('platform-browser/load_js', () => {
5557 el . charset = 'UTF-8' ;
5658 } ) ;
5759 } ,
58- gapiScript : ' https://gapiScript' ,
59- recaptchaV2Script : ' https://recaptchaV2Script' ,
60- recaptchaEnterpriseScript : ' https://recaptchaEnterpriseScript'
60+ gapiScript : trustedResourceUrl ` https://gapiScript` ,
61+ recaptchaV2Script : trustedResourceUrl ` https://recaptchaV2Script` ,
62+ recaptchaEnterpriseScript : trustedResourceUrl ` https://recaptchaEnterpriseScript`
6163 } ) ;
6264 const el = document . createElement ( 'script' ) ;
6365 sinon . stub ( el ) ; // Prevent actually setting the src attribute
6466 sinon . stub ( document , 'createElement' ) . returns ( el ) ;
6567
68+ const testUrl = trustedResourceUrl `http://localhost/url` ;
6669 // eslint-disable-next-line @typescript-eslint/no-floating-promises
67- _loadJS ( 'http://localhost/url' ) ;
68- expect ( el . setAttribute ) . to . have . been . calledWith (
69- 'src' ,
70- 'http://localhost/url'
71- ) ;
70+ _loadJS ( testUrl ) ;
71+ expect ( el . src ) . to . eq ( unwrapResourceUrl ( testUrl ) ) ;
7272 expect ( el . type ) . to . eq ( 'text/javascript' ) ;
7373 expect ( el . charset ) . to . eq ( 'UTF-8' ) ;
7474 } ) ;
0 commit comments