Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: rlz_test/rlztest.py

Issue 10910145: Added rlz testcases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import subprocess
2 import sys
3 import selenium.selenium
4 import re
5 import unittest
6 import commands
7 import time
8 import _winreg
9 import logging
10 import optparse
11 import logging
12 import selenium.webdriver.common.keys
13 import os
14
15 from selenium import webdriver
16 #from rlz_tester import RlzTester
17 from chromium_proxy_server_version2 import Main
18 from chromium_proxy_server_version3 import ChromiumProxyServer
19 from subprocess import Popen, PIPE, STDOUT
20 from selenium.webdriver.common.keys import Keys as Keys
21
22
23 class RlzTest(unittest.TestCase):
24
25 def setUp(self):
26 """Performs necessary setup work before running each test in this class."""
27 # Delete RLZ key Folder
28 self.deleteRegistryKey()
29 # Launch Proxy Server
30 print ('Serving clients: 127.0.0.1')
31 self.proxy_server = subprocess.Popen([
32 'python',
33 'chromium_proxy_server_version3.py',
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 is this file name correct?
prachij 2012/09/11 21:04:19 As we were making quite lot of changes to proxy se
34 '--client=127.0.0.1',
35 '--port=8080',
36 '--urls=http://clients1.google.com/tools/pso/ping,www.google.com'])
37
38 print('\nLaunching Chrome...')
39 # Launch chrome and set proxy.
40 service = webdriver.chrome.service.Service(
41 r'C:\Users\prachij\chromedriver.exe')
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 path is hardcoded to your own home dir. Should ma
prachij 2012/09/11 21:04:19 changed to take it from command line. On 2012/09/1
42 service.start()
43 self.driver = webdriver.Remote(
44 service.service_url, {
45 'proxy': {'proxyType': 'manual', 'httpProxy': 'localhost:8080'},
46 'chrome.switches': ['disable-extensions'],
47 'chrome.nativeEvents': True})
48
49 def tearDown(self):
50 """Kills the chrome driver after after the test method has been called."""
51 # Terminate the chrome driver.
52 print '\nTerminating Chrome Driver...'
53 self.driver.quit()
54 # Kill proxy server.
55 print '\nKilling Proxy Server...'
56 subprocess.Popen.kill(self.proxy_server)
57
58 def deleteRegistryKey(self):
59 """Delete RLZ key Folder from win registry."""
60 try:
61 hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
62 'Software\Google\Common\Rlz')
63 except _winreg.error, err:
64 return True
65 if(hkey):
66 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
67 'Software\Google\Common\Rlz\Events\C')
68 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
69 'Software\Google\Common\Rlz\StatefulEvents\C')
70 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
71 'Software\Google\Common\Rlz\Events')
72 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
73 'Software\Google\Common\Rlz\StatefulEvents')
74 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
75 'Software\Google\Common\Rlz\PTimes')
76 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
77 'Software\Google\Common\Rlz\RLZs')
78 _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
79 'Software\Google\Common\Rlz')
80
81 def GetKeyValues(self,key, subkey):
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 add space before key
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 I think it should be GetKeyValueNames().
prachij 2012/09/11 21:04:19 Done.
prachij 2012/09/11 21:04:19 Done.
82 """Get the values for particular subkey"""
83 list_names =[]
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 space before []
prachij 2012/09/11 21:04:19 Done.
84 counter = 0
85 try:
86 hkey = _winreg.OpenKey(key, subkey)
87 except _winreg.error, err:
88 return -1
89 while True:
90 try:
91 value = _winreg.EnumValue(hkey, counter)
92 list_names.append(value[0])
93 counter+=1
94 #print list_names
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 remove line
prachij 2012/09/11 21:04:19 Done.
95 except _winreg.error:
96 break
97 hkey.Close()
98 return list_names
99
100 def testRlzPingAtFirstChromeLaunch(self):
101 """Test rlz ping when chrome is lauched for first time."""
102 # Check the ping in Events folder in registry.
103 time.sleep(2)
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 why sleep?
104 list_key=[]
105 list_key=self.GetKeyValues(_winreg.HKEY_CURRENT_USER,
106 'Software\Google\Common\Rlz\Events\C')
107 print '\nList of event reported to registry-'\
108 'Software\Google\Common\Rlz\Events :\n',list_key
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 don't use \ at end. do this: print ('...long s
prachij 2012/09/11 21:04:19 Done.
109 #self.assertEqual('C1S', list_key[0])
110 #self.assertEqual('C2I', list_key[1])
111
112 # Wait for 90 sec till chrome sends ping to server.
113 time.sleep(90)
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 this could ne flaky. should probably wait a littl
prachij 2012/09/11 21:04:19 Till now I haven't seen this flaky, but may be you
114 self.driver.get('http://www.google.com')
115
116 # Open log file and validate events chrome launch(C1I,C2I,C1S)
117 # are appended in ping.
118 contents = open(os.getcwd()+'\ServerXXX.log', 'r', 1).read()
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 ServerXXX.log ?
prachij 2012/09/11 21:04:19 This is global log file created my proxy server wh
Roger Tawa OOO till Jul 10th 2012/09/14 19:43:36 Hmmm, should probably choose a better name :-)
119 event_start = contents.find('events=')
120 event_end = contents.find('&rep', event_start)
121 events=contents[event_start+7:event_end]
122 events_List=events.split(',')
123 self.assertTrue('C1S' in events_List)
124 self.assertTrue('C1I' in events_List)
125 self.assertTrue('C2I' in events_List)
126
127 # Validate brand code in url ping.
128 self.assertTrue(re.search('CHMZ', contents))
129
130 # Print first chrome launch ping on Console.
131 start = contents.find('http://clients1.google.com/tools/'+
132 'pso/ping?as=chrome&brand=CHMZ')
133 end = contents.find('HTTP', start)
134 print '\nChrome Launch ping send :\n', contents[start:end]
135
136 # Validate events in win registry.
137 list_key=[]
138 list_key=self.GetKeyValues(_winreg.HKEY_CURRENT_USER,
139 'Software\Google\Common\Rlz\StatefulEvents\C')
140 desc="""'\nList of event reported to registry-
141 Software\Google\Common\Rlz\StatefulEvents:"""
142 print desc, list_key
143 self.assertEqual('C1I', list_key[0])
144 self.assertEqual('C2I', list_key[1])
145
146 def testRlzPingForFirstSearch(self):
147 """Test rlz ping when first search is performed in chrome."""
148 # Type search string in omnibox.
149 self.driver.switch_to_active_element().send_keys(Keys.CONTROL + 'l')
150 self.driver.switch_to_active_element().send_keys('java')
151 self.driver.switch_to_active_element().send_keys(Keys.ENTER)
152 time.sleep(2)
153 print '\nCurrent Url before chrome ping is sent:\n',
154 self.driver.current_url
155
156 # Assert brand code 'CHMZ' is not appended in search string.
157 self.assertFalse(re.search('CHMZ', self.driver.current_url))
158
159 # Wait for 90 sec till chrome sends ping to server.
160 time.sleep(90)
161
162 # Open log file and validate events chrome launch(C1I,C2I,C1S)
163 # and first search(C1F) are appended in ping.
164 contents = open(os.getcwd()+'\ServerXXX.log', 'r', 1).read()
165 event_start = contents.find('events=')
166 event_end = contents.find('&rep', event_start)
167 events=contents[event_start+7:event_end]
168 events_List=events.split(',')
169 self.assertTrue('C1S' in events_List)
170 self.assertTrue('C1I' in events_List)
171 self.assertTrue('C2I' in events_List)
172 self.assertTrue('C1F' in events_List)
173
174 # Print first chrome launch /default first search ping on Console.
175 start = contents.find('http://clients1.google.com/tools/pso/'+
176 'ping?as=chrome&brand=CHMZ')
177 end = contents.find('HTTP', start)
178 print '\nChrome Launch ping send\n', contents[start:end]
179
180 # Type search string in omnibox after ping is sent to server.
181 self.driver.switch_to_active_element().send_keys(Keys.CONTROL + 'l')
182 self.driver.switch_to_active_element().send_keys('java')
183 self.driver.switch_to_active_element().send_keys(Keys.ENTER)
184 time.sleep(2)
185 print '\nCurrent Url after chrome ping is sent:\n',
186 self.driver.current_url
187
188 # Assert brand code 'CHMZ' is appended in search string.
189 self.assertTrue(re.search('CHMZ', self.driver.current_url))
190
191 # Validate events in win registry.
192 list_key=[]
193 list_key=self.GetKeyValues(_winreg.HKEY_CURRENT_USER,
194 'Software\Google\Common\Rlz\StatefulEvents\C')
195 desc = """\nList of event reported to registry-
196 Software\Google\Common\Rlz\StatefulEvents:\n"""
197 print '\nList of event reported to registry-'\
198 'Software\Google\Common\Rlz\StatefulEvents:\n', list_key
199 self.assertTrue('C1I' in list_key)
200 self.assertTrue('C2I' in list_key)
201 self.assertTrue('C1F' in list_key)
202
203 def runTest(self):
204 pass
205
206 if __name__ == '__main__':
207 unittest.main()
208
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698