web_component_unittest.py revision effb81e5f8246d0db0270817048dc992db66e9fb
1# Copyright 2014 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
5import unittest
6import StringIO
7
8from telemetry.web_components import web_component
9
10class SimpleWebComponent(web_component.WebComponent):
11  def __init__(self):
12    super(SimpleWebComponent, self).__init__(
13      tvcm_module_name='telemetry.web_components.viewer_unittest_data',
14      js_class_name='telemetry.web_components.SimpleWebComponent',
15      data_binding_property='dataToView')
16
17  def WriteDataToFileAsJson(self, f):
18    f.write("1\n")
19
20class WebComponentTests(unittest.TestCase):
21  def testForSmoke(self):
22    v = SimpleWebComponent()
23
24    f = StringIO.StringIO()
25    v.WriteWebComponentToFile(f)
26
27  def testRead(self):
28    v = SimpleWebComponent()
29
30    f = StringIO.StringIO()
31    v.WriteWebComponentToFile(f)
32
33    f.seek(0)
34
35    data = SimpleWebComponent.ReadDataObjectFromWebComponentFile(f)
36    self.assertEquals(data, 1)
37