From b7f7f2c775ddf96520d883a3e408e41df2b1ac3e Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Fri, 28 Oct 2016 13:55:44 -0700 Subject: [PATCH] Merge --- src/service/document-info-impl.js | 16 +++++++++++----- test/functional/test-document-info.js | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/service/document-info-impl.js b/src/service/document-info-impl.js index c68fe23e1a42..09d9e3c992a4 100644 --- a/src/service/document-info-impl.js +++ b/src/service/document-info-impl.js @@ -61,10 +61,10 @@ export class DocInfo { if (this.info_) { return this.info_; } - - const url = this.ampdoc_.getUrl(); + const ampdoc = this.ampdoc_; + const url = ampdoc.getUrl(); const sourceUrl = getSourceUrl(url); - const rootNode = this.ampdoc_.getRootNode(); + const rootNode = ampdoc.getRootNode(); let canonicalUrl = rootNode && rootNode.AMP && rootNode.AMP.canonicalUrl; if (!canonicalUrl) { @@ -73,8 +73,14 @@ export class DocInfo { ? parseUrl(canonicalTag.href).href : sourceUrl; } - const pageViewId = getPageViewId(this.ampdoc_.win); - return this.info_ = {url, sourceUrl, canonicalUrl, pageViewId}; + const pageViewId = getPageViewId(ampdoc.win); + return this.info_ = { + get sourceUrl() { + return getSourceUrl(ampdoc.getUrl()); + }, + canonicalUrl, + pageViewId, + }; } } diff --git a/test/functional/test-document-info.js b/test/functional/test-document-info.js index 88bcaccadab8..4ddd4134272a 100644 --- a/test/functional/test-document-info.js +++ b/test/functional/test-document-info.js @@ -69,8 +69,6 @@ describe('document-info', () => { win.document.defaultView = win; installDocService(win, true); installDocumentInfoServiceForDoc(win.document); - expect(documentInfoForDoc(win.document).url).to.equal( - 'https://cdn.ampproject.org/v/www.origin.com/foo/?f=0'); expect(documentInfoForDoc(win.document).sourceUrl).to.equal( 'http://www.origin.com/foo/?f=0'); }); @@ -88,6 +86,7 @@ describe('document-info', () => { }; win.document.defaultView = win; installDocService(win, true); + installDocumentInfoServiceForDoc(win.document); expect(documentInfoForDoc(win.document).sourceUrl).to.equal( 'http://www.origin.com/foo/?f=0'); win.location.href = 'https://cdn.ampproject.org/v/www.origin.com/foo/?f=1';