@@ -10,6 +10,7 @@ import { freemiumPIRDataExamples } from './freemium-pir-banner/mocks/freemiumPIR
1010import { activityMockTransport } from './activity/mocks/activity.mock-transport.js' ;
1111import { protectionsMockTransport } from './protections/mocks/protections.mock-transport.js' ;
1212import { omnibarMockTransport } from './omnibar/mocks/omnibar.mock-transport.js' ;
13+ import { tabsMockTransport } from './tabs/tabs.mock-transport.js' ;
1314
1415/**
1516 * @typedef {import('../types/new-tab').Favorite } Favorite
@@ -119,6 +120,7 @@ export function mockTransport() {
119120 activity : activityMockTransport ( ) ,
120121 protections : protectionsMockTransport ( ) ,
121122 omnibar : omnibarMockTransport ( ) ,
123+ tabs : tabsMockTransport ( ) ,
122124 } ;
123125
124126 return new TestTransportConfig ( {
@@ -492,68 +494,7 @@ export function mockTransport() {
492494 return Promise . resolve ( fromStorage ) ;
493495 }
494496 case 'initialSetup' : {
495- /** @type {import('../types/new-tab.ts').Widgets } */
496- const widgetsFromStorage = read ( 'widgets' ) || [
497- { id : 'updateNotification' } ,
498- { id : 'rmf' } ,
499- { id : 'freemiumPIRBanner' } ,
500- { id : 'nextSteps' } ,
501- { id : 'favorites' } ,
502- ] ;
503-
504- /** @type {import('../types/new-tab.ts').WidgetConfigs } */
505- const widgetConfigFromStorage = read ( 'widget_config' ) || [ { id : 'favorites' , visibility : 'visible' } ] ;
506-
507- /** @type {UpdateNotificationData } */
508- let updateNotification = { content : null } ;
509- const isDelayed = url . searchParams . has ( 'update-notification-delay' ) ;
510-
511- if ( ! isDelayed && url . searchParams . has ( 'update-notification' ) ) {
512- const value = url . searchParams . get ( 'update-notification' ) ;
513- if ( value && value in updateNotificationExamples ) {
514- updateNotification = updateNotificationExamples [ value ] ;
515- }
516- }
517-
518- /** @type {import('../types/new-tab.ts').InitialSetupResponse } */
519- const initial = {
520- widgets : widgetsFromStorage ,
521- widgetConfigs : widgetConfigFromStorage ,
522- platform : { name : 'integration' } ,
523- env : 'development' ,
524- locale : 'en' ,
525- updateNotification,
526- } ;
527-
528- widgetsFromStorage . push ( { id : 'protections' } ) ;
529- widgetConfigFromStorage . push ( { id : 'protections' , visibility : 'visible' } ) ;
530-
531- if ( url . searchParams . has ( 'omnibar' ) ) {
532- const favoritesWidgetIndex = widgetsFromStorage . findIndex ( ( widget ) => widget . id === 'favorites' ) ?? 0 ;
533- widgetsFromStorage . splice ( favoritesWidgetIndex , 0 , { id : 'omnibar' } ) ;
534- const favoritesWidgetConfigIndex = widgetConfigFromStorage . findIndex ( ( widget ) => widget . id === 'favorites' ) ?? 0 ;
535- widgetConfigFromStorage . splice ( favoritesWidgetConfigIndex , 0 , { id : 'omnibar' , visibility : 'visible' } ) ;
536- }
537-
538- initial . customizer = customizerData ( ) ;
539-
540- /** @type {import('../types/new-tab').NewTabPageSettings } */
541- const settings = {
542- customizerDrawer : { state : 'enabled' } ,
543- } ;
544-
545- if ( url . searchParams . get ( 'autoOpen' ) === 'true' && settings . customizerDrawer ) {
546- settings . customizerDrawer . autoOpen = true ;
547- }
548-
549- if ( url . searchParams . get ( 'adBlocking' ) === 'enabled' ) {
550- settings . adBlocking = { state : 'enabled' } ;
551- }
552-
553- // feature flags
554- initial . settings = settings ;
555-
556- return Promise . resolve ( initial ) ;
497+ return Promise . resolve ( initialSetup ( url ) ) ;
557498 }
558499 default : {
559500 return Promise . reject ( new Error ( 'unhandled request' + msg ) ) ;
@@ -563,6 +504,78 @@ export function mockTransport() {
563504 } ) ;
564505}
565506
507+ /**
508+ * @param {URL } url
509+ * @return {import('../types/new-tab').InitialSetupResponse }
510+ */
511+ export function initialSetup ( url ) {
512+ /** @type {import('../types/new-tab.ts').Widgets } */
513+ const widgetsFromStorage = [
514+ { id : 'updateNotification' } ,
515+ { id : 'rmf' } ,
516+ { id : 'freemiumPIRBanner' } ,
517+ { id : 'nextSteps' } ,
518+ { id : 'favorites' } ,
519+ ] ;
520+
521+ /** @type {import('../types/new-tab.ts').WidgetConfigs } */
522+ const widgetConfigFromStorage = [ { id : 'favorites' , visibility : 'visible' } ] ;
523+
524+ /** @type {UpdateNotificationData } */
525+ let updateNotification = { content : null } ;
526+ const isDelayed = url . searchParams . has ( 'update-notification-delay' ) ;
527+
528+ if ( ! isDelayed && url . searchParams . has ( 'update-notification' ) ) {
529+ const value = url . searchParams . get ( 'update-notification' ) ;
530+ if ( value && value in updateNotificationExamples ) {
531+ updateNotification = updateNotificationExamples [ value ] ;
532+ }
533+ }
534+
535+ /** @type {import('../types/new-tab.ts').InitialSetupResponse } */
536+ const initial = {
537+ widgets : widgetsFromStorage ,
538+ widgetConfigs : widgetConfigFromStorage ,
539+ platform : { name : 'integration' } ,
540+ env : 'development' ,
541+ locale : 'en' ,
542+ updateNotification,
543+ } ;
544+
545+ widgetsFromStorage . push ( { id : 'protections' } ) ;
546+ widgetConfigFromStorage . push ( { id : 'protections' , visibility : 'visible' } ) ;
547+
548+ if ( url . searchParams . has ( 'omnibar' ) ) {
549+ const favoritesWidgetIndex = widgetsFromStorage . findIndex ( ( widget ) => widget . id === 'favorites' ) ?? 0 ;
550+ widgetsFromStorage . splice ( favoritesWidgetIndex , 0 , { id : 'omnibar' } ) ;
551+ const favoritesWidgetConfigIndex = widgetConfigFromStorage . findIndex ( ( widget ) => widget . id === 'favorites' ) ?? 0 ;
552+ widgetConfigFromStorage . splice ( favoritesWidgetConfigIndex , 0 , { id : 'omnibar' , visibility : 'visible' } ) ;
553+ }
554+
555+ initial . customizer = customizerData ( ) ;
556+
557+ /** @type {import('../types/new-tab').NewTabPageSettings } */
558+ const settings = {
559+ customizerDrawer : { state : 'enabled' } ,
560+ } ;
561+
562+ if ( url . searchParams . get ( 'autoOpen' ) === 'true' && settings . customizerDrawer ) {
563+ settings . customizerDrawer . autoOpen = true ;
564+ }
565+
566+ if ( url . searchParams . get ( 'adBlocking' ) === 'enabled' ) {
567+ settings . adBlocking = { state : 'enabled' } ;
568+ }
569+
570+ if ( url . searchParams . has ( 'tabs' ) ) {
571+ initial . tabs = { tabId : '01' , tabIds : [ '01' ] } ;
572+ }
573+
574+ // feature flags
575+ initial . settings = settings ;
576+ return initial ;
577+ }
578+
566579/**
567580 * @template {{id: string}} T
568581 * @param {T[] } array
0 commit comments