@@ -40,9 +40,8 @@ describe('chrome extensions', () => {
4040 it ( 'does not crash when using chrome.management' , async ( ) => {
4141 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
4242 const w = new BrowserWindow ( { show : false , webPreferences : { session : customSession , sandbox : true } } ) ;
43- w . loadURL ( 'about:blank' ) ;
43+ await w . loadURL ( 'about:blank' ) ;
4444
45- await emittedOnce ( w . webContents , 'dom-ready' ) ;
4645 await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'persistent-background-page' ) ) ;
4746 const args : any = await emittedOnce ( app , 'web-contents-created' ) ;
4847 const wc : Electron . WebContents = args [ 1 ] ;
@@ -60,9 +59,8 @@ describe('chrome extensions', () => {
6059 it ( 'can open WebSQLDatabase in a background page' , async ( ) => {
6160 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
6261 const w = new BrowserWindow ( { show : false , webPreferences : { session : customSession , sandbox : true } } ) ;
63- w . loadURL ( 'about:blank' ) ;
62+ await w . loadURL ( 'about:blank' ) ;
6463
65- await emittedOnce ( w . webContents , 'dom-ready' ) ;
6664 await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'persistent-background-page' ) ) ;
6765 const args : any = await emittedOnce ( app , 'web-contents-created' ) ;
6866 const wc : Electron . WebContents = args [ 1 ] ;
@@ -77,8 +75,7 @@ describe('chrome extensions', () => {
7775 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
7876 const w = new BrowserWindow ( { show : false , webPreferences : { session : customSession , sandbox : true } } ) ;
7977 const extension = await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'ui-page' ) ) ;
80- w . loadURL ( `${ extension . url } bare-page.html` ) ;
81- await emittedOnce ( w . webContents , 'dom-ready' ) ;
78+ await w . loadURL ( `${ extension . url } bare-page.html` ) ;
8279 await expect ( fetch ( w . webContents , `${ url } /cors` ) ) . to . not . be . rejectedWith ( TypeError ) ;
8380 } ) ;
8481
@@ -90,8 +87,7 @@ describe('chrome extensions', () => {
9087 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
9188 await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'red-bg' ) ) ;
9289 const w = new BrowserWindow ( { show : false , webPreferences : { session : customSession } } ) ;
93- w . loadURL ( url ) ;
94- await emittedOnce ( w . webContents , 'dom-ready' ) ;
90+ await w . loadURL ( url ) ;
9591 const bg = await w . webContents . executeJavaScript ( 'document.documentElement.style.backgroundColor' ) ;
9692 expect ( bg ) . to . equal ( 'red' ) ;
9793 } ) ;
@@ -145,8 +141,7 @@ describe('chrome extensions', () => {
145141 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
146142 await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'red-bg' ) ) ;
147143 const w = new BrowserWindow ( { show : false } ) ; // not in the session
148- w . loadURL ( url ) ;
149- await emittedOnce ( w . webContents , 'dom-ready' ) ;
144+ await w . loadURL ( url ) ;
150145 const bg = await w . webContents . executeJavaScript ( 'document.documentElement.style.backgroundColor' ) ;
151146 expect ( bg ) . to . equal ( '' ) ;
152147 } ) ;
@@ -169,8 +164,7 @@ describe('chrome extensions', () => {
169164 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
170165 extension = await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'chrome-i18n' ) ) ;
171166 w = new BrowserWindow ( { show : false , webPreferences : { session : customSession , nodeIntegration : true } } ) ;
172- w . loadURL ( url ) ;
173- await emittedOnce ( w . webContents , 'dom-ready' ) ;
167+ await w . loadURL ( url ) ;
174168 } ) ;
175169 it ( 'getAcceptLanguages()' , async ( ) => {
176170 const result = await exec ( 'getAcceptLanguages' ) ;
@@ -184,28 +178,37 @@ describe('chrome extensions', () => {
184178 } ) ;
185179
186180 describe ( 'chrome.runtime' , ( ) => {
187- let content : any ;
188- before ( async ( ) => {
181+ let w : BrowserWindow ;
182+ const exec = async ( name : string ) => {
183+ const p = emittedOnce ( ipcMain , 'success' ) ;
184+ await w . webContents . executeJavaScript ( `exec('${ name } ')` ) ;
185+ const [ , result ] = await p ;
186+ return result ;
187+ } ;
188+ beforeEach ( async ( ) => {
189189 const customSession = session . fromPartition ( `persist:${ require ( 'uuid' ) . v4 ( ) } ` ) ;
190190 await customSession . loadExtension ( path . join ( fixtures , 'extensions' , 'chrome-runtime' ) ) ;
191- const w = new BrowserWindow ( { show : false , webPreferences : { session : customSession } } ) ;
192- try {
193- w . loadURL ( url ) ;
194- await emittedOnce ( w . webContents , 'dom-ready' ) ;
195- content = JSON . parse ( await w . webContents . executeJavaScript ( 'document.documentElement.textContent' ) ) ;
196- expect ( content ) . to . be . an ( 'object' ) ;
197- } finally {
198- w . destroy ( ) ;
199- }
191+ w = new BrowserWindow ( { show : false , webPreferences : { session : customSession , nodeIntegration : true } } ) ;
192+ await w . loadURL ( url ) ;
193+ } ) ;
194+ it ( 'getManifest()' , async ( ) => {
195+ const result = await exec ( 'getManifest' ) ;
196+ expect ( result ) . to . be . an ( 'object' ) . with . property ( 'name' , 'chrome-runtime' ) ;
200197 } ) ;
201- it ( 'getManifest()' , ( ) => {
202- expect ( content . manifest ) . to . be . an ( 'object' ) . with . property ( 'name' , 'chrome-runtime' ) ;
198+ it ( 'id' , async ( ) => {
199+ const result = await exec ( 'id' ) ;
200+ expect ( result ) . to . be . a ( 'string' ) . with . lengthOf ( 32 ) ;
203201 } ) ;
204- it ( 'id' , ( ) => {
205- expect ( content . id ) . to . be . a ( 'string' ) . with . lengthOf ( 32 ) ;
202+ it ( 'getURL()' , async ( ) => {
203+ const result = await exec ( 'getURL' ) ;
204+ expect ( result ) . to . be . a ( 'string' ) . and . match ( / ^ c h r o m e - e x t e n s i o n : \/ \/ .* m a i n .j s $ / ) ;
206205 } ) ;
207- it ( 'getURL()' , ( ) => {
208- expect ( content . url ) . to . be . a ( 'string' ) . and . match ( / ^ c h r o m e - e x t e n s i o n : \/ \/ .* m a i n .j s $ / ) ;
206+ it ( 'getPlatformInfo()' , async ( ) => {
207+ const result = await exec ( 'getPlatformInfo' ) ;
208+ expect ( result ) . to . be . an ( 'object' ) ;
209+ expect ( result . os ) . to . be . a ( 'string' ) ;
210+ expect ( result . arch ) . to . be . a ( 'string' ) ;
211+ expect ( result . nacl_arch ) . to . be . a ( 'string' ) ;
209212 } ) ;
210213 } ) ;
211214
@@ -562,17 +565,15 @@ describe('chrome extensions', () => {
562565 it ( 'loads a ui page of an extension' , async ( ) => {
563566 const { id } = await session . defaultSession . loadExtension ( path . join ( fixtures , 'extensions' , 'ui-page' ) ) ;
564567 const w = new BrowserWindow ( { show : false } ) ;
565- w . loadURL ( `chrome-extension://${ id } /bare-page.html` ) ;
566- await emittedOnce ( w . webContents , 'dom-ready' ) ;
568+ await w . loadURL ( `chrome-extension://${ id } /bare-page.html` ) ;
567569 const textContent = await w . webContents . executeJavaScript ( 'document.body.textContent' ) ;
568570 expect ( textContent ) . to . equal ( 'ui page loaded ok\n' ) ;
569571 } ) ;
570572
571573 it ( 'can load resources' , async ( ) => {
572574 const { id } = await session . defaultSession . loadExtension ( path . join ( fixtures , 'extensions' , 'ui-page' ) ) ;
573575 const w = new BrowserWindow ( { show : false } ) ;
574- w . loadURL ( `chrome-extension://${ id } /page-script-load.html` ) ;
575- await emittedOnce ( w . webContents , 'dom-ready' ) ;
576+ await w . loadURL ( `chrome-extension://${ id } /page-script-load.html` ) ;
576577 const textContent = await w . webContents . executeJavaScript ( 'document.body.textContent' ) ;
577578 expect ( textContent ) . to . equal ( 'script loaded ok\n' ) ;
578579 } ) ;
0 commit comments