OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import time | 6 import time |
7 | 7 |
8 import pyauto_functional | 8 import pyauto_functional |
9 import pyauto | 9 import pyauto |
10 | 10 |
11 | 11 |
12 class NetflixTestHelper(): | 12 class NetflixTestHelper(): |
13 """Helper functions for Netflix tests. | 13 """Helper functions for Netflix tests. |
14 | 14 |
15 For sample usage, look at class NetflixTest. | 15 For sample usage, look at class NetflixTest. |
16 """ | 16 """ |
17 | 17 |
18 # Netflix player states. | 18 # Netflix player states. |
19 is_playing = '4' | 19 IS_PLAYING = '4' |
20 | 20 |
21 title_homepage = 'http://movies.netflix.com/WiHome' | 21 TITLE_HOMEPAGE = 'http://movies.netflix.com/WiHome' |
22 signout_page = 'https://account.netflix.com/Logout' | 22 SIGNOUT_PAGE = 'https://account.netflix.com/Logout' |
23 # 30 Rock | 23 # 30 Rock. |
24 test_title = 'http://movies.netflix.com/WiPlayer?'+ \ | 24 VIDEO_URL = 'http://movies.netflix.com/WiPlayer?' + \ |
25 'movieid=70136124&trkid=2361637&t=30+Rock' | 25 'movieid=70136124&trkid=2361637&t=30+Rock' |
26 _pyauto = None | 26 _pyauto = None |
27 | 27 |
28 def __init__(self, pyauto): | 28 def __init__(self, pyauto): |
29 self._pyauto = pyauto | 29 self._pyauto = pyauto |
30 | 30 |
31 def _IsNetflixPluginEnabled(self): | 31 def _IsNetflixPluginEnabled(self): |
32 """Determine Netflix plugin availability and its state.""" | 32 """Determine Netflix plugin availability and its state.""" |
33 return [x for x in self._pyauto.GetPluginsInfo().Plugins() \ | 33 return [x for x in self._pyauto.GetPluginsInfo().Plugins() \ |
34 if x['name'] == 'Netflix' and x['enabled']] | 34 if x['name'] == 'Netflix' and x['enabled']] |
35 | 35 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 def _CurrentPlaybackTime(self): | 90 def _CurrentPlaybackTime(self): |
91 """Returns the current playback time in seconds.""" | 91 """Returns the current playback time in seconds.""" |
92 time = self._pyauto.ExecuteJavascript(""" | 92 time = self._pyauto.ExecuteJavascript(""" |
93 time = nrdp.video.currentTime; | 93 time = nrdp.video.currentTime; |
94 window.domAutomationController.send(time + ''); | 94 window.domAutomationController.send(time + ''); |
95 """) | 95 """) |
96 return int(float(time)) | 96 return int(float(time)) |
97 | 97 |
98 def _SignOut(self): | 98 def _SignOut(self): |
99 """Sing out from Netflix Login.""" | 99 """Sing out from Netflix Login.""" |
100 self._pyauto.NavigateToURL(self._pyauto.signout_page) | 100 self._pyauto.NavigateToURL(self.SIGNOUT_PAGE) |
101 | 101 |
102 def _LoginAndStartPlaying(self): | 102 def _LoginAndStartPlaying(self): |
103 """Login and start playing the video.""" | 103 """Login and start playing the video.""" |
104 self._pyauto.assertTrue(self._pyauto._IsNetflixPluginEnabled(), | 104 self._pyauto.assertTrue(self._pyauto._IsNetflixPluginEnabled(), |
105 msg='Netflix plugin is disabled or not available.') | 105 msg='Netflix plugin is disabled or not available.') |
106 self._pyauto._LoginToNetflix() | 106 self._pyauto._LoginToNetflix() |
107 self._pyauto.assertTrue(self._pyauto.WaitUntil( | 107 self._pyauto.assertTrue(self._pyauto.WaitUntil( |
108 lambda:self._pyauto.GetActiveTabURL().spec(), | 108 lambda:self._pyauto.GetActiveTabURL().spec(), |
109 expect_retval=self._pyauto.title_homepage), | 109 expect_retval=self.TITLE_HOMEPAGE), |
110 msg='Login to Netflix failed.') | 110 msg='Login to Netflix failed.') |
111 self._pyauto.NavigateToURL(self._pyauto.test_title) | 111 self._pyauto.NavigateToURL(self.VIDEO_URL) |
112 self._pyauto._HandleInfobars() | 112 self._pyauto._HandleInfobars() |
113 self._pyauto.assertTrue(self._pyauto.WaitUntil( | 113 self._pyauto.assertTrue(self._pyauto.WaitUntil( |
114 lambda: self._pyauto.ExecuteJavascript(""" | 114 lambda: self._pyauto.ExecuteJavascript(""" |
115 player_status = nrdp.video.readyState; | 115 player_status = nrdp.video.readyState; |
116 window.domAutomationController.send(player_status + ''); | 116 window.domAutomationController.send(player_status + ''); |
117 """), expect_retval=self._pyauto.is_playing), | 117 """), expect_retval=self.IS_PLAYING), |
118 msg='Player did not start playing the title.') | 118 msg='Player did not start playing the title.') |
119 | 119 |
120 class NetflixTest(pyauto.PyUITest, NetflixTestHelper): | 120 class NetflixTest(pyauto.PyUITest, NetflixTestHelper): |
121 """Test case for Netflix player.""" | 121 """Test case for Netflix player.""" |
122 | 122 |
123 def __init__(self, methodName='runTest', **kwargs): | 123 def __init__(self, methodName='runTest', **kwargs): |
124 pyauto.PyUITest.__init__(self, methodName, **kwargs) | 124 pyauto.PyUITest.__init__(self, methodName, **kwargs) |
125 NetflixTestHelper.__init__(self, self) | 125 NetflixTestHelper.__init__(self, self) |
126 | 126 |
127 def tearDown(self): | 127 def tearDown(self): |
(...skipping 30 matching lines...) Expand all Loading... |
158 # crosbug.com/22037 | 158 # crosbug.com/22037 |
159 # In case player doesn't start playing at all, above while loop may | 159 # In case player doesn't start playing at all, above while loop may |
160 # still pass. So re-verifying and assuming that player did play something | 160 # still pass. So re-verifying and assuming that player did play something |
161 # during last 10 seconds. | 161 # during last 10 seconds. |
162 self.assertTrue(current_time > 0, | 162 self.assertTrue(current_time > 0, |
163 msg='Netflix player didnot start playing.') | 163 msg='Netflix player didnot start playing.') |
164 | 164 |
165 | 165 |
166 if __name__ == '__main__': | 166 if __name__ == '__main__': |
167 pyauto_functional.Main() | 167 pyauto_functional.Main() |
OLD | NEW |