OLD | NEW |
(Empty) | |
| 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 |
| 5 import unittest |
| 6 |
| 7 from telemetry import benchmark |
| 8 from telemetry import user_story |
| 9 from telemetry.page import page_test |
| 10 from telemetry.page import test_expectations |
| 11 from telemetry.results import results_options |
| 12 from telemetry.unittest_util import options_for_unittests |
| 13 from telemetry.user_story import shared_user_story_state |
| 14 from telemetry.user_story import user_story_runner |
| 15 from telemetry.user_story import user_story_set |
| 16 |
| 17 |
| 18 class FakePlatform(object): |
| 19 def CanMonitorThermalThrottling(self): |
| 20 return False |
| 21 |
| 22 |
| 23 class TestSharedUserStoryState(shared_user_story_state.SharedUserStoryState): |
| 24 |
| 25 _platform = FakePlatform() |
| 26 |
| 27 @classmethod |
| 28 def SetTestPlatform(cls, platform): |
| 29 cls._platform = platform |
| 30 |
| 31 def __init__(self, test, options, user_story_setz): |
| 32 super(TestSharedUserStoryState, self).__init__( |
| 33 test, options, user_story_setz) |
| 34 |
| 35 @property |
| 36 def platform(self): |
| 37 return self._platform |
| 38 |
| 39 def WillRunUserStory(self, user_storyz): |
| 40 pass |
| 41 |
| 42 def GetTestExpectationAndSkipValue(self, expectations): |
| 43 return 'pass', None |
| 44 |
| 45 def RunUserStory(self, results): |
| 46 pass |
| 47 |
| 48 def DidRunUserStory(self, results): |
| 49 pass |
| 50 |
| 51 def TearDown(self, results): |
| 52 pass |
| 53 |
| 54 |
| 55 class FooUserStoryState(TestSharedUserStoryState): |
| 56 pass |
| 57 |
| 58 |
| 59 class BarUserStoryState(TestSharedUserStoryState): |
| 60 pass |
| 61 |
| 62 |
| 63 class DummyTest(page_test.PageTest): |
| 64 def ValidatePage(self, *_): |
| 65 pass |
| 66 |
| 67 |
| 68 class EmptyMetadataForTest(benchmark.BenchmarkMetadata): |
| 69 def __init__(self): |
| 70 super(EmptyMetadataForTest, self).__init__('') |
| 71 |
| 72 |
| 73 def _GetOptionForUnittest(): |
| 74 options = options_for_unittests.GetCopy() |
| 75 options.output_formats = ['none'] |
| 76 options.suppress_gtest_report = True |
| 77 parser = options.CreateParser() |
| 78 user_story_runner.AddCommandLineArgs(parser) |
| 79 options.MergeDefaultValues(parser.get_default_values()) |
| 80 user_story_runner.ProcessCommandLineArgs(parser, options) |
| 81 return options |
| 82 |
| 83 |
| 84 class UserStoryRunnerTest(unittest.TestCase): |
| 85 |
| 86 def setUp(self): |
| 87 self.options = _GetOptionForUnittest() |
| 88 self.expectations = test_expectations.TestExpectations() |
| 89 self.results = results_options.CreateResults( |
| 90 EmptyMetadataForTest(), self.options) |
| 91 |
| 92 def testGetUserStoryGroupsWithSameSharedUserStoryClass(self): |
| 93 us = user_story_set.UserStorySet() |
| 94 us.AddUserStory(user_story.UserStory(FooUserStoryState)) |
| 95 us.AddUserStory(user_story.UserStory(FooUserStoryState)) |
| 96 us.AddUserStory(user_story.UserStory(BarUserStoryState)) |
| 97 us.AddUserStory(user_story.UserStory(FooUserStoryState)) |
| 98 story_groups = ( |
| 99 user_story_runner.GetUserStoryGroupsWithSameSharedUserStoryClass( |
| 100 us)) |
| 101 self.assertEqual(len(story_groups), 3) |
| 102 self.assertEqual(story_groups[0].shared_user_story_state_class, |
| 103 FooUserStoryState) |
| 104 self.assertEqual(story_groups[1].shared_user_story_state_class, |
| 105 BarUserStoryState) |
| 106 self.assertEqual(story_groups[2].shared_user_story_state_class, |
| 107 FooUserStoryState) |
| 108 |
| 109 def testSuccefulUserStoryTest(self): |
| 110 us = user_story_set.UserStorySet() |
| 111 us.AddUserStory(user_story.UserStory(FooUserStoryState)) |
| 112 us.AddUserStory(user_story.UserStory(FooUserStoryState)) |
| 113 us.AddUserStory(user_story.UserStory(BarUserStoryState)) |
| 114 user_story_runner.Run( |
| 115 DummyTest(), us, self.expectations, self.options, self.results) |
| 116 self.assertEquals(0, len(self.results.failures)) |
| 117 self.assertEquals(3, len(self.results.pages_that_succeeded)) |
OLD | NEW |