aboutsummaryrefslogtreecommitdiff
path: root/catapult/catapult_build/dev_server_unittest.py
blob: 718b2d61d3dca1e321d9ac7b679a23fa18d99c16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright (c) 2015 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 json
import os
import unittest


from catapult_build import dev_server
from perf_insights_build import perf_insights_dev_server_config
from tracing_build import tracing_dev_server_config
import webapp2

class DevServerTests(unittest.TestCase):

  def setUp(self):
    self.pds = [
        perf_insights_dev_server_config.PerfInsightsDevServerConfig(),
        tracing_dev_server_config.TracingDevServerConfig(),
    ]

    self.args = dev_server._AddCommandLineArguments(self.pds, [])

  def testStaticDirectoryHandling(self):
    app = dev_server.DevServerApp(self.pds, self.args)
    request = webapp2.Request.blank('/tracing/tests.html')
    response = request.get_response(app)

    self.assertEqual(response.status_int, 200)

  def testGetURLForAbsFilename(self):
    app = dev_server.DevServerApp(self.pds, self.args)
    class FakeServer(object):
      pass
    app.server = FakeServer()

    cfg = tracing_dev_server_config.TracingDevServerConfig()
    base_html_filename = os.path.join(cfg.project.tracing_src_path,
                                      'base', 'base.html')
    url = app.GetURLForAbsFilename(base_html_filename)
    self.assertEqual(url, '/tracing/base/base.html')

    url = app.GetURLForAbsFilename('/tmp/foo')
    self.assertIsNone(url)

  def testGetAbsFilenameForHref(self):
    app = dev_server.DevServerApp(self.pds, self.args)

    cfg = tracing_dev_server_config.TracingDevServerConfig()
    base_html_filename = os.path.join(cfg.project.tracing_src_path,
                                      'base', 'base.html')

    filename = app.GetAbsFilenameForHref('/tracing/base/base.html')
    self.assertEqual(base_html_filename, filename)

    filename = app.GetAbsFilenameForHref('/etc/passwd')
    self.assertIsNone(filename)

  def testTestDataDirectory(self):
    app = dev_server.DevServerApp(self.pds, self.args)
    request = webapp2.Request.blank('/tracing/test_data/trivial_trace.json')
    response = request.get_response(app)

    self.assertEqual(response.status_int, 200)

  def testTestDataDirectoryListing(self):
    app = dev_server.DevServerApp(self.pds, self.args)
    request = webapp2.Request.blank('/tracing/test_data/__file_list__')
    response = request.get_response(app)

    self.assertEqual(response.status_int, 200)
    res = json.loads(response.body)
    assert '/tracing/test_data/trivial_trace.json' in res

  def testSkpDataDirectoryListing(self):
    app = dev_server.DevServerApp(self.pds, self.args)
    request = webapp2.Request.blank('/tracing/skp_data/__file_list__')
    response = request.get_response(app)

    self.assertEqual(response.status_int, 200)
    res = json.loads(response.body)
    assert '/tracing/skp_data/lthi_cats.skp' in res

  def testTestListingHandler(self):
    app = dev_server.DevServerApp(self.pds, self.args)
    request = webapp2.Request.blank('/tracing/tests')
    response = request.get_response(app)

    self.assertEqual(response.status_int, 200)
    res = json.loads(response.body)
    self.assertTrue('test_relpaths' in res)
    self.assertTrue(len(res['test_relpaths']) > 0)