text: /**
   * Copyright 2016 The AMP HTML Authors. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS-IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import {AmpAdNetworkGmosspImpl} from '../amp-ad-network-gmossp-impl';
  import {
    AmpAdUIHandler, // eslint-disable-line no-unused-vars
  } from '../../../amp-ad/0.1/amp-ad-ui';
  import {
    AmpAdXOriginIframeHandler, // eslint-disable-line no-unused-vars
  } from '../../../amp-ad/0.1/amp-ad-xorigin-iframe-handler';
  import {createElementWithAttributes} from '../../../../src/dom';
  import {gmosspIsA4AEnabled} from '../gmossp-a4a-config';
  
  describes.realWin('gmossp-a4a-config', {amp: false}, env => {
    let doc;
    let win;
    beforeEach(() => {
      win = env.win;
      doc = win.document;
    });
    it('should pass a4a config predicate', () => {
      const element = createElementWithAttributes(doc, 'amp-ad', {
        src: 'https://sp.gmossp-sp.jp/ads/ssp.ad?space_id=33303&is_a4a=1',
        'data-use-a4a': 'true',
      });
      expect(gmosspIsA4AEnabled(win, element)).to.be.true;
    });
    it('should pass a4a config predicate', () => {
      const element = createElementWithAttributes(doc, 'amp-ad', {
        src:
          'https://amp.sp.gmossp-sp.jp/_a4a/ads/ssp.ad?space_id=33303&is_a4a=1',
        'data-use-a4a': 'true',
      });
      expect(gmosspIsA4AEnabled(win, element)).to.be.true;
    });
    it('should fail a4a config predicate due to useRemoteHtml', () => {
      const element = createElementWithAttributes(doc, 'amp-ad', {
        src:
          'https://amp.sp.gmossp-sp.jp/_a4a/ads/ssp.ad?space_id=33303&is_a4a=1',
        'data-use-a4a': 'true',
      });
      const useRemoteHtml = true;
      expect(gmosspIsA4AEnabled(win, element, useRemoteHtml)).to.be.false;
    });
    it('should fail a4a config predicate due to missing use-a4a', () => {
      const element = createElementWithAttributes(doc, 'amp-ad', {
        src: 'https://sp.gmossp-sp.jp/ads/ssp.ad?space_id=33303&is_a4a=1',
      });
      expect(gmosspIsA4AEnabled(win, element)).to.be.false;
    });
    it('should fail a4a config predicate due to missing src', () => {
      const element = createElementWithAttributes(doc, 'amp-ad', {
        'data-use-a4a': 'true',
      });
      expect(gmosspIsA4AEnabled(win, element)).to.be.false;
    });
    it('should fail a4a config predicate due to invalid src', () => {
      const element = createElementWithAttributes(doc, 'amp-ad', {
        src: 'https://evil.com?hello=world&https://sp.gmossp-sp.jp',
        'data-use-a4a': 'true',
      });
      expect(gmosspIsA4AEnabled(win, element)).to.be.false;
    });
  });
  
  describes.realWin(
    'amp-ad-network-gmossp-impl',
    {
      amp: {
        extensions: ['amp-ad-network-gmossp-impl'],
      },
    },
    env => {
      let win, doc;
      let gmosspImpl;
      let gmosspImplElem;
  
      beforeEach(() => {
        win = env.win;
        doc = win.document;
        gmosspImplElem = doc.createElement('amp-ad');
        gmosspImplElem.setAttribute('type', 'gmossp');
        gmosspImplElem.setAttribute('data-use-a4a', 'true');
        env.sandbox
          .stub(AmpAdNetworkGmosspImpl.prototype, 'getSigningServiceNames')
          .callsFake(() => {
            return ['google'];
          });
        gmosspImpl = new AmpAdNetworkGmosspImpl(gmosspImplElem);
      });
  
      describe('#isValidElement', () => {
        it('should be valid', () => {
          gmosspImplElem.setAttribute(
            'src',
            'https://amp.sp.gmossp-sp.jp/_a4a/ads/ssp.ad?space_id=33303&is_a4a=1'
          );
          expect(gmosspImpl.isValidElement()).to.be.true;
        });
        it('should be valid', () => {
          gmosspImplElem.setAttribute(
            'src',
            'https://sp.gmossp-sp.jp/ads/ssp.ad?space_id=33303&is_a4a=1'
          );
          expect(gmosspImpl.isValidElement()).to.be.true;
        });
        it('should NOT be valid (impl tag name)', () => {
          gmosspImplElem = doc.createElement('amp-ad-network-gmossp-impl');
          gmosspImplElem.setAttribute('type', 'gmossp');
          gmosspImpl = new AmpAdNetworkGmosspImpl(gmosspImplElem);
          expect(gmosspImpl.isValidElement()).to.be.false;
        });
      });
  
      describe('#getAdUrl', () => {
        it('should be valid', () => {
          gmosspImplElem.setAttribute(
            'src',
            'https://amp.sp.gmossp-sp.jp/_a4a/ads/ssp.ad?space_id=33303&is_a4a=1'
          );
          const base = 'https://amp.sp.gmossp-sp.jp/_a4a/ads/ssp.ad?';
          expect(gmosspImpl.getAdUrl().substring(0, base.length)).to.equal(base);
        });
        it('should be valid', () => {
          gmosspImplElem.setAttribute(
            'src',
            'https://sp.gmossp-sp.jp/ads/ssp.ad?space_id=33303&is_a4a=1'
          );
          const base = 'https://amp.sp.gmossp-sp.jp/_a4a/ads/ssp.ad?';
          expect(gmosspImpl.getAdUrl().substring(0, base.length)).to.equal(base);
        });
      });
    }
  );
  