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 NetflixTestHelper(): |
13 """Test case for Netflix player""" | 13 """Helper functions for Netflix tests. |
14 | |
15 For sample usage, look at class NetflixTest. | |
16 """ | |
14 | 17 |
15 # Netflix player states | 18 # Netflix player states. |
16 _is_playing = '4' | 19 is_playing = '4' |
17 | 20 |
18 _title_homepage = 'http://movies.netflix.com/WiHome' | 21 title_homepage = 'http://movies.netflix.com/WiHome' |
19 _signout_page = 'https://account.netflix.com/Logout' | 22 signout_page = 'https://account.netflix.com/Logout' |
20 # 30 Rock | 23 # 30 Rock |
21 _test_title = 'http://movies.netflix.com/WiPlayer?'+ \ | 24 test_title = 'http://movies.netflix.com/WiPlayer?'+ \ |
22 'movieid=70136124&trkid=2361637&t=30+Rock' | 25 'movieid=70136124&trkid=2361637&t=30+Rock' |
26 _pyauto = None | |
23 | 27 |
24 def tearDown(self): | 28 def __init__(self, pyauto): |
25 self._SignOut() | 29 self._pyauto = pyauto |
26 pyauto.PyUITest.tearDown(self) | |
27 | 30 |
28 def _IsNetflixPluginEnabled(self): | 31 def _IsNetflixPluginEnabled(self): |
29 """Determine Netflix plugin availability and its state""" | 32 """Determine Netflix plugin availability and its state.""" |
30 return [x for x in self.GetPluginsInfo().Plugins() \ | 33 return [x for x in self._pyauto.GetPluginsInfo().Plugins() \ |
31 if x['name'] == 'Netflix' and x['enabled']] | 34 if x['name'] == 'Netflix' and x['enabled']] |
32 | 35 |
33 def _LoginToNetflix(self): | 36 def _LoginToNetflix(self): |
34 """Login to Netflix""" | 37 """Login to Netflix.""" |
35 credentials = self.GetPrivateInfo()['test_netflix_acct'] | 38 credentials = self._pyauto.GetPrivateInfo()['test_netflix_acct'] |
36 board_name = self.ChromeOSBoard() | 39 board_name = self._pyauto.ChromeOSBoard() |
37 assert credentials.get(board_name), \ | 40 assert credentials.get(board_name), \ |
38 'No netflix credentials for %s' % board_name | 41 'No netflix credentials for %s.' % board_name |
39 self.NavigateToURL(credentials['login_url']) | 42 self._pyauto.NavigateToURL(credentials['login_url']) |
40 login_js = """ | 43 login_js = """ |
41 document.getElementById('email').value='%s'; | 44 document.getElementById('email').value='%s'; |
42 document.getElementById('password').value='%s'; | 45 document.getElementById('password').value='%s'; |
43 window.domAutomationController.send('ok'); | 46 window.domAutomationController.send('ok'); |
44 """ % (credentials[board_name], credentials['password']) | 47 """ % (credentials[board_name], credentials['password']) |
45 self.assertEqual(self.ExecuteJavascript(login_js), 'ok', | 48 self._pyauto.assertEqual(self._pyauto.ExecuteJavascript(login_js), 'ok', |
46 msg='Failed to set login credentials') | 49 msg='Failed to set login credentials.') |
47 self.assertTrue(self.SubmitForm('login-form'), | 50 self._pyauto.assertTrue(self._pyauto.SubmitForm('login-form'), |
48 msg='Login to Netflix failed') | 51 msg='Login to Netflix failed.') |
49 | 52 |
53 def _GetVideoDroppedFrames(self, tab_index=0, windex=0): | |
54 """Returns total Netflix video dropped frames.""" | |
55 js = """ | |
56 var frames = nrdp.video.droppedFrames; | |
57 window.domAutomationController.send(frames + ''); | |
58 """ | |
59 return int(self._pyauto.ExecuteJavascript(js, tab_index, windex)) | |
dennis_jeffrey
2011/11/22 01:08:19
nit: "tab_index=tab_index, windex=windex"
(since
| |
60 | |
61 def _GetVideoFrames(self, tab_index=0, windex=0): | |
62 """Returns Netflix video total frames.""" | |
63 js = """ | |
64 var frames = nrdp.video.totalFrames; | |
65 window.domAutomationController.send(frames + ''); | |
66 """ | |
67 return int(self._pyauto.ExecuteJavascript(js, tab_index, windex)) | |
dennis_jeffrey
2011/11/22 01:08:19
Same comment as line 59 above.
| |
68 | |
50 def _HandleInfobars(self): | 69 def _HandleInfobars(self): |
51 """Manage infobars, come up during the test. | 70 """Manage infobars, come up during the test. |
52 | 71 |
53 We expect password and Netflix infobars. Processing only Netflix infobar, | 72 We expect password and Netflix infobars. Processing only Netflix infobar, |
54 since to start a vidoe, pressing the OK button is a must. We can keep other | 73 since to start a vidoe, pressing the OK button is a must. We can keep other |
55 inforbars open.""" | 74 infobars open.""" |
56 self.WaitForInfobarCount(2) | 75 self._pyauto.WaitForInfobarCount(2) |
57 tab_info = self.GetBrowserInfo()['windows'][0]['tabs'][0] | 76 tab_info = self._pyauto.GetBrowserInfo()['windows'][0]['tabs'][0] |
58 infobars = tab_info['infobars'] | 77 infobars = tab_info['infobars'] |
59 index = 0 | 78 index = 0 |
60 netflix_infobar_status = False | 79 netflix_infobar_status = False |
61 for infobar in infobars: | 80 for infobar in infobars: |
62 if infobar['buttons'][0] == 'OK': | 81 if infobar['buttons'][0] == 'OK': |
63 self.PerformActionOnInfobar('accept', infobar_index=index) | 82 self._pyauto.PerformActionOnInfobar('accept', infobar_index=index) |
64 netflix_infobar_status = True | 83 netflix_infobar_status = True |
65 index = index + 1 | 84 index = index + 1 |
66 self.assertTrue(netflix_infobar_status, | 85 self._pyauto.assertTrue(netflix_infobar_status, |
67 msg='Netflix infobar did not show up') | 86 msg='Netflix infobar did not show up') |
68 | 87 |
69 def _CurrentPlaybackTime(self): | 88 def _CurrentPlaybackTime(self): |
70 """Returns the current playback time in seconds""" | 89 """Returns the current playback time in seconds.""" |
71 time = self.ExecuteJavascript(""" | 90 time = self._pyauto.ExecuteJavascript(""" |
72 time = nrdp.video.currentTime; | 91 time = nrdp.video.currentTime; |
73 window.domAutomationController.send(time + ''); | 92 window.domAutomationController.send(time + ''); |
74 """) | 93 """) |
75 return int(float(time)) | 94 return int(float(time)) |
76 | 95 |
77 def _SignOut(self): | 96 def _SignOut(self): |
78 """Sing out from Netflix Login""" | 97 """Sing out from Netflix Login.""" |
79 self.NavigateToURL(self._signout_page) | 98 self._pyauto.NavigateToURL(self._pyauto.signout_page) |
80 | 99 |
81 def _LoginAndStartPlaying(self): | 100 def _LoginAndStartPlaying(self): |
82 """Login and start playing the video""" | 101 """Login and start playing the video.""" |
83 self.assertTrue(self._IsNetflixPluginEnabled(), | 102 self._pyauto.assertTrue(self._pyauto._IsNetflixPluginEnabled(), |
84 msg='Netflix plugin is disabled or not available') | 103 msg='Netflix plugin is disabled or not available.') |
85 self._LoginToNetflix() | 104 self._pyauto._LoginToNetflix() |
86 self.assertTrue(self.WaitUntil( | 105 self._pyauto.assertTrue(self._pyauto.WaitUntil( |
87 lambda:self.GetActiveTabURL().spec(), | 106 lambda:self._pyauto.GetActiveTabURL().spec(), |
88 expect_retval=self._title_homepage), | 107 expect_retval=self._pyauto.title_homepage), |
89 msg='Login to Netflix failed') | 108 msg='Login to Netflix failed.') |
90 self.NavigateToURL(self._test_title) | 109 self._pyauto.NavigateToURL(self._pyauto.test_title) |
91 self._HandleInfobars() | 110 self._pyauto._HandleInfobars() |
92 self.assertTrue(self.WaitUntil( | 111 self._pyauto.assertTrue(self._pyauto.WaitUntil( |
93 lambda: self.ExecuteJavascript(""" | 112 lambda: self._pyauto.ExecuteJavascript(""" |
94 player_status = nrdp.video.readyState; | 113 player_status = nrdp.video.readyState; |
95 window.domAutomationController.send(player_status + ''); | 114 window.domAutomationController.send(player_status + ''); |
96 """), expect_retval=self._is_playing), | 115 """), expect_retval=self._pyauto.is_playing), |
97 msg='Player did not start playing the title') | 116 msg='Player did not start playing the title.') |
117 | |
118 class NetflixTest(pyauto.PyUITest, NetflixTestHelper): | |
119 """Test case for Netflix player.""" | |
120 | |
121 def __init__(self, methodName='runTest', **kwargs): | |
122 pyauto.PyUITest.__init__(self, methodName, **kwargs) | |
123 NetflixTestHelper.__init__(self, self) | |
124 | |
125 def tearDown(self): | |
126 self._SignOut() | |
127 pyauto.PyUITest.tearDown(self) | |
98 | 128 |
99 def testPlayerLoadsAndPlays(self): | 129 def testPlayerLoadsAndPlays(self): |
100 """Test that Netflix player loads and plays the title""" | 130 """Test that Netflix player loads and plays the title.""" |
101 self._LoginAndStartPlaying() | 131 self._LoginAndStartPlaying() |
102 | 132 |
103 def testPlaying(self): | 133 def testPlaying(self): |
104 """Test that title playing progresses""" | 134 """Test that title playing progresses.""" |
105 self._LoginAndStartPlaying() | 135 self._LoginAndStartPlaying() |
106 title_length = self.ExecuteJavascript(""" | 136 title_length = self.ExecuteJavascript(""" |
107 time = nrdp.video.duration; | 137 time = nrdp.video.duration; |
108 window.domAutomationController.send(time + ''); | 138 window.domAutomationController.send(time + ''); |
109 """) | 139 """) |
110 title_length = int(float(title_length)) | 140 title_length = int(float(title_length)) |
111 prev_time = 0 | 141 prev_time = 0 |
112 current_time = 0 | 142 current_time = 0 |
113 count = 0 | 143 count = 0 |
114 while current_time < title_length: | 144 while current_time < title_length: |
115 # We want to test playing only for ten seconds | 145 # We want to test playing only for ten seconds. |
116 count = count + 1 | 146 count = count + 1 |
117 if count == 10: | 147 if count == 10: |
118 break | 148 break |
119 current_time = self._CurrentPlaybackTime() | 149 current_time = self._CurrentPlaybackTime() |
120 self.assertTrue(prev_time <= current_time, | 150 self.assertTrue(prev_time <= current_time, |
121 msg='Prev playing time %s is greater than current time %s' | 151 msg='Prev playing time %s is greater than current time %s.' |
122 % (prev_time, current_time)) | 152 % (prev_time, current_time)) |
123 prev_time = current_time | 153 prev_time = current_time |
124 # play video for some time | 154 # play video for some time |
125 time.sleep(1) | 155 time.sleep(1) |
126 # crosbug.com/22037 | 156 # crosbug.com/22037 |
127 # In case player doesn't start playing at all, above while loop may | 157 # In case player doesn't start playing at all, above while loop may |
128 # still pass. So re-verifying and assuming that player did play something | 158 # still pass. So re-verifying and assuming that player did play something |
129 # during last 10 seconds. | 159 # during last 10 seconds. |
130 self.assertTrue(current_time > 0, | 160 self.assertTrue(current_time > 0, |
131 msg='Netflix player didnot start playing') | 161 msg='Netflix player didnot start playing.') |
132 | 162 |
133 | 163 |
134 if __name__ == '__main__': | 164 if __name__ == '__main__': |
135 pyauto_functional.Main() | 165 pyauto_functional.Main() |
OLD | NEW |