| 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 NetflixTest(pyauto.PyUITest): | 12 class NetflixTest(pyauto.PyUITest): |
| 13 """Test case for Netflix player""" | 13 """Test case for Netflix player""" |
| 14 | 14 |
| 15 # Netflix player states | 15 # Netflix player states |
| 16 is_playing = '4' | 16 _is_playing = '4' |
| 17 | 17 |
| 18 title_homepage = 'http://movies.netflix.com/WiHome' | 18 _title_homepage = 'http://movies.netflix.com/WiHome' |
| 19 signout_page = 'https://account.netflix.com/Logout' | 19 _signout_page = 'https://account.netflix.com/Logout' |
| 20 # 30 Rock | 20 # 30 Rock |
| 21 test_title = 'http://movies.netflix.com/WiPlayer?'+ \ | 21 _test_title = 'http://movies.netflix.com/WiPlayer?'+ \ |
| 22 'movieid=70136124&trkid=2361637&t=30+Rock' | 22 'movieid=70136124&trkid=2361637&t=30+Rock' |
| 23 | 23 |
| 24 def tearDown(self): | 24 def tearDown(self): |
| 25 self._SignOut() | 25 self._SignOut() |
| 26 pyauto.PyUITest.tearDown(self) | 26 pyauto.PyUITest.tearDown(self) |
| 27 | 27 |
| 28 def _IsNetflixPluginEnabled(self): | 28 def _IsNetflixPluginEnabled(self): |
| 29 """Determine Netflix plugin availability and its state""" | 29 """Determine Netflix plugin availability and its state""" |
| 30 return [x for x in self.GetPluginsInfo().Plugins() \ | 30 return [x for x in self.GetPluginsInfo().Plugins() \ |
| 31 if x['name'] == 'Netflix' and x['enabled']] | 31 if x['name'] == 'Netflix' and x['enabled']] |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 def _CurrentPlaybackTime(self): | 65 def _CurrentPlaybackTime(self): |
| 66 """Returns the current playback time in seconds""" | 66 """Returns the current playback time in seconds""" |
| 67 time = self.ExecuteJavascript(""" | 67 time = self.ExecuteJavascript(""" |
| 68 time = nrdp.video.currentTime; | 68 time = nrdp.video.currentTime; |
| 69 window.domAutomationController.send(time + ''); | 69 window.domAutomationController.send(time + ''); |
| 70 """) | 70 """) |
| 71 return int(float(time)) | 71 return int(float(time)) |
| 72 | 72 |
| 73 def _SignOut(self): | 73 def _SignOut(self): |
| 74 """Sing out from Netflix Login""" | 74 """Sing out from Netflix Login""" |
| 75 self.NavigateToURL(self.signout_page) | 75 self.NavigateToURL(self._signout_page) |
| 76 | 76 |
| 77 def _LoginAndStartPlaying(self): | 77 def _LoginAndStartPlaying(self): |
| 78 """Login and start playing the video""" | 78 """Login and start playing the video""" |
| 79 self.assertTrue(self._IsNetflixPluginEnabled(), | 79 self.assertTrue(self._IsNetflixPluginEnabled(), |
| 80 msg='Netflix plugin is disabled or not available') | 80 msg='Netflix plugin is disabled or not available') |
| 81 self._LoginToNetflix() | 81 self._LoginToNetflix() |
| 82 self.assertTrue(self.WaitUntil( | 82 self.assertTrue(self.WaitUntil( |
| 83 lambda:self.GetActiveTabURL().spec(), | 83 lambda:self.GetActiveTabURL().spec(), |
| 84 expect_retval=self.title_homepage), | 84 expect_retval=self._title_homepage), |
| 85 msg='Login to Netflix failed') | 85 msg='Login to Netflix failed') |
| 86 self.NavigateToURL(self.test_title) | 86 self.NavigateToURL(self._test_title) |
| 87 self._HandleInfobars() | 87 self._HandleInfobars() |
| 88 self.assertTrue(self.WaitUntil( | 88 self.assertTrue(self.WaitUntil( |
| 89 lambda: self.ExecuteJavascript(""" | 89 lambda: self.ExecuteJavascript(""" |
| 90 player_status = nrdp.video.readyState; | 90 player_status = nrdp.video.readyState; |
| 91 window.domAutomationController.send(player_status + ''); | 91 window.domAutomationController.send(player_status + ''); |
| 92 """), expect_retval=self.is_playing), | 92 """), expect_retval=self._is_playing), |
| 93 msg='Player did not start playing the title') | 93 msg='Player did not start playing the title') |
| 94 | 94 |
| 95 def testPlayerLoadsAndPlays(self): | 95 def testPlayerLoadsAndPlays(self): |
| 96 """Test that Netflix player loads and plays the title""" | 96 """Test that Netflix player loads and plays the title""" |
| 97 self._LoginAndStartPlaying() | 97 self._LoginAndStartPlaying() |
| 98 | 98 |
| 99 def testPlaying(self): | 99 def testPlaying(self): |
| 100 """Test that title playing progresses""" | 100 """Test that title playing progresses""" |
| 101 self._LoginAndStartPlaying() | 101 self._LoginAndStartPlaying() |
| 102 title_length = self.ExecuteJavascript(""" | 102 title_length = self.ExecuteJavascript(""" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 116 self.assertTrue(prev_time <= current_time, | 116 self.assertTrue(prev_time <= current_time, |
| 117 msg='Prev playing time %s is greater than current time %s' | 117 msg='Prev playing time %s is greater than current time %s' |
| 118 % (prev_time, current_time)) | 118 % (prev_time, current_time)) |
| 119 prev_time = current_time | 119 prev_time = current_time |
| 120 # play video for some time | 120 # play video for some time |
| 121 time.sleep(1) | 121 time.sleep(1) |
| 122 | 122 |
| 123 | 123 |
| 124 if __name__ == '__main__': | 124 if __name__ == '__main__': |
| 125 pyauto_functional.Main() | 125 pyauto_functional.Main() |
| OLD | NEW |