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

Unified Diff: tools/chrome_remote_control/chrome_remote_control/multi_page_benchmark_unittest.py

Issue 10965027: Add web page replay to chrome_remote_control. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace CreateForwarder with CreateReplayServer Created 8 years, 2 months 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/chrome_remote_control/chrome_remote_control/multi_page_benchmark_unittest.py
diff --git a/tools/chrome_remote_control/chrome_remote_control/multi_page_benchmark_unittest.py b/tools/chrome_remote_control/chrome_remote_control/multi_page_benchmark_unittest.py
index 27c585a3d9b1537475268cbe182b3c4b6b393ffa..e679c42afe307c24a9f32e80e2057cc2d1d23b5c 100644
--- a/tools/chrome_remote_control/chrome_remote_control/multi_page_benchmark_unittest.py
+++ b/tools/chrome_remote_control/chrome_remote_control/multi_page_benchmark_unittest.py
@@ -1,8 +1,11 @@
# 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
+
from chrome_remote_control import multi_page_benchmark
from chrome_remote_control import multi_page_benchmark_unittest_base
+from chrome_remote_control import page_set
class BenchThatFails(multi_page_benchmark.MultiPageBenchmark):
def MeasurePage(self, page, tab):
@@ -21,9 +24,21 @@ class BenchForBlank(multi_page_benchmark.MultiPageBenchmark):
contents = tab.runtime.Evaluate('document.body.textContent')
assert contents.strip() == 'Hello world'
+class BenchForReplay(multi_page_benchmark.MultiPageBenchmark):
+ def MeasurePage(self, page, tab):
+ # Web Page Replay returns '404 Not found' if a page is not in the archive.
+ contents = tab.runtime.Evaluate('document.body.textContent')
+ if '404 Not Found' in contents.strip():
+ raise multi_page_benchmark.MeasurementFailure('Page not in archive.')
+
class MultiPageBenchmarkUnitTest(
multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase):
+ _record = False
+
+ def CustomizeOptionsForTest(self, options):
+ options.record = self._record
+
def testGotToBlank(self):
ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html')
benchmark = BenchForBlank()
@@ -41,5 +56,34 @@ class MultiPageBenchmarkUnitTest(
benchmark = BenchThatHasDefaults()
all_results = self.RunBenchmark(benchmark, ps)
self.assertEquals(len(all_results.page_results), 1)
- self.assertEquals(all_results.page_results[0]['results']["x"], 7)
+ self.assertEquals(all_results.page_results[0]['results']['x'], 7)
+
+ def testRecordAndReplay(self):
+ test_archive = '/tmp/google.wpr'
+ try:
+ ps = page_set.PageSet(description='',
+ archive_path=test_archive,
+ file_path='/tmp/test_pageset.json')
+ benchmark = BenchForReplay()
+
+ # First record an archive with only www.google.com.
+ self._record = True
+
+ ps.pages = [page_set.Page('http://www.google.com/')]
+ all_results = self.RunBenchmark(benchmark, ps)
+ self.assertEquals(0, len(all_results.page_failures))
+
+ # Now replay it and verify that google.com is found but foo.com is not.
+ self._record = False
+
+ ps.pages = [page_set.Page('http://www.foo.com/')]
+ all_results = self.RunBenchmark(benchmark, ps)
+ self.assertEquals(1, len(all_results.page_failures))
+
+ ps.pages = [page_set.Page('http://www.google.com/')]
+ all_results = self.RunBenchmark(benchmark, ps)
+ self.assertEquals(0, len(all_results.page_failures))
+ finally:
+ assert os.path.isfile(test_archive)
+ os.remove(test_archive)

Powered by Google App Engine
This is Rietveld 408576698