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

Unified Diff: tools/android/loading/loading_trace_analyzer_unittest.py

Issue 1738803003: tools/android/loading: Implements loading_trace_analyzer.py's unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i11
Patch Set: Addresses pasko's nit in the ListRequests's doc string Created 4 years, 10 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
« no previous file with comments | « tools/android/loading/loading_trace_analyzer.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/loading_trace_analyzer_unittest.py
diff --git a/tools/android/loading/loading_trace_analyzer_unittest.py b/tools/android/loading/loading_trace_analyzer_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..b01aab2b9018cb0c187ab9ed5fe40383fdfc7d78
--- /dev/null
+++ b/tools/android/loading/loading_trace_analyzer_unittest.py
@@ -0,0 +1,59 @@
+# Copyright 2016 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 gzip
+import os
+import re
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+import loading_trace_analyzer
+
+LOADING_DIR = os.path.dirname(__file__)
+TEST_DATA_DIR = os.path.join(LOADING_DIR, 'testdata')
+
+
+class LoadingTraceAnalyzerTest(unittest.TestCase):
+ _ROLLING_STONE = os.path.join(TEST_DATA_DIR, 'rollingstone.trace.gz')
+
+ def setUp(self):
+ self._temp_dir = tempfile.mkdtemp()
+ self.trace_path = self._TmpPath('trace.json')
+ with gzip.GzipFile(self._ROLLING_STONE) as f:
+ with open(self.trace_path, 'w') as g:
+ g.write(f.read())
+
+ def tearDown(self):
+ shutil.rmtree(self._temp_dir)
+
+ def _TmpPath(self, name):
+ return os.path.join(self._temp_dir, name)
+
+ def testRequestsCmd(self):
+ lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path)]
+ self.assertNotEqual(0, len(lines))
+
+ lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path,
+ output_format='hello {protocol} world {url}')]
+ self.assertNotEqual(0, len(lines))
+ for line in lines:
+ self.assertTrue(re.match(r'^hello \S+ world \S+$', line))
+
+ lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path,
+ where_format='{url}', where_statement=r'^http://.*$')]
+ self.assertNotEqual(0, len(lines))
+ for line in lines:
+ self.assertTrue(line.startswith('http://'))
+
+ lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path,
+ where_format='{url}', where_statement=r'^https://.*$')]
+ self.assertNotEqual(0, len(lines))
+ for line in lines:
+ self.assertTrue(line.startswith('https://'))
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/android/loading/loading_trace_analyzer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698