| Index: tools/telemetry/telemetry/value/trace_unittest.py
|
| diff --git a/tools/telemetry/telemetry/value/trace_unittest.py b/tools/telemetry/telemetry/value/trace_unittest.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8d1434aacd7aa4b7bc526c3453361d92aa06fa8f
|
| --- /dev/null
|
| +++ b/tools/telemetry/telemetry/value/trace_unittest.py
|
| @@ -0,0 +1,72 @@
|
| +# Copyright 2013 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 cStringIO
|
| +import json
|
| +import logging
|
| +import unittest
|
| +
|
| +from telemetry.core import util
|
| +from telemetry.value import trace as trace_value_module
|
| +
|
| +class TraceValueTest(unittest.TestCase):
|
| + def testSerialize(self):
|
| + ri = trace_value_module.TraceValue({'traceEvents': [1,2,3]})
|
| + f = cStringIO.StringIO()
|
| + ri.Serialize(f)
|
| + v = f.getvalue()
|
| +
|
| + assert 'traceEvents' in v
|
| + assert '[1, 2, 3]' in v
|
| +
|
| + json.loads(v)
|
| +
|
| + def testEmptyArrayValue(self):
|
| + # We can import empty lists and empty string.
|
| + v = trace_value_module.TraceValue([])
|
| + assert v.HasEventsFor(trace_value_module.CHROME_TRACE_PART) == False
|
| +
|
| + def testEmptyStringValue(self):
|
| + v = trace_value_module.TraceValue('')
|
| + assert v.HasEventsFor(trace_value_module.CHROME_TRACE_PART) == False
|
| +
|
| + def testListForm(self):
|
| + v = trace_value_module.TraceValue([{'ph': 'B'}])
|
| + assert v.HasEventsFor(trace_value_module.CHROME_TRACE_PART) == True
|
| + assert len(v.GetEventsFor(trace_value_module.CHROME_TRACE_PART)) == 1
|
| +
|
| + def testStringForm(self):
|
| + v = trace_value_module.TraceValue('[{"ph": "B"}]')
|
| + assert v.HasEventsFor(trace_value_module.CHROME_TRACE_PART) == True
|
| + assert len(v.GetEventsFor(trace_value_module.CHROME_TRACE_PART)) == 1
|
| +
|
| + def testStringForm2(self):
|
| + v = trace_value_module.TraceValue('{"inspectorTimelineEvents": [1]}')
|
| + assert v.HasEventsFor(trace_value_module.INSPECTOR_TRACE_PART)
|
| + assert len(v.GetEventsFor(trace_value_module.INSPECTOR_TRACE_PART)) == 1
|
| +
|
| + def testCorrectlyMalformedStringForm(self):
|
| + v = trace_value_module.TraceValue("""[
|
| + {"ph": "B"}""")
|
| + assert v.HasEventsFor(trace_value_module.CHROME_TRACE_PART) == True
|
| +
|
| + def testCorrectlyMalformedStringForm2(self):
|
| + v = trace_value_module.TraceValue("""[
|
| + {"ph": "B"},""")
|
| + assert v.HasEventsFor(trace_value_module.CHROME_TRACE_PART) == True
|
| +
|
| +class TraceValueBuilderTest(unittest.TestCase):
|
| + def testBasicChrome(self):
|
| + builder = trace_value_module.TraceValueBuilder()
|
| + builder.AddEventsTo(trace_value_module.CHROME_TRACE_PART, [1,2,3])
|
| + builder.AddEventsTo(trace_value_module.TAB_ID_PART, ['tab-7'])
|
| +
|
| + self.assertTrue(builder.HasEventsFor(trace_value_module.CHROME_TRACE_PART))
|
| + self.assertTrue(builder.HasEventsFor(trace_value_module.TAB_ID_PART))
|
| +
|
| + v = builder.AsValue()
|
| + self.assertTrue(v.HasEventsFor(trace_value_module.CHROME_TRACE_PART))
|
| + self.assertTrue(v.HasEventsFor(trace_value_module.TAB_ID_PART))
|
| +
|
| + self.assertRaises(Exception, builder.AsValue)
|
|
|