• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Runs Canvasmark HTML5, Canvas 2D rendering and javascript benchmark.
6
7CanvasMark tests the HTML5 <canvas> rendering performance for commonly used
8operations in HTML5 games: bitmaps, canvas drawing, alpha blending, polygon
9fills, shadows and text functions.
10"""
11
12import os
13
14from telemetry import test
15from telemetry.page import page_measurement
16from telemetry.page import page_set
17
18
19class _CanvasMarkMeasurement(page_measurement.PageMeasurement):
20
21  def WillNavigateToPage(self, page, tab):
22    page.script_to_evaluate_on_commit = """
23        var __results = [];
24        var __real_log = window.console.log;
25        window.console.log = function(msg) {
26          __results.push(msg);
27          __real_log.apply(this, [msg]);
28        }
29        """
30
31  def MeasurePage(self, _, tab, results):
32    tab.WaitForJavaScriptExpression('__results.length == 8', 300)
33    results_log = tab.EvaluateJavaScript('__results')
34    total = 0
35    for output in results_log:
36      # Split the results into score and test name.
37      # results log e.g., "489 [Test 1 - Asteroids - Bitmaps]"
38      score_and_name = output.split(' [', 2)
39      assert len(score_and_name) == 2, \
40        'Unexpected result format "%s"' % score_and_name
41      score = int(score_and_name[0])
42      name = score_and_name[1][:-1]
43      results.Add(name, 'score', score, data_type='unimportant')
44      # Aggregate total score for all tests.
45      total += score
46    results.Add('Score', 'score', total)
47
48
49class CanvasMark(test.Test):
50  test = _CanvasMarkMeasurement
51
52  def CreatePageSet(self, options):
53    ps = page_set.PageSet(
54      file_path=os.path.abspath(__file__),
55      archive_data_file='../page_sets/data/canvasmark.json',
56      make_javascript_deterministic=False)
57    ps.AddPageWithDefaultRunNavigate(
58      'http://www.kevs3d.co.uk/dev/canvasmark/?auto=true')
59    return ps
60