Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: tools/telemetry/examples/gpu_mapsgl_endurance_browsertest.py

Issue 11360172: Added Tab.SnapshotContent and MapsGL example to telemetry (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/examples/gpu_mapsgl_endurance_browsertest.py
diff --git a/tools/telemetry/examples/gpu_mapsgl_endurance_browsertest.py b/tools/telemetry/examples/gpu_mapsgl_endurance_browsertest.py
new file mode 100755
index 0000000000000000000000000000000000000000..2e3af398b9b03fee80c549142d2c4c17f458778b
--- /dev/null
+++ b/tools/telemetry/examples/gpu_mapsgl_endurance_browsertest.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 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.
+import os
+import sys
+import time
+import json
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+import telemetry
+
+def ReadTestExpectations(json_test_expectations_path):
+ f = open(json_test_expectations_path, 'r')
+ json_contents = json.load(f)
+ return json_contents
+
+def CompareToExpectedResults(snapshot, expectations):
+ result = True
+ for expectation in expectations:
+ location = expectation["location"]
+ iter_result = snapshot.CheckPixelColor(location[0], location[1],
+ expectation["color"], expectation["tolerance"])
+ if not iter_result:
+ print("FAILURE: Expected", location, "to be", expectation["color"],
+ "but got", snapshot.GetPixel(location[0], location[1]))
+ result &= iter_result
+ return result
+
+def RunSingleTest(browser,
+ url,
+ json_test_expectations_filename,
+ failure_filename_prefix):
+ expectations = ReadTestExpectations(json_test_expectations_filename)
+
+ #TODO: BringBrowserWindowToFront?
Ken Russell (switch to Gerrit) 2012/11/09 20:26:28 TODOs require a contact person. http://google-styl
+ #TODO: browser.window.SetBounds?
+
+ with browser.ConnectToNthTab(0) as tab:
+ tab.page.Navigate(url)
+ time.sleep(2) # Why is this needed?
+ tab.WaitForDocumentReadyStateToBeComplete()
+
+ if tab.runtime.Evaluate('window.chrome.gpuBenchmarking === undefined'):
+ print 'Browser does not support gpu benchmarks API.'
+ return 255
+
+ if tab.runtime.Evaluate(
+ 'window.chrome.gpuBenchmarking.windowSnapshot === undefined'):
+ print 'Browser does not support window snapshot API.'
+ return 255
+
+ # Mock up the message queue functionality used by the mapping test
Ken Russell (switch to Gerrit) 2012/11/09 20:26:28 Please use periods after comments. It makes them e
+ tab.runtime.Evaluate("""
+ if(!window.domAutomationController) {
+ window.domAutomationController = {};
+ }
+ window.domAutomationController.message_queue = [];
+ window.domAutomationController.setAutomationId = function(id) {}
+ window.domAutomationController.send = function(val) {
+ window.domAutomationController.message_queue.push(val);
+ }
+ """)
+
+ def CheckMessages():
+ message = tab.runtime.Evaluate(
+ "window.domAutomationController.message_queue.shift();")
+ return message == "FINISHED"
+
+ telemetry.WaitFor(CheckMessages, 1000, 0.5)
+
+ snapshot = tab.SnapshotContent()
+ if not snapshot:
+ print "Failed to capture snapshot"
+ return 255
+
+ all_pixels_match = CompareToExpectedResults(snapshot, expectations)
+
+ if not all_pixels_match:
+ print "Color check failed at end of test"
+ snapshot.WriteFile(failure_filename_prefix + "-output.png")
+ return 1
+
+ return 0
+
+def Main(args):
+ options = telemetry.BrowserOptions()
+ parser = options.CreateParser('snapshot_test.py')
+ options, args = parser.parse_args(args)
+
+ options.extra_browser_args.append('--enable-gpu-benchmarking')
+ browser_to_create = telemetry.FindBrowser(options)
+ assert browser_to_create
+ with browser_to_create.Create() as browser:
+ return RunSingleTest(browser,
+ "http://localhost:8000/basic.html",
+ "mapsgl_single_run_basic_expectations.json",
+ "single-run-basic")
+
+if __name__ == '__main__':
+ sys.exit(Main(sys.argv[1:]))

Powered by Google App Engine
This is Rietveld 408576698