3
3
// found in the LICENSE file.
4
4
5
5
import * as Host from '../../core/host/host.js' ;
6
+ import * as Platform from '../../core/platform/platform.js' ;
6
7
import type * as Root from '../../core/root/root.js' ;
7
8
import { updateHostConfig } from '../../testing/EnvironmentHelpers.js' ;
8
9
9
10
import * as UI from './legacy.js' ;
10
11
12
+ const { urlString} = Platform . DevToolsPath ;
13
+
11
14
describe ( 'UIUtils' , ( ) => {
12
15
describe ( 'openInNewTab' , ( ) => {
13
16
const { openInNewTab} = UI . UIUtils ;
@@ -42,13 +45,7 @@ describe('UIUtils', () => {
42
45
43
46
openInNewTab ( url ) ;
44
47
45
- sinon . assert . calledOnceWithMatch ( stub , sinon . match ( value => {
46
- try {
47
- return new URL ( value ) . searchParams . get ( 'utm_source' ) === 'unittests' ;
48
- } catch {
49
- return false ;
50
- }
51
- } , 'doesn\'t have `utm_source=unittests` search parameter' ) ) ;
48
+ sinon . assert . calledOnceWithExactly ( stub , urlString `${ url } ` ) ;
52
49
stub . restore ( ) ;
53
50
}
54
51
} ) ;
@@ -67,13 +64,8 @@ describe('UIUtils', () => {
67
64
68
65
openInNewTab ( url ) ;
69
66
70
- sinon . assert . calledOnceWithMatch ( stub , sinon . match ( value => {
71
- try {
72
- return new URL ( value ) . searchParams . get ( 'utm_source' ) === 'devtools' ;
73
- } catch {
74
- return false ;
75
- }
76
- } , 'doesn\'t have `utm_source=devtools` search parameter' ) ) ;
67
+ sinon . assert . calledOnce ( stub ) ;
68
+ assert . strictEqual ( new URL ( stub . args [ 0 ] [ 0 ] ) . searchParams . get ( 'utm_source' ) , 'devtools' ) ;
77
69
stub . restore ( ) ;
78
70
}
79
71
} ) ;
@@ -101,43 +93,13 @@ describe('UIUtils', () => {
101
93
102
94
openInNewTab ( url ) ;
103
95
104
- sinon . assert . calledOnceWithMatch ( stub , sinon . match ( value => {
105
- try {
106
- return new URL ( value ) . searchParams . get ( 'utm_campaign' ) === channel ;
107
- } catch {
108
- return false ;
109
- }
110
- } , `doesn't have \`utm_campaign=${ channel } \` search parameter` ) ) ;
96
+ sinon . assert . calledOnce ( stub ) ;
97
+ assert . strictEqual ( new URL ( stub . args [ 0 ] [ 0 ] ) . searchParams . get ( 'utm_campaign' ) , channel ) ;
111
98
stub . restore ( ) ;
112
99
}
113
100
}
114
101
} ) ;
115
102
116
- it ( 'adds `utm_medium=referral` search parameter to Google documentation set links' , ( ) => {
117
- const URLs = [
118
- 'http://developer.chrome.com/docs/devtools/workspaces/' ,
119
- 'http://developers.google.com/learn/' ,
120
- 'http://web.dev/' ,
121
- 'https://developer.chrome.com/docs/devtools/' ,
122
- 'https://developers.google.com/community/' ,
123
- 'https://web.dev/baseline/' ,
124
- ] ;
125
- for ( const url of URLs ) {
126
- const stub = sinon . stub ( InspectorFrontendHostInstance , 'openInNewTab' ) ;
127
-
128
- openInNewTab ( url ) ;
129
-
130
- sinon . assert . calledOnceWithMatch ( stub , sinon . match ( value => {
131
- try {
132
- return new URL ( value ) . searchParams . get ( 'utm_medium' ) === 'referral' ;
133
- } catch {
134
- return false ;
135
- }
136
- } , 'doesn\'t have `utm_medium=referral` search parameter' ) ) ;
137
- stub . restore ( ) ;
138
- }
139
- } ) ;
140
-
141
103
it ( 'correctly preserves anchors' , ( ) => {
142
104
updateHostConfig ( { channel : 'stable' } ) ;
143
105
const stub = sinon . stub ( InspectorFrontendHostInstance , 'openInNewTab' ) ;
0 commit comments