11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)# found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)"""Impact HTML5 Gaming benchmark.
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)Tests one very specific use case: smooth running games rendered with the
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)<canvas> element. The score for the HTML5-Benchmark takes the total time the
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)browser spent rendering frames (formula is 1000000/(sqrt(totalTime) + lagTime *
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)0.1)). The benchmark automatically runs at a reasonable screen size. Final
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)score is a indicator for the browser's ability to smoothly run HTML5 games."""
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)import os
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
15116680a4aac90f2aa7413d9095a592090648e557Ben Murdochfrom telemetry import benchmark
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)from telemetry.page import page_set
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)from telemetry.page import page_test
18116680a4aac90f2aa7413d9095a592090648e557Ben Murdochfrom telemetry.value import scalar
19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class _HTML5GamingMeasurement(page_test.PageTest):
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  def ValidateAndMeasurePage(self, _, tab, results):
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    tab.ExecuteJavaScript('benchmark();')
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    # Default value of score element is 87485, its value is updated with actual
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    # score when test finish.
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    tab.WaitForJavaScriptExpression(
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        'document.getElementById("score").innerHTML != "87485"', 200)
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    result = int(tab.EvaluateJavaScript(
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        'document.getElementById("score").innerHTML'))
30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    results.AddValue(
31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        scalar.ScalarValue(results.current_page, 'Score', 'score', result))
32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch@benchmark.Disabled
36116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass HTML5Gaming(benchmark.Benchmark):
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  """Imapct HTML5 smooth running games benchmark suite."""
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  test = _HTML5GamingMeasurement
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  def CreatePageSet(self, options):
405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    ps = page_set.PageSet(
415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      file_path=os.path.abspath(__file__),
425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      archive_data_file='../page_sets/data/html5gaming.json',
435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      make_javascript_deterministic=False)
445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    ps.AddPageWithDefaultRunNavigate('http://html5-benchmark.com/')
455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    return ps
46