File: smoke_test.py

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 3,421 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import pytest

from chrome.test.variations import drivers
from chrome.test.variations import fixtures
from chrome.test.variations.fixtures import test_options
from chrome.test.variations.test_utils.driver import DriverUtil
from http.server import HTTPServer
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait


def test_load_simple_url(driver_factory: drivers.DriverFactory,
                         local_http_server: HTTPServer,
                         seed_locator: fixtures.SeedLocator,
                         test_options: test_options.TestOptions,
                         add_tag: fixtures.result_sink.AddTag,
                         add_features: fixtures.features.AddFeatures):
  url = (f'http://localhost:{local_http_server.server_port}')
  with driver_factory.create_driver(
    seed_file=seed_locator.get_seed()) as driver:
    versions = driver.execute_cdp_cmd(cmd='Browser.getVersion', cmd_args={})
    # https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-getVersion
    # expecting { 'product': 'Chrome/120.0.6090.0' }
    version = versions['product'].split('/')[1]
    add_tag('launched_version', version)
    driver.set_window_size(800, 600)
    driver.get(url)
    WebDriverWait(driver, 5).until(
      EC.presence_of_element_located((By.TAG_NAME, 'body')))

    # log features
    features = DriverUtil(driver, test_options).get_features()
    add_features(features)


def test_basic_rendering(driver_factory: drivers.DriverFactory,
                         local_http_server: HTTPServer,
                         seed_locator: fixtures.SeedLocator,
                         test_options: test_options.TestOptions,
                         skia_gold_util: fixtures.VariationsSkiaGoldUtil,
                         add_features: fixtures.features.AddFeatures):
  url = (f'http://localhost:{local_http_server.server_port}')
  with driver_factory.create_driver(
    seed_file=seed_locator.get_seed()) as driver:
    driver.set_window_size(800, 600)
    driver.get(url)
    driver_factory.wait_for_screenshot()
    body = WebDriverWait(driver, 5).until(
      EC.presence_of_element_located((By.TAG_NAME, 'body')))

    status, error_msg = skia_gold_util.compare(
      name='body',
      png_data=skia_gold_util.screenshot_from_element(body))

    assert status == 0, error_msg

    # log features
    features = DriverUtil(driver, test_options).get_features()
    add_features(features)


def test_load_crash_seed(driver_factory: drivers.DriverFactory,
                         local_http_server: HTTPServer,
                         seed_locator: fixtures.SeedLocator):
  url = (f'http://localhost:{local_http_server.server_port}')
  # Launch Chrome normally.
  with driver_factory.create_driver() as driver:
    driver.get(url)
    WebDriverWait(driver, 5).until(
      EC.presence_of_element_located((By.TAG_NAME, 'body')))

  # Launch again with bad seed, expecting a crash.
  with pytest.raises(WebDriverException):
    with driver_factory.create_driver(
      seed_file=seed_locator.get_seed(fixtures.SeedName.CRASH)
      ) as driver:
      driver.get(url)