| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 logging | 6 import logging |
| 7 import os |
| 7 import time | 8 import time |
| 8 | 9 |
| 9 import pyauto_functional | 10 import pyauto_functional |
| 10 import pyauto | 11 import pyauto |
| 11 import test_utils | 12 import test_utils |
| 12 | 13 |
| 13 | 14 |
| 14 class NetflixTestHelper(): | 15 class NetflixTestHelper(): |
| 15 """Helper functions for Netflix tests. | 16 """Helper functions for Netflix tests. |
| 16 | 17 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 index = 0 | 86 index = 0 |
| 86 netflix_infobar_status = False | 87 netflix_infobar_status = False |
| 87 for infobar in infobars: | 88 for infobar in infobars: |
| 88 if infobar['buttons'][0] == 'OK': | 89 if infobar['buttons'][0] == 'OK': |
| 89 self._pyauto.PerformActionOnInfobar('accept', infobar_index=index) | 90 self._pyauto.PerformActionOnInfobar('accept', infobar_index=index) |
| 90 netflix_infobar_status = True | 91 netflix_infobar_status = True |
| 91 index = index + 1 | 92 index = index + 1 |
| 92 self._pyauto.assertTrue(netflix_infobar_status, | 93 self._pyauto.assertTrue(netflix_infobar_status, |
| 93 msg='Netflix infobar did not show up') | 94 msg='Netflix infobar did not show up') |
| 94 | 95 |
| 95 def _CurrentPlaybackTime(self): | 96 def CurrentPlaybackTime(self): |
| 96 """Returns the current playback time in seconds.""" | 97 """Returns the current playback time in seconds.""" |
| 97 time = self._pyauto.ExecuteJavascript(""" | 98 time = self._pyauto.ExecuteJavascript(""" |
| 98 time = nrdp.video.currentTime; | 99 time = nrdp.video.currentTime; |
| 99 window.domAutomationController.send(time + ''); | 100 window.domAutomationController.send(time + ''); |
| 100 """) | 101 """) |
| 101 return int(float(time)) | 102 return int(float(time)) |
| 102 | 103 |
| 103 def _SignOut(self): | 104 def SignOut(self): |
| 104 """Sing out from Netflix Login.""" | 105 """Sign out from Netflix Login.""" |
| 105 self._pyauto.NavigateToURL(self.SIGNOUT_PAGE) | 106 self._pyauto.NavigateToURL(self.SIGNOUT_PAGE) |
| 106 | 107 |
| 107 def _LoginAndStartPlaying(self): | 108 def LoginAndStartPlaying(self): |
| 108 """Login and start playing the video.""" | 109 """Login and start playing the video.""" |
| 109 self._pyauto.assertTrue(self._pyauto._IsNetflixPluginEnabled(), | 110 self._pyauto.assertTrue(self._pyauto._IsNetflixPluginEnabled(), |
| 110 msg='Netflix plugin is disabled or not available.') | 111 msg='Netflix plugin is disabled or not available.') |
| 111 self._pyauto._LoginToNetflix() | 112 self._pyauto._LoginToNetflix() |
| 112 self._pyauto.assertTrue(self._pyauto.WaitUntil( | 113 self._pyauto.assertTrue(self._pyauto.WaitUntil( |
| 113 lambda:self._pyauto.GetActiveTabURL().spec(), | 114 lambda: self._pyauto.GetActiveTabURL().spec(), |
| 114 expect_retval=self.TITLE_HOMEPAGE), | 115 expect_retval=self.TITLE_HOMEPAGE), |
| 115 msg='Login to Netflix failed.') | 116 msg='Login to Netflix failed.') |
| 116 self._pyauto.NavigateToURL(self.VIDEO_URL) | 117 self._pyauto.NavigateToURL(self.VIDEO_URL) |
| 117 self._pyauto._HandleInfobars() | 118 self._pyauto._HandleInfobars() |
| 118 | 119 |
| 119 def _CheckNetflixPlaying(self, expected_result, error_msg): | 120 def CheckNetflixPlaying(self, expected_result, error_msg): |
| 120 """Check if Netflix is playing the video or not. | 121 """Check if Netflix is playing the video or not. |
| 121 | 122 |
| 122 Args: | 123 Args: |
| 123 expected_result: expected return value from Netflix player. | 124 expected_result: expected return value from Netflix player. |
| 124 error_msg: If expected value isn't matching, error message to throw. | 125 error_msg: If expected value isn't matching, error message to throw. |
| 125 """ | 126 """ |
| 126 self._pyauto.assertTrue(self._pyauto.WaitUntil( | 127 self._pyauto.assertTrue(self._pyauto.WaitUntil( |
| 127 lambda: self._pyauto.ExecuteJavascript(""" | 128 lambda: self._pyauto.ExecuteJavascript(""" |
| 128 player_status = nrdp.video.readyState; | 129 player_status = nrdp.video.readyState; |
| 129 window.domAutomationController.send(player_status + ''); | 130 window.domAutomationController.send(player_status + ''); |
| 130 """), expect_retval=expected_result), | 131 """), expect_retval=expected_result), |
| 131 msg=error_msg) | 132 msg=error_msg) |
| 132 | 133 |
| 133 | 134 |
| 134 class NetflixTest(pyauto.PyUITest, NetflixTestHelper): | 135 class NetflixTest(pyauto.PyUITest, NetflixTestHelper): |
| 135 """Test case for Netflix player.""" | 136 """Test case for Netflix player.""" |
| 136 | 137 |
| 137 def __init__(self, methodName='runTest', **kwargs): | 138 def __init__(self, methodName='runTest', **kwargs): |
| 138 pyauto.PyUITest.__init__(self, methodName, **kwargs) | 139 pyauto.PyUITest.__init__(self, methodName, **kwargs) |
| 139 NetflixTestHelper.__init__(self, self) | 140 NetflixTestHelper.__init__(self, self) |
| 140 | 141 |
| 141 def _Login(self): | 142 def _Login(self): |
| 142 """Perform login""" | 143 """Perform login""" |
| 143 credentials = self.GetPrivateInfo()['test_google_account'] | 144 credentials = self.GetPrivateInfo()['test_google_account'] |
| 144 self.Login(credentials['username'], credentials['password']) | 145 self.Login(credentials['username'], credentials['password']) |
| 145 logging.info('Logged in as %s' % credentials['username']) | 146 logging.info('Logged in as %s' % credentials['username']) |
| 146 login_info = self.GetLoginInfo() | 147 login_info = self.GetLoginInfo() |
| 147 self.assertTrue(login_info['is_logged_in'], msg='Login failed.') | 148 self.assertTrue(login_info['is_logged_in'], msg='Login failed.') |
| 149 self.assertFalse(login_info['is_guest'], |
| 150 msg='Should not be logged in as guest.') |
| 151 |
| 152 def setUp(self): |
| 153 assert os.geteuid() == 0, 'Run test as root since we might need to logout' |
| 154 pyauto.PyUITest.setUp(self) |
| 155 if self.GetLoginInfo()['is_logged_in']: |
| 156 self.Logout() |
| 157 self._Login() |
| 148 | 158 |
| 149 def tearDown(self): | 159 def tearDown(self): |
| 150 self._SignOut() | 160 self.SignOut() |
| 151 # We have a test which runs in Guest mode, but other tests must run in | 161 pyauto.PyUITest.tearDown(self) |
| 152 # Normal mode since Netflix only runs in Normal mode. | |
| 153 # Adding logout part here in case GuestMode test fails in between. | |
| 154 if self.GetLoginInfo()['is_guest']: | |
| 155 self.Logout() | |
| 156 self._Login() | |
| 157 pyauto.PyUITest.tearDown(self) | |
| 158 | 162 |
| 159 def testPlayerLoadsAndPlays(self): | 163 def testPlayerLoadsAndPlays(self): |
| 160 """Test that Netflix player loads and plays the title.""" | 164 """Test that Netflix player loads and plays the title.""" |
| 161 self._LoginAndStartPlaying() | 165 self.LoginAndStartPlaying() |
| 162 self._CheckNetflixPlaying(self.IS_PLAYING, | 166 self.CheckNetflixPlaying(self.IS_PLAYING, |
| 163 'Player did not start playing the title.') | 167 'Player did not start playing the title.') |
| 164 | 168 |
| 165 def testPlaying(self): | 169 def testPlaying(self): |
| 166 """Test that title playing progresses.""" | 170 """Test that title playing progresses.""" |
| 167 self._LoginAndStartPlaying() | 171 self.LoginAndStartPlaying() |
| 168 self._CheckNetflixPlaying(self.IS_PLAYING, | 172 self.CheckNetflixPlaying(self.IS_PLAYING, |
| 169 'Player did not start playing the title.') | 173 'Player did not start playing the title.') |
| 170 title_length = self.ExecuteJavascript(""" | 174 title_length = self.ExecuteJavascript(""" |
| 171 time = nrdp.video.duration; | 175 time = nrdp.video.duration; |
| 172 window.domAutomationController.send(time + ''); | 176 window.domAutomationController.send(time + ''); |
| 173 """) | 177 """) |
| 174 title_length = int(float(title_length)) | 178 title_length = int(float(title_length)) |
| 175 prev_time = 0 | 179 prev_time = 0 |
| 176 current_time = 0 | 180 current_time = 0 |
| 177 count = 0 | 181 count = 0 |
| 178 while current_time < title_length: | 182 while current_time < title_length: |
| 179 # We want to test playing only for ten seconds. | 183 # We want to test playing only for ten seconds. |
| 180 count = count + 1 | 184 count = count + 1 |
| 181 if count == 10: | 185 if count == 10: |
| 182 break | 186 break |
| 183 current_time = self._CurrentPlaybackTime() | 187 current_time = self.CurrentPlaybackTime() |
| 184 self.assertTrue(prev_time <= current_time, | 188 self.assertTrue(prev_time <= current_time, |
| 185 msg='Prev playing time %s is greater than current time %s.' | 189 msg='Prev playing time %s is greater than current time %s.' |
| 186 % (prev_time, current_time)) | 190 % (prev_time, current_time)) |
| 187 prev_time = current_time | 191 prev_time = current_time |
| 188 # play video for some time | 192 # play video for some time |
| 189 time.sleep(1) | 193 time.sleep(1) |
| 190 # In case player doesn't start playing at all, above while loop may | 194 # In case player doesn't start playing at all, above while loop may |
| 191 # still pass. So re-verifying and assuming that player did play something | 195 # still pass. So re-verifying and assuming that player did play something |
| 192 # during last 10 seconds. | 196 # during last 10 seconds. |
| 193 self.assertTrue(current_time > 0, | 197 self.assertTrue(current_time > 0, |
| 194 msg='Netflix player did not start playing.') | 198 msg='Netflix player did not start playing.') |
| 195 | 199 |
| 196 def testGuestMode(self): | 200 |
| 197 """Test that Netflix doesn't play in Guest mode login""" | 201 class NetflixGuestModeTest(pyauto.PyUITest, NetflixTestHelper): |
| 198 login_info = self.GetLoginInfo() | 202 """Netflix in guest mode.""" |
| 199 if login_info['is_logged_in']: | 203 |
| 204 def __init__(self, methodName='runTest', **kwargs): |
| 205 pyauto.PyUITest.__init__(self, methodName, **kwargs) |
| 206 NetflixTestHelper.__init__(self, self) |
| 207 |
| 208 def setUp(self): |
| 209 assert os.geteuid() == 0, 'Run test as root since we might need to logout' |
| 210 pyauto.PyUITest.setUp(self) |
| 211 if self.GetLoginInfo()['is_logged_in']: |
| 200 self.Logout() | 212 self.Logout() |
| 201 self.LoginAsGuest() | 213 self.LoginAsGuest() |
| 202 login_info = self.GetLoginInfo() | 214 login_info = self.GetLoginInfo() |
| 203 self.assertTrue(login_info['is_logged_in'], msg='Not logged in at all.') | 215 self.assertTrue(login_info['is_logged_in'], msg='Not logged in at all.') |
| 204 self.assertTrue(login_info['is_guest'], msg='Not logged in as guest.') | 216 self.assertTrue(login_info['is_guest'], msg='Not logged in as guest.') |
| 205 self._LoginAndStartPlaying() | 217 |
| 206 self._CheckNetflixPlaying( | 218 def tearDown(self): |
| 219 self.SignOut() |
| 220 self.Logout() |
| 221 pyauto.PyUITest.tearDown(self) |
| 222 |
| 223 def testGuestMode(self): |
| 224 """Test that Netflix doesn't play in guest mode login.""" |
| 225 self.LoginAndStartPlaying() |
| 226 self.CheckNetflixPlaying( |
| 207 self.IS_GUEST_MODE_ERROR, | 227 self.IS_GUEST_MODE_ERROR, |
| 208 'Netflix player did not return a Guest mode error.') | 228 'Netflix player did not return a Guest mode error.') |
| 209 # Page contents parsing doesn't work : crosbug.com/27977 | 229 # Page contents parsing doesn't work : crosbug.com/27977 |
| 210 # Uncomment the following line when that bug is fixed. | 230 # Uncomment the following line when that bug is fixed. |
| 211 # self.assertTrue('Guest Mode Unsupported' in self.GetTabContents()) | 231 # self.assertTrue('Guest Mode Unsupported' in self.GetTabContents()) |
| 212 | 232 |
| 213 | 233 |
| 214 if __name__ == '__main__': | 234 if __name__ == '__main__': |
| 215 pyauto_functional.Main() | 235 pyauto_functional.Main() |
| OLD | NEW |