# Copyright 2013 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.

from core import perf_benchmark

from measurements import startup
import page_sets
from telemetry import benchmark


class _StartupCold(perf_benchmark.PerfBenchmark):
  """Measures cold startup time with a clean profile."""
  options = {'pageset_repeat': 5}

  @classmethod
  def Name(cls):
    return 'startup'

  def CreatePageTest(self, options):
    return startup.Startup(cold=True)


class _StartupWarm(perf_benchmark.PerfBenchmark):
  """Measures warm startup time with a clean profile."""
  options = {'pageset_repeat': 20}

  @classmethod
  def Name(cls):
    return 'startup'

  @classmethod
  def ValueCanBeAddedPredicate(cls, _, is_first_result):
    return not is_first_result

  def CreatePageTest(self, options):
    return startup.Startup(cold=False)


@benchmark.Enabled('has tabs')
@benchmark.Disabled('snowleopard') # crbug.com/336913
class StartupColdBlankPage(_StartupCold):
  """Measures cold startup time with a clean profile."""
  tag = 'cold'
  page_set = page_sets.BlankPageSet

  @classmethod
  def Name(cls):
    return 'startup.cold.blank_page'


@benchmark.Enabled('has tabs')
class StartupWarmBlankPage(_StartupWarm):
  """Measures warm startup time with a clean profile."""
  tag = 'warm'
  page_set = page_sets.BlankPageSet

  @classmethod
  def Name(cls):
    return 'startup.warm.blank_page'

@benchmark.Enabled('has tabs')
@benchmark.Enabled('win', 'linux', 'mac')
@benchmark.Disabled('reference', 'android')  # http://crbug.com/481919
class StartupLargeProfileColdBlankPage(_StartupCold):
  """Measures cold startup time with a large profile."""
  tag = 'cold'
  page_set = page_sets.BlankPageSetWithLargeProfile
  options = {'pageset_repeat': 1}

  def __init__(self, max_failures=None):
    super(StartupLargeProfileColdBlankPage, self).__init__(max_failures)

  def SetExtraBrowserOptions(self, options):
    options.browser_startup_timeout = 10 * 60

  @classmethod
  def Name(cls):
    return 'startup.large_profile.cold.blank_page'

@benchmark.Enabled('has tabs')
@benchmark.Enabled('win', 'linux', 'mac')
@benchmark.Disabled('reference', 'android')  # http://crbug.com/481919
class StartupLargeProfileWarmBlankPage(_StartupWarm):
  """Measures warm startup time with a large profile."""
  tag = 'warm'
  page_set = page_sets.BlankPageSetWithLargeProfile
  options = {'pageset_repeat': 1}

  def __init__(self, max_failures=None):
    super(StartupLargeProfileWarmBlankPage, self).__init__(max_failures)

  def SetExtraBrowserOptions(self, options):
    options.browser_startup_timeout = 10 * 60

  @classmethod
  def Name(cls):
    return 'startup.large_profile.warm.blank_page'

# Copyright 2013 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.

from core import perf_benchmark

from measurements import startup
import page_sets
from telemetry import benchmark


class _StartupCold(perf_benchmark.PerfBenchmark):
  """Measures cold startup time with a clean profile."""
  options = {'pageset_repeat': 5}

  @classmethod
  def Name(cls):
    return 'startup'

  def CreatePageTest(self, options):
    return startup.Startup(cold=True)


class _StartupWarm(perf_benchmark.PerfBenchmark):
  """Measures warm startup time with a clean profile."""
  options = {'pageset_repeat': 20}

  @classmethod
  def Name(cls):
    return 'startup'

  @classmethod
  def ValueCanBeAddedPredicate(cls, _, is_first_result):
    return not is_first_result

  def CreatePageTest(self, options):
    return startup.Startup(cold=False)


@benchmark.Enabled('has tabs')
@benchmark.Disabled('snowleopard') # crbug.com/336913
class StartupColdBlankPage(_StartupCold):
  """Measures cold startup time with a clean profile."""
  tag = 'cold'
  page_set = page_sets.BlankPageSet

  @classmethod
  def Name(cls):
    return 'startup.cold.blank_page'


@benchmark.Enabled('has tabs')
class StartupWarmBlankPage(_StartupWarm):
  """Measures warm startup time with a clean profile."""
  tag = 'warm'
  page_set = page_sets.BlankPageSet

  @classmethod
  def Name(cls):
    return 'startup.warm.blank_page'

@benchmark.Enabled('has tabs')
@benchmark.Enabled('win', 'linux', 'mac')
@benchmark.Disabled('reference', 'android')  # http://crbug.com/481919
class StartupLargeProfileColdBlankPage(_StartupCold):
  """Measures cold startup time with a large profile."""
  tag = 'cold'
  page_set = page_sets.BlankPageSetWithLargeProfile
  options = {'pageset_repeat': 3}

  def __init__(self, max_failures=None):
    super(StartupLargeProfileColdBlankPage, self).__init__(max_failures)

  def SetExtraBrowserOptions(self, options):
    options.browser_startup_timeout = 10 * 60

  @classmethod
  def Name(cls):
    return 'startup.large_profile.cold.blank_page'

@benchmark.Enabled('has tabs')
@benchmark.Enabled('win', 'linux', 'mac')
@benchmark.Disabled('reference', 'android')  # http://crbug.com/481919
class StartupLargeProfileWarmBlankPage(_StartupWarm):
  """Measures warm startup time with a large profile."""
  tag = 'warm'
  page_set = page_sets.BlankPageSetWithLargeProfile
  options = {'pageset_repeat': 4}

  def __init__(self, max_failures=None):
    super(StartupLargeProfileWarmBlankPage, self).__init__(max_failures)

  def SetExtraBrowserOptions(self, options):
    options.browser_startup_timeout = 10 * 60

  @classmethod
  def Name(cls):
    return 'startup.large_profile.warm.blank_page'

Increase page_set repeat for large profile tests.