@override
(env)
| 697 | |
| 698 | /** @override */ |
| 699 | setup(env) { |
| 700 | const spec = this.spec.amp; |
| 701 | const {win} = env; |
| 702 | let completePromise; |
| 703 | |
| 704 | // Configure mode. |
| 705 | configureAmpTestMode(win); |
| 706 | |
| 707 | // AMP requires canonical URL. |
| 708 | const link = win.document.createElement('link'); |
| 709 | link.setAttribute('rel', 'canonical'); |
| 710 | link.setAttribute('href', spec.canonicalUrl || window.location.href); |
| 711 | win.document.head.appendChild(link); |
| 712 | |
| 713 | if (!spec.runtimeOn) { |
| 714 | win.name = '__AMP__off=1'; |
| 715 | } |
| 716 | const ampdocType = spec.ampdoc || 'single'; |
| 717 | const singleDoc = ampdocType == 'single' || ampdocType == 'fie'; |
| 718 | installDocService(win, singleDoc, spec.params); |
| 719 | const ampdocService = Services.ampdocServiceFor(win); |
| 720 | env.ampdocService = ampdocService; |
| 721 | installExtensionsService(win); |
| 722 | env.extensions = Services.extensionsFor(win); |
| 723 | installBuiltinElements(win); |
| 724 | installRuntimeServices(win); |
| 725 | env.flushVsync = function () { |
| 726 | win.__AMP_SERVICES.vsync.obj.runScheduledTasks_(); |
| 727 | }; |
| 728 | if (singleDoc) { |
| 729 | // Install AMP CSS for main runtime, if it hasn't been installed yet. |
| 730 | completePromise = installRuntimeStylesPromise(win); |
| 731 | const ampdoc = ampdocService.getAmpDoc(win.document); |
| 732 | env.ampdoc = ampdoc; |
| 733 | installAmpdocServices(ampdoc); |
| 734 | adopt(win); |
| 735 | Services.resourcesForDoc(ampdoc).ampInitComplete(); |
| 736 | // Ensure cached meta name/content pairs are cleared before each test |
| 737 | ampdoc.meta_ = null; |
| 738 | maybeTrackImpression(win); |
| 739 | } else if (ampdocType == 'multi' || ampdocType == 'shadow') { |
| 740 | adoptShadowMode(win); |
| 741 | // Notice that ampdoc's themselves install runtime styles in shadow roots. |
| 742 | // Thus, not changes needed here. |
| 743 | } |
| 744 | const extensions = []; |
| 745 | if (spec.extensions) { |
| 746 | spec.extensions.forEach((extensionIdWithVersion) => { |
| 747 | const tuple = extensionIdWithVersion.split(':'); |
| 748 | const extensionId = tuple[0]; |
| 749 | // Default to 0.1 if no version was provided. |
| 750 | const extensionVersion = tuple[1] || '0.1'; |
| 751 | extensions.push({extensionId, extensionVersion}); |
| 752 | const installer = |
| 753 | extensionsBuffer[`${extensionId}:${extensionVersion}`]; |
| 754 | if (installer) { |
| 755 | if (env.ampdoc) { |
| 756 | env.ampdoc.declareExtension(extensionId, extensionVersion); |
no test coverage detected