This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
mirrored from https://chromium.googlesource.com/chromium/dom-distiller
-
Notifications
You must be signed in to change notification settings - Fork 82
/
run_jstests.py
executable file
·94 lines (76 loc) · 3.2 KB
/
run_jstests.py
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
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Runs DomDistillers jstests.
This uses ChromeDriver (https://sites.google.com/a/chromium.org/chromedriver/) to run the jstests.
This requires that the ChromeDriver executable is on the PATH and that Selenium WebDriver is
installed.
In addition, ChromeDriver assumes that Chrome is available at /usr/bin/google-chrome.
"""
import argparse
import os
import sys
import time
import urllib
try:
from selenium import webdriver
except:
print 'ERROR:'
print 'Couldn\'t import webdriver. Please run `sudo ./install-build-deps.sh`.'
sys.exit(1)
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--filter', help='See gtest_filter syntax.')
parser.add_argument('--repeat', type=int, default=1, help='Number of times to repeat the tests.')
parser.add_argument('--debug_level', help='Verbosity level of debug messages.')
parser.add_argument('--no_console_log',
action='store_true', help='Disable the console log output.')
parser.add_argument('--shuffle', type=int, help='Set to 1 to run test cases in random order.')
parser.add_argument('--no_sandbox', type=int, help='Set to 1 to add --no-sandbox option to Chrome.')
options = parser.parse_args(argv)
params = {}
if options.filter:
params['filter'] = options.filter
if options.debug_level:
params['debug_level'] = int(options.debug_level)
if options.no_console_log:
params['console_log'] = '0'
if options.shuffle:
params['shuffle'] = options.shuffle
image_loaded = "return window.image_loaded"
test_runner = "return org.chromium.distiller.JsTestEntry.run()"
test_html = os.path.abspath(os.path.join(os.path.dirname(__file__), "war", "test.html"))
test_html += "?" + urllib.urlencode(params)
chrome_options = webdriver.ChromeOptions()
# Travis-CI uses OpenVZ containers which are incompatible with the sandbox technology.
# See https://code.google.com/p/chromium/issues/detail?id=31077 for more information.
# Ref: https://github.com/travis-ci/travis-ci/issues/938#issuecomment-16336150
# Drone.io also has issues running newer versions of Chrome.
# Ref: http://crbug.com/495254
if options.no_sandbox:
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(chrome_options=chrome_options)
for i in range(options.repeat):
driver.get("file://" + test_html)
while not driver.execute_script(image_loaded):
print "Wait for image loading..."
time.sleep(0.1)
start = time.time()
result = driver.execute_script(test_runner)
end = time.time()
if not result['success'] or options.repeat == i+1:
print result['log'].encode('utf-8')
print 'Tests run: %d, Failures: %d, Skipped: %d, Time elapsed: %0.3f sec' % (result['numTests'],
result['failed'], result['skipped'], end - start)
if not result['success']:
driver.quit()
if options.repeat > 1:
print 'Failed at run #%d/%d' % (i+1, options.repeat)
return 1
driver.quit()
if options.repeat > 1:
print 'Passed %d runs' % (options.repeat)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))