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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rlz_test/rlztest.py
===================================================================
--- rlz_test/rlztest.py (revision 0)
+++ rlz_test/rlztest.py (revision 0)
@@ -0,0 +1,208 @@
+import subprocess
+import sys
+import selenium.selenium
+import re
+import unittest
+import commands
+import time
+import _winreg
+import logging
+import optparse
+import logging
+import selenium.webdriver.common.keys
+import os
+
+from selenium import webdriver
+#from rlz_tester import RlzTester
+from chromium_proxy_server_version2 import Main
+from chromium_proxy_server_version3 import ChromiumProxyServer
+from subprocess import Popen, PIPE, STDOUT
+from selenium.webdriver.common.keys import Keys as Keys
+
+
+class RlzTest(unittest.TestCase):
+
+ def setUp(self):
+ """Performs necessary setup work before running each test in this class."""
+ # Delete RLZ key Folder
+ self.deleteRegistryKey()
+ # Launch Proxy Server
+ print ('Serving clients: 127.0.0.1')
+ self.proxy_server = subprocess.Popen([
+ 'python',
+ '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
+ '--client=127.0.0.1',
+ '--port=8080',
+ '--urls=http://clients1.google.com/tools/pso/ping,www.google.com'])
+
+ print('\nLaunching Chrome...')
+ # Launch chrome and set proxy.
+ service = webdriver.chrome.service.Service(
+ 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
+ service.start()
+ self.driver = webdriver.Remote(
+ service.service_url, {
+ 'proxy': {'proxyType': 'manual', 'httpProxy': 'localhost:8080'},
+ 'chrome.switches': ['disable-extensions'],
+ 'chrome.nativeEvents': True})
+
+ def tearDown(self):
+ """Kills the chrome driver after after the test method has been called."""
+ # Terminate the chrome driver.
+ print '\nTerminating Chrome Driver...'
+ self.driver.quit()
+ # Kill proxy server.
+ print '\nKilling Proxy Server...'
+ subprocess.Popen.kill(self.proxy_server)
+
+ def deleteRegistryKey(self):
+ """Delete RLZ key Folder from win registry."""
+ try:
+ hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz')
+ except _winreg.error, err:
+ return True
+ if(hkey):
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\Events\C')
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\StatefulEvents\C')
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\Events')
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\StatefulEvents')
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\PTimes')
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\RLZs')
+ _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz')
+
+ 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.
+ """Get the values for particular subkey"""
+ list_names =[]
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 space before []
prachij 2012/09/11 21:04:19 Done.
+ counter = 0
+ try:
+ hkey = _winreg.OpenKey(key, subkey)
+ except _winreg.error, err:
+ return -1
+ while True:
+ try:
+ value = _winreg.EnumValue(hkey, counter)
+ list_names.append(value[0])
+ counter+=1
+ #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.
+ except _winreg.error:
+ break
+ hkey.Close()
+ return list_names
+
+ def testRlzPingAtFirstChromeLaunch(self):
+ """Test rlz ping when chrome is lauched for first time."""
+ # Check the ping in Events folder in registry.
+ time.sleep(2)
Roger Tawa OOO till Jul 10th 2012/09/11 00:29:42 why sleep?
+ list_key=[]
+ list_key=self.GetKeyValues(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\Events\C')
+ print '\nList of event reported to registry-'\
+ '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.
+ #self.assertEqual('C1S', list_key[0])
+ #self.assertEqual('C2I', list_key[1])
+
+ # Wait for 90 sec till chrome sends ping to server.
+ 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
+ self.driver.get('http://www.google.com')
+
+ # Open log file and validate events chrome launch(C1I,C2I,C1S)
+ # are appended in ping.
+ 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 :-)
+ event_start = contents.find('events=')
+ event_end = contents.find('&rep', event_start)
+ events=contents[event_start+7:event_end]
+ events_List=events.split(',')
+ self.assertTrue('C1S' in events_List)
+ self.assertTrue('C1I' in events_List)
+ self.assertTrue('C2I' in events_List)
+
+ # Validate brand code in url ping.
+ self.assertTrue(re.search('CHMZ', contents))
+
+ # Print first chrome launch ping on Console.
+ start = contents.find('http://clients1.google.com/tools/'+
+ 'pso/ping?as=chrome&brand=CHMZ')
+ end = contents.find('HTTP', start)
+ print '\nChrome Launch ping send :\n', contents[start:end]
+
+ # Validate events in win registry.
+ list_key=[]
+ list_key=self.GetKeyValues(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\StatefulEvents\C')
+ desc="""'\nList of event reported to registry-
+ Software\Google\Common\Rlz\StatefulEvents:"""
+ print desc, list_key
+ self.assertEqual('C1I', list_key[0])
+ self.assertEqual('C2I', list_key[1])
+
+ def testRlzPingForFirstSearch(self):
+ """Test rlz ping when first search is performed in chrome."""
+ # Type search string in omnibox.
+ self.driver.switch_to_active_element().send_keys(Keys.CONTROL + 'l')
+ self.driver.switch_to_active_element().send_keys('java')
+ self.driver.switch_to_active_element().send_keys(Keys.ENTER)
+ time.sleep(2)
+ print '\nCurrent Url before chrome ping is sent:\n',
+ self.driver.current_url
+
+ # Assert brand code 'CHMZ' is not appended in search string.
+ self.assertFalse(re.search('CHMZ', self.driver.current_url))
+
+ # Wait for 90 sec till chrome sends ping to server.
+ time.sleep(90)
+
+ # Open log file and validate events chrome launch(C1I,C2I,C1S)
+ # and first search(C1F) are appended in ping.
+ contents = open(os.getcwd()+'\ServerXXX.log', 'r', 1).read()
+ event_start = contents.find('events=')
+ event_end = contents.find('&rep', event_start)
+ events=contents[event_start+7:event_end]
+ events_List=events.split(',')
+ self.assertTrue('C1S' in events_List)
+ self.assertTrue('C1I' in events_List)
+ self.assertTrue('C2I' in events_List)
+ self.assertTrue('C1F' in events_List)
+
+ # Print first chrome launch /default first search ping on Console.
+ start = contents.find('http://clients1.google.com/tools/pso/'+
+ 'ping?as=chrome&brand=CHMZ')
+ end = contents.find('HTTP', start)
+ print '\nChrome Launch ping send\n', contents[start:end]
+
+ # Type search string in omnibox after ping is sent to server.
+ self.driver.switch_to_active_element().send_keys(Keys.CONTROL + 'l')
+ self.driver.switch_to_active_element().send_keys('java')
+ self.driver.switch_to_active_element().send_keys(Keys.ENTER)
+ time.sleep(2)
+ print '\nCurrent Url after chrome ping is sent:\n',
+ self.driver.current_url
+
+ # Assert brand code 'CHMZ' is appended in search string.
+ self.assertTrue(re.search('CHMZ', self.driver.current_url))
+
+ # Validate events in win registry.
+ list_key=[]
+ list_key=self.GetKeyValues(_winreg.HKEY_CURRENT_USER,
+ 'Software\Google\Common\Rlz\StatefulEvents\C')
+ desc = """\nList of event reported to registry-
+ Software\Google\Common\Rlz\StatefulEvents:\n"""
+ print '\nList of event reported to registry-'\
+ 'Software\Google\Common\Rlz\StatefulEvents:\n', list_key
+ self.assertTrue('C1I' in list_key)
+ self.assertTrue('C2I' in list_key)
+ self.assertTrue('C1F' in list_key)
+
+ def runTest(self):
+ pass
+
+if __name__ == '__main__':
+ unittest.main()
+
« 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