1 # Copyright (c) 2015 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 import json 5 import os 6 import unittest 7 8 9 from catapult_build import dev_server 10 from perf_insights_build import perf_insights_dev_server_config 11 from tracing_build import tracing_dev_server_config 12 import webapp2 13 14 class DevServerTests(unittest.TestCase): 15 16 def setUp(self): 17 self.pds = [ 18 perf_insights_dev_server_config.PerfInsightsDevServerConfig(), 19 tracing_dev_server_config.TracingDevServerConfig(), 20 ] 21 22 self.args = dev_server._AddCommandLineArguments(self.pds, []) 23 24 def testStaticDirectoryHandling(self): 25 app = dev_server.DevServerApp(self.pds, self.args) 26 request = webapp2.Request.blank('/tracing/tests.html') 27 response = request.get_response(app) 28 29 self.assertEqual(response.status_int, 200) 30 31 def testGetURLForAbsFilename(self): 32 app = dev_server.DevServerApp(self.pds, self.args) 33 class FakeServer(object): 34 pass 35 app.server = FakeServer() 36 37 cfg = tracing_dev_server_config.TracingDevServerConfig() 38 base_html_filename = os.path.join(cfg.project.tracing_src_path, 39 'base', 'base.html') 40 url = app.GetURLForAbsFilename(base_html_filename) 41 self.assertEqual(url, '/tracing/base/base.html') 42 43 url = app.GetURLForAbsFilename('/tmp/foo') 44 self.assertIsNone(url) 45 46 def testGetAbsFilenameForHref(self): 47 app = dev_server.DevServerApp(self.pds, self.args) 48 49 cfg = tracing_dev_server_config.TracingDevServerConfig() 50 base_html_filename = os.path.join(cfg.project.tracing_src_path, 51 'base', 'base.html') 52 53 filename = app.GetAbsFilenameForHref('/tracing/base/base.html') 54 self.assertEqual(base_html_filename, filename) 55 56 filename = app.GetAbsFilenameForHref('/etc/passwd') 57 self.assertIsNone(filename) 58 59 def testTestDataDirectory(self): 60 app = dev_server.DevServerApp(self.pds, self.args) 61 request = webapp2.Request.blank('/tracing/test_data/trivial_trace.json') 62 response = request.get_response(app) 63 64 self.assertEqual(response.status_int, 200) 65 66 def testTestDataDirectoryListing(self): 67 app = dev_server.DevServerApp(self.pds, self.args) 68 request = webapp2.Request.blank('/tracing/test_data/__file_list__') 69 response = request.get_response(app) 70 71 self.assertEqual(response.status_int, 200) 72 res = json.loads(response.body) 73 assert '/tracing/test_data/trivial_trace.json' in res 74 75 def testSkpDataDirectoryListing(self): 76 app = dev_server.DevServerApp(self.pds, self.args) 77 request = webapp2.Request.blank('/tracing/skp_data/__file_list__') 78 response = request.get_response(app) 79 80 self.assertEqual(response.status_int, 200) 81 res = json.loads(response.body) 82 assert '/tracing/skp_data/lthi_cats.skp' in res 83 84 def testTestListingHandler(self): 85 app = dev_server.DevServerApp(self.pds, self.args) 86 request = webapp2.Request.blank('/tracing/tests') 87 response = request.get_response(app) 88 89 self.assertEqual(response.status_int, 200) 90 res = json.loads(response.body) 91 self.assertTrue('test_relpaths' in res) 92 self.assertTrue(len(res['test_relpaths']) > 0) 93