@@ -24,6 +24,8 @@ window.onbeforeunload = () => {
24
24
return promptBeforeReload ? false : undefined ;
25
25
} ;
26
26
27
+ const kOpenTestLinkAltText = 'Open' ;
28
+
27
29
// The possible options for the tests.
28
30
interface StandaloneOptions {
29
31
runnow : boolean ;
@@ -435,7 +437,7 @@ function makeTreeNodeHeaderHTML(
435
437
onChange ( true ) ;
436
438
} ;
437
439
438
- const href = `? ${ worker ? 'worker&' : '' } ${ debug ? 'debug&' : '' } q= ${ n . query . toString ( ) } ` ;
440
+ const href = createSearchQuery ( [ n . query . toString ( ) ] ) ;
439
441
if ( onChange ) {
440
442
div . on ( 'toggle' , function ( this ) {
441
443
onChange ( ( this as HTMLDetailsElement ) . open ) ;
@@ -458,8 +460,8 @@ function makeTreeNodeHeaderHTML(
458
460
$ ( '<a>' )
459
461
. addClass ( 'nodelink' )
460
462
. attr ( 'href' , href )
461
- . attr ( 'alt' , 'Open' )
462
- . attr ( 'title' , 'Open' )
463
+ . attr ( 'alt' , kOpenTestLinkAltText )
464
+ . attr ( 'title' , kOpenTestLinkAltText )
463
465
. appendTo ( header ) ;
464
466
if ( 'testCreationStack' in n && n . testCreationStack ) {
465
467
$ ( '<button>' )
@@ -535,6 +537,18 @@ function prepareParams(params: Record<string, ParamValue>): string {
535
537
return new URLSearchParams ( pairs ) . toString ( ) ;
536
538
}
537
539
540
+ /**
541
+ * Given a search query, generates a search parameter string
542
+ * @param queries array of queries
543
+ * @param params an optional existing search
544
+ * @returns a search query string
545
+ */
546
+ function createSearchQuery ( queries : string [ ] , params ?: string ) {
547
+ params = params === undefined ? prepareParams ( optionsToRecord ( options ) ) : params ;
548
+ // Add in q separately to avoid escaping punctuation marks.
549
+ return `?${ params } ${ params ? '&' : '' } ${ queries . map ( q => 'q=' + q ) . join ( '&' ) } ` ;
550
+ }
551
+
538
552
void ( async ( ) => {
539
553
const loader = new DefaultTestFileLoader ( ) ;
540
554
@@ -546,14 +560,17 @@ void (async () => {
546
560
isFullCTS = qs . length === 1 && qs [ 0 ] === rootQuerySpec ;
547
561
548
562
// Update the URL bar to match the exact current options.
549
- const updateURLWithCurrentOptions = ( ) => {
550
- const search = prepareParams ( optionsToRecord ( options ) ) ;
563
+ const updateURLsWithCurrentOptions = ( ) => {
564
+ const params = prepareParams ( optionsToRecord ( options ) ) ;
551
565
let url = `${ window . location . origin } ${ window . location . pathname } ` ;
552
- // Add in q separately to avoid escaping punctuation marks.
553
- url += `?${ search } ${ search ? '&' : '' } ${ qs . map ( q => 'q=' + q ) . join ( '&' ) } ` ;
566
+ url += createSearchQuery ( qs , params ) ;
554
567
window . history . replaceState ( null , '' , url . toString ( ) ) ;
568
+ document . querySelectorAll ( `a[alt=${ kOpenTestLinkAltText } ]` ) . forEach ( elem => {
569
+ const a = elem as HTMLAnchorElement ;
570
+ const qs = new URLSearchParams ( a . search ) . getAll ( 'q' ) ;
571
+ a . search = createSearchQuery ( qs , params ) ;
572
+ } ) ;
555
573
} ;
556
- updateURLWithCurrentOptions ( ) ;
557
574
558
575
const addOptionsToPage = ( options : StandaloneOptions , optionsInfos : StandaloneOptionsInfos ) => {
559
576
const optionsElem = $ ( 'table#options>tbody' ) [ 0 ] ;
@@ -565,14 +582,14 @@ void (async () => {
565
582
. prop ( 'checked' , optionValues [ optionName ] as boolean )
566
583
. on ( 'change' , function ( ) {
567
584
optionValues [ optionName ] = ( this as HTMLInputElement ) . checked ;
568
- updateURLWithCurrentOptions ( ) ;
585
+ updateURLsWithCurrentOptions ( ) ;
569
586
} ) ;
570
587
} ;
571
588
572
589
const createSelect = ( optionName : string , info : StandaloneOptionInfo ) => {
573
590
const select = $ ( '<select>' ) . on ( 'change' , function ( ) {
574
591
optionValues [ optionName ] = ( this as HTMLInputElement ) . value ;
575
- updateURLWithCurrentOptions ( ) ;
592
+ updateURLsWithCurrentOptions ( ) ;
576
593
} ) ;
577
594
const currentValue = optionValues [ optionName ] ;
578
595
for ( const { value, description } of info . selectValueDescriptions ! ) {
0 commit comments