| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import utils |
| 6 |
| 5 from telemetry import page | 7 from telemetry import page |
| 6 from telemetry import story | 8 from telemetry import story |
| 7 from benchmarks.pagesets import media_router_page | 9 from benchmarks.pagesets import media_router_page |
| 8 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
| 9 from telemetry.page import shared_page_state | 11 from telemetry.page import shared_page_state |
| 10 | 12 |
| 11 | 13 |
| 12 class SharedState(shared_page_state.SharedPageState): | 14 class SharedState(shared_page_state.SharedPageState): |
| 13 """Shared state that restarts the browser for every single story.""" | 15 """Shared state that restarts the browser for every single story.""" |
| 14 | 16 |
| 15 def __init__(self, test, finder_options, story_set): | 17 def __init__(self, test, finder_options, story_set): |
| 16 super(SharedState, self).__init__( | 18 super(SharedState, self).__init__( |
| 17 test, finder_options, story_set) | 19 test, finder_options, story_set) |
| 18 | 20 |
| 19 def DidRunStory(self, results): | 21 def DidRunStory(self, results): |
| 20 super(SharedState, self).DidRunStory(results) | 22 super(SharedState, self).DidRunStory(results) |
| 21 self._StopBrowser() | 23 self._StopBrowser() |
| 22 | 24 |
| 23 | 25 |
| 24 class CastDialogPage(media_router_page.CastPage): | 26 class CastDialogPage(media_router_page.CastPage): |
| 25 """Cast page to open a cast-enabled page and open media router dialog.""" | 27 """Cast page to open a cast-enabled page and open media router dialog.""" |
| 26 | 28 |
| 27 def __init__(self, page_set, url='file://basic_test.html', | 29 def __init__(self, page_set, url='file://basic_test.html', |
| 28 shared_page_state_class=shared_page_state.SharedPageState): | 30 shared_page_state_class=shared_page_state.SharedPageState): |
| 29 super(CastDialogPage, self).__init__( | 31 super(CastDialogPage, self).__init__( |
| 30 url=url, page_set=page_set, | 32 url=url, page_set=page_set, |
| 31 shared_page_state_class=shared_page_state_class) | 33 shared_page_state_class=shared_page_state_class) |
| 32 | 34 |
| 33 def RunPageInteractions(self, action_runner): | 35 def RunPageInteractions(self, action_runner): |
| 34 # Wait for 5s after Chrome is opened in order to get consistent results. | 36 pass |
| 35 action_runner.Wait(5) | |
| 36 with action_runner.CreateInteraction('LaunchDialog'): | |
| 37 action_runner.ExecuteJavaScript('collectPerfData();') | |
| 38 self._WaitForResult( | |
| 39 action_runner, | |
| 40 lambda: action_runner.EvaluateJavaScript('initialized'), | |
| 41 'Failed to initialize') | |
| 42 | |
| 43 action_runner.TapElement(selector='#start_session_button') | |
| 44 action_runner.Wait(5) | |
| 45 for tab in action_runner.tab.browser.tabs: | |
| 46 # Close media router dialog | |
| 47 if tab.url == 'chrome://media-router/': | |
| 48 self.CloseDialog(tab) | |
| 49 | 37 |
| 50 | 38 |
| 51 class CastIdlePage(CastDialogPage): | 39 class CastIdlePage(CastDialogPage): |
| 52 """Cast page to open a cast-enabled page and do nothing.""" | 40 """Cast page to open a cast-enabled page and do nothing.""" |
| 53 | 41 |
| 54 def __init__(self, page_set): | 42 def __init__(self, page_set): |
| 55 super(CastIdlePage, self).__init__( | 43 super(CastIdlePage, self).__init__( |
| 56 page_set=page_set, | 44 page_set=page_set, |
| 57 url='file://basic_test.html', | 45 url='file://basic_test.html', |
| 58 shared_page_state_class=SharedState) | 46 shared_page_state_class=SharedState) |
| 59 | 47 |
| 60 def RunPageInteractions(self, action_runner): | 48 def RunPageInteractions(self, action_runner): |
| 61 super(CastIdlePage, self).RunPageInteractions(action_runner) | 49 # Wait for 5s after Chrome is opened in order to get consistent results. |
| 62 action_runner.Wait(15) | 50 action_runner.Wait(5) |
| 51 with action_runner.CreateInteraction('Idle'): |
| 52 action_runner.ExecuteJavaScript('collectPerfData();') |
| 53 action_runner.Wait(300) |
| 63 | 54 |
| 64 | 55 |
| 65 class CastFlingingPage(media_router_page.CastPage): | 56 class CastFlingingPage(media_router_page.CastPage): |
| 66 """Cast page to fling a video to Chromecast device.""" | 57 """Cast page to fling a video to Chromecast device.""" |
| 67 | 58 |
| 68 def __init__(self, page_set): | 59 def __init__(self, page_set): |
| 69 super(CastFlingingPage, self).__init__( | 60 super(CastFlingingPage, self).__init__( |
| 70 page_set=page_set, | 61 page_set=page_set, |
| 71 url='file://basic_test.html#flinging', | 62 url='file://basic_test.html#flinging', |
| 72 shared_page_state_class=SharedState) | 63 shared_page_state_class=SharedState) |
| 73 | 64 |
| 74 def RunPageInteractions(self, action_runner): | 65 def RunPageInteractions(self, action_runner): |
| 75 # Wait for 5s after Chrome is opened in order to get consistent results. | 66 # Wait for 5s after Chrome is opened in order to get consistent results. |
| 76 action_runner.Wait(5) | 67 action_runner.Wait(5) |
| 77 with action_runner.CreateInteraction('flinging'): | 68 with action_runner.CreateInteraction('flinging'): |
| 78 action_runner.ExecuteJavaScript('collectPerfData();') | |
| 79 | |
| 80 self._WaitForResult( | 69 self._WaitForResult( |
| 81 action_runner, | 70 action_runner, |
| 82 lambda: action_runner.EvaluateJavaScript('initialized'), | 71 lambda: action_runner.EvaluateJavaScript('initialized'), |
| 83 'Failed to initialize') | 72 'Failed to initialize') |
| 84 | 73 |
| 85 # Start session | 74 # Start session |
| 86 action_runner.TapElement(selector='#start_session_button') | 75 action_runner.TapElement(selector='#start_session_button') |
| 87 self._WaitForResult( | 76 self._WaitForResult( |
| 88 action_runner, | 77 action_runner, |
| 89 lambda: len(action_runner.tab.browser.tabs) >= 2, | 78 lambda: len(action_runner.tab.browser.tabs) >= 2, |
| 90 'MR dialog never showed up.') | 79 'MR dialog never showed up.') |
| 91 | 80 |
| 92 # Wait for 2s to make sure the dialog is fully loaded. | 81 # Wait for 2s to make sure the dialog is fully loaded. |
| 93 action_runner.Wait(2) | 82 action_runner.Wait(2) |
| 94 for tab in action_runner.tab.browser.tabs: | 83 for tab in action_runner.tab.browser.tabs: |
| 95 # Choose sink | 84 # Choose sink |
| 96 if tab.url == 'chrome://media-router/': | 85 if tab.url == 'chrome://media-router/': |
| 97 self.ChooseSink(tab, self._GetDeviceName()) | 86 self.ChooseSink(tab, self._GetDeviceName()) |
| 98 | 87 |
| 99 self._WaitForResult( | 88 self._WaitForResult( |
| 100 action_runner, | 89 action_runner, |
| 101 lambda: action_runner.EvaluateJavaScript('currentSession'), | 90 lambda: action_runner.EvaluateJavaScript('currentSession'), |
| 102 'Failed to start session', | 91 'Failed to start session', |
| 103 timeout=10) | 92 timeout=10) |
| 104 | 93 |
| 105 # Load Media | 94 # Load Media |
| 106 # TODO: use local video instead of the public one. | |
| 107 self.ExecuteAsyncJavaScript( | 95 self.ExecuteAsyncJavaScript( |
| 108 action_runner, | 96 action_runner, |
| 109 'loadMedia("http://easyhtml5video.com/images/happyfit2.mp4");', | 97 'loadMedia("%s");' % utils.GetInternalVideoURL(), |
| 110 lambda: action_runner.EvaluateJavaScript('currentMedia'), | 98 lambda: action_runner.EvaluateJavaScript('currentMedia'), |
| 111 'Failed to load media') | 99 'Failed to load media', |
| 100 timeout=120) |
| 112 | 101 |
| 113 action_runner.Wait(20) | 102 action_runner.Wait(5) |
| 103 action_runner.ExecuteJavaScript('collectPerfData();') |
| 104 action_runner.Wait(300) |
| 114 # Stop session | 105 # Stop session |
| 115 self.ExecuteAsyncJavaScript( | 106 self.ExecuteAsyncJavaScript( |
| 116 action_runner, | 107 action_runner, |
| 117 'stopSession();', | 108 'stopSession();', |
| 118 lambda: not action_runner.EvaluateJavaScript('currentSession'), | 109 lambda: not action_runner.EvaluateJavaScript('currentSession'), |
| 119 'Failed to stop session') | 110 'Failed to stop session') |
| 120 | 111 |
| 121 | 112 |
| 122 class MediaRouterDialogPageSet(story.StorySet): | 113 class MediaRouterDialogPageSet(story.StorySet): |
| 123 """Pageset for media router dialog latency tests.""" | 114 """Pageset for media router dialog latency tests.""" |
| 124 | 115 |
| 125 def __init__(self): | 116 def __init__(self): |
| 126 super(MediaRouterDialogPageSet, self).__init__( | 117 super(MediaRouterDialogPageSet, self).__init__( |
| 127 cloud_storage_bucket=story.PARTNER_BUCKET) | 118 cloud_storage_bucket=story.PARTNER_BUCKET) |
| 128 self.AddStory(CastDialogPage(self)) | 119 self.AddStory(CastDialogPage(self)) |
| 129 | 120 |
| 130 | 121 |
| 131 class MediaRouterCPUMemoryPageSet(story.StorySet): | 122 class MediaRouterCPUMemoryPageSet(story.StorySet): |
| 132 """Pageset for media router CPU/memory usage tests.""" | 123 """Pageset for media router CPU/memory usage tests.""" |
| 133 | 124 |
| 134 def __init__(self): | 125 def __init__(self): |
| 135 super(MediaRouterCPUMemoryPageSet, self).__init__( | 126 super(MediaRouterCPUMemoryPageSet, self).__init__( |
| 136 cloud_storage_bucket=story.PARTNER_BUCKET) | 127 cloud_storage_bucket=story.PARTNER_BUCKET) |
| 137 self.AddStory(CastIdlePage(self)) | 128 self.AddStory(CastIdlePage(self)) |
| 138 self.AddStory(CastFlingingPage(self)) | 129 self.AddStory(CastFlingingPage(self)) |
| OLD | NEW |