@@ -128,11 +128,49 @@ describe('Referer detection', () => {
128
128
numIframes : 0 ,
129
129
stack : [ 'https://example.com/some/page' ] ,
130
130
canonicalUrl : 'https://example.com/canonical/page' ,
131
- page : 'https://example.com/canonical /page' ,
131
+ page : 'https://example.com/some /page' ,
132
132
ref : 'https://othersite.com/' ,
133
133
domain : 'example.com'
134
134
} ) ;
135
135
} ) ;
136
+
137
+ it ( 'Should set page and canonical to pageUrl value set in config if present, even if canonical url is also present in head' , ( ) => {
138
+ config . setConfig ( { 'pageUrl' : 'https://www.set-from-config.com/path' } ) ;
139
+ const testWindow = buildWindowTree ( [ 'https://example.com/some/page' ] , 'https://othersite.com/' , 'https://example.com/canonical/page' ) ,
140
+ result = detectReferer ( testWindow ) ( ) ;
141
+
142
+ sinon . assert . match ( result , {
143
+ topmostLocation : 'https://example.com/some/page' ,
144
+ location : 'https://example.com/some/page' ,
145
+ reachedTop : true ,
146
+ isAmp : false ,
147
+ numIframes : 0 ,
148
+ stack : [ 'https://example.com/some/page' ] ,
149
+ canonicalUrl : 'https://www.set-from-config.com/path' ,
150
+ page : 'https://www.set-from-config.com/path' ,
151
+ ref : 'https://othersite.com/' ,
152
+ domain : 'www.set-from-config.com'
153
+ } ) ;
154
+ } ) ;
155
+
156
+ it ( 'Should set page with query params if canonical url is present without query params but the current page does have them' , ( ) => {
157
+ config . setConfig ( { 'pageUrl' : 'https://www.set-from-config.com/path' } ) ;
158
+ const testWindow = buildWindowTree ( [ 'https://example.com/some/page?query1=123&query2=456' ] , 'https://othersite.com/' , 'https://example.com/canonical/page' ) ,
159
+ result = detectReferer ( testWindow ) ( ) ;
160
+
161
+ sinon . assert . match ( result , {
162
+ topmostLocation : 'https://example.com/some/page?query1=123&query2=456' ,
163
+ location : 'https://example.com/some/page?query1=123&query2=456' ,
164
+ reachedTop : true ,
165
+ isAmp : false ,
166
+ numIframes : 0 ,
167
+ stack : [ 'https://example.com/some/page?query1=123&query2=456' ] ,
168
+ canonicalUrl : 'https://www.set-from-config.com/path' ,
169
+ page : 'https://www.set-from-config.com/path?query1=123&query2=456' ,
170
+ ref : 'https://othersite.com/' ,
171
+ domain : 'www.set-from-config.com'
172
+ } ) ;
173
+ } ) ;
136
174
} ) ;
137
175
138
176
describe ( 'Friendly iframes' , ( ) => {
@@ -174,7 +212,7 @@ describe('Referer detection', () => {
174
212
'https://example.com/third/page'
175
213
] ,
176
214
canonicalUrl : 'https://example.com/canonical/page' ,
177
- page : 'https://example.com/canonical /page' ,
215
+ page : 'https://example.com/some /page' ,
178
216
ref : 'https://othersite.com/' ,
179
217
domain : 'example.com'
180
218
} ) ;
@@ -317,7 +355,7 @@ describe('Referer detection', () => {
317
355
'https://ad-iframe.ampproject.org/ad'
318
356
] ,
319
357
canonicalUrl : 'https://example.com/some/page/' ,
320
- page : 'https://example.com/some/page/' ,
358
+ page : 'https://example.com/some/page/amp/ ' ,
321
359
ref : null ,
322
360
domain : 'example.com'
323
361
} ) ;
@@ -344,7 +382,7 @@ describe('Referer detection', () => {
344
382
'https://ad-iframe.ampproject.org/ad'
345
383
] ,
346
384
canonicalUrl : 'https://example.com/some/page/' ,
347
- page : 'https://example.com/some/page/' ,
385
+ page : 'https://example.com/some/page/amp/ ' ,
348
386
ref : null ,
349
387
domain : 'example.com'
350
388
} ) ;
@@ -384,7 +422,7 @@ describe('Referer detection', () => {
384
422
'https://ad-iframe.ampproject.org/ad'
385
423
] ,
386
424
canonicalUrl : 'https://example.com/some/page/' ,
387
- page : 'https://example.com/some/page/' ,
425
+ page : 'https://example.com/some/page/amp/ ' ,
388
426
ref : null ,
389
427
domain : 'example.com' ,
390
428
} ) ;
@@ -412,7 +450,7 @@ describe('Referer detection', () => {
412
450
'https://ad-iframe.ampproject.org/ad'
413
451
] ,
414
452
canonicalUrl : 'https://example.com/some/page/' ,
415
- page : 'https://example.com/some/page/' ,
453
+ page : 'https://example.com/some/page/amp/ ' ,
416
454
ref : null ,
417
455
domain : 'example.com'
418
456
} ) ;
@@ -441,7 +479,7 @@ describe('Referer detection', () => {
441
479
'https://ad-iframe.ampproject.org/ad'
442
480
] ,
443
481
canonicalUrl : 'https://example.com/some/page/' ,
444
- page : 'https://example.com/some/page/' ,
482
+ page : 'https://example.com/some/page/amp/ ' ,
445
483
ref : null ,
446
484
domain : 'example.com' ,
447
485
} ) ;
0 commit comments