// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {getBrowserAndPages, getTestServerPort, platform} from '../../shared/helper.js';

const fontsByPlatform = {
  'mac': 'Helvetica Neue',
  'win32': 'Tahoma',
  'linux': 'Arial',
};

export const loadComponentDocExample = async (urlComponent: string) => {
  const {frontend} = getBrowserAndPages();
  const url = new URL(`http://localhost:${getTestServerPort()}/front_end/ui/components/docs/${urlComponent}`);
  url.searchParams.set('fontFamily', fontsByPlatform[platform]);
  await frontend.goto(url.toString(), {
    waitUntil: 'networkidle0',
  });
};

const SHOULD_GATHER_COVERAGE_INFORMATION = process.env.COVERAGE === '1';

export const preloadForCodeCoverage = (name: string) => {
  if (!SHOULD_GATHER_COVERAGE_INFORMATION) {
    return;
  }

  before(async function() {
    this.timeout(0);
    const {frontend} = getBrowserAndPages();
    await frontend.setExtraHTTPHeaders({
      'devtools-compute-coverage': '1',
    });
    await loadComponentDocExample(name);
    await frontend.setExtraHTTPHeaders({});
  });
};

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {getBrowserAndPages, getTestServerPort, platform} from '../../shared/helper.js';

const fontsByPlatform = {
  'mac': 'Helvetica Neue',
  'win32': 'Tahoma',
  'linux': '"Liberation Sans"',
};

export const loadComponentDocExample = async (urlComponent: string) => {
  const {frontend} = getBrowserAndPages();
  const url = new URL(`http://localhost:${getTestServerPort()}/front_end/ui/components/docs/${urlComponent}`);
  url.searchParams.set('fontFamily', fontsByPlatform[platform]);
  await frontend.goto(url.toString(), {
    waitUntil: 'networkidle0',
  });
};

const SHOULD_GATHER_COVERAGE_INFORMATION = process.env.COVERAGE === '1';

export const preloadForCodeCoverage = (name: string) => {
  if (!SHOULD_GATHER_COVERAGE_INFORMATION) {
    return;
  }

  before(async function() {
    this.timeout(0);
    const {frontend} = getBrowserAndPages();
    await frontend.setExtraHTTPHeaders({
      'devtools-compute-coverage': '1',
    });
    await loadComponentDocExample(name);
    await frontend.setExtraHTTPHeaders({});
  });
};

Set linux font for interaction tests to Liberation Sans
Set linux font for interaction tests to Liberation Sans

This font is shared between gLinux and the bots.

Bug: none;
Change-Id: I4a69bce005e876502130661e2844037638069b2d
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3168265
Reviewed-by: Paul Lewis <8915f5d5c39a08c5a3e8a8d7314756e4580816f9@chromium.org>
Commit-Queue: Jack Franklin <993fcadce4d04090da2fefd557a0995e7966c8d5@chromium.org>
