99const expect = require ( 'chai' ) . expect ;
1010
1111const { runUnitTests} = require ( '../../../infra/testing/webdriver/runUnitTests' ) ;
12- const { TabManager } = require ( '../../../infra/testing/webdriver/TabManager ' ) ;
12+ const { IframeManager } = require ( '../../../infra/testing/webdriver/IframeManager ' ) ;
1313const activateAndControlSW = require ( '../../../infra/testing/activate-and-control' ) ;
1414const cleanSWEnv = require ( '../../../infra/testing/clean-sw' ) ;
1515const templateData = require ( '../../../infra/testing/server/template-data' ) ;
1616
1717// Store local references of these globals.
18- const { webdriver, server, seleniumBrowser } = global . __workbox ;
18+ const { webdriver, server} = global . __workbox ;
1919
2020describe ( `[workbox-broadcast-update]` , function ( ) {
2121 it ( `passes all SW unit tests` , async function ( ) {
@@ -122,13 +122,7 @@ describe(`[workbox-broadcast-update] Plugin`, function() {
122122 } ) ;
123123
124124 it ( `should broadcast a message to all open window clients by default` , async function ( ) {
125- // This test doesn't work in Safari:
126- // https://github.com/GoogleChrome/workbox/issues/2755
127- if ( seleniumBrowser . getId ( ) === 'safari' ) {
128- this . skip ( ) ;
129- }
130-
131- const tabManager = new TabManager ( webdriver ) ;
125+ const iframeManager = new IframeManager ( webdriver ) ;
132126
133127 templateData . assign ( {
134128 title : 'Broadcast Cache Update Test' ,
@@ -152,15 +146,11 @@ describe(`[workbox-broadcast-update] Plugin`, function() {
152146 } , dynamicPageURL ) ;
153147 } ) ;
154148
155- // Update the template data, then open a new tab to trigger the update.
149+ // Update the template data and open an iframe to trigger the cache update.
156150 templateData . assign ( {
157151 body : 'Third test, with an updated body.' ,
158152 } ) ;
159-
160- await tabManager . openTab ( dynamicPageURL ) ;
161-
162- // Go back to the initial tab to assert the message was received there.
163- await tabManager . closeOpenedTabs ( ) ;
153+ await iframeManager . createIframeClient ( dynamicPageURL ) ;
164154
165155 await webdriver . wait ( ( ) => {
166156 return webdriver . executeScript ( ( ) => {
@@ -183,34 +173,19 @@ describe(`[workbox-broadcast-update] Plugin`, function() {
183173 } ) ;
184174
185175 it ( `should only broadcast a message to the client that made the request when notifyAllClients is false` , async function ( ) {
186- // This test doesn't work in Safari:
187- // https://github.com/GoogleChrome/workbox/issues/2755
188- if ( seleniumBrowser . getId ( ) === 'safari' ) {
189- this . skip ( ) ;
190- }
191-
192176 const url = `${ apiURL } ?notifyAllClientsTest` ;
193- const tabManager = new TabManager ( webdriver ) ;
177+ const iframeManager = new IframeManager ( webdriver ) ;
194178
195179 await webdriver . get ( testingURL ) ;
196180 await webdriver . executeAsyncScript ( ( url , cb ) => {
197181 fetch ( url ) . then ( ( ) => cb ( ) ) . catch ( ( err ) => cb ( err . message ) ) ;
198182 } , url ) ;
199183
200- await tabManager . openTab ( testingURL ) ;
201- await webdriver . executeAsyncScript ( ( url , cb ) => {
202- fetch ( url ) . then ( ( ) => cb ( ) ) . catch ( ( err ) => cb ( err . message ) ) ;
203- } , url ) ;
204-
205- await webdriver . wait ( ( ) => {
206- return webdriver . executeScript ( ( ) => {
207- return window . __messages . length > 0 ;
208- } ) ;
209- } ) ;
184+ const iframeClient = await iframeManager . createIframeClient ( testingURL ) ;
185+ await iframeClient . executeAsyncScript ( `fetch(${ JSON . stringify ( url ) } )` ) ;
186+ await iframeClient . wait ( 'window.__messages.length > 0' ) ;
210187
211- const populatedMessages = await webdriver . executeScript ( ( ) => {
212- return window . __messages ;
213- } ) ;
188+ const populatedMessages = await iframeClient . executeAsyncScript ( 'window.__messages' ) ;
214189 expect ( populatedMessages ) . to . eql ( [ {
215190 type : 'CACHE_UPDATED' ,
216191 meta : 'workbox-broadcast-update' ,
@@ -220,8 +195,6 @@ describe(`[workbox-broadcast-update] Plugin`, function() {
220195 } ,
221196 } ] ) ;
222197
223- await tabManager . closeOpenedTabs ( ) ;
224-
225198 const unpopulatedMessages = await webdriver . executeScript ( ( ) => {
226199 return window . __messages ;
227200 } ) ;
0 commit comments