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

Side by Side Diff: client/site_tests/login_ChromeProfileSanitary/login_ChromeProfileSanitary.py

Issue 1534001: switch to autox.py and robustify login/logout code (Closed)
Patch Set: merge with head Created 10 years, 8 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
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging, os, stat, time, utils 5 import logging, os, stat, time, utils
6 from autotest_lib.client.bin import chromeos_constants, site_cryptohome 6 from autotest_lib.client.bin import chromeos_constants, site_cryptohome
7 from autotest_lib.client.bin import site_login, test 7 from autotest_lib.client.bin import site_login, site_ui_test
8 from autotest_lib.client.common_lib import error, site_httpd, site_ui 8 from autotest_lib.client.common_lib import error, site_httpd, site_ui
9 9
10 def respond_with_cookies(handler, url_args): 10 def respond_with_cookies(handler, url_args):
11 """Responds with a Set-Cookie header to any GET request, and redirects 11 """Responds with a Set-Cookie header to any GET request, and redirects
12 to a chosen URL. 12 to a chosen URL.
13 """ 13 """
14 handler.send_response(303) 14 handler.send_response(303)
15 handler.send_header('Set-Cookie', 'name=value') 15 handler.send_header('Set-Cookie', 'name=value')
16 handler.send_header('Location', url_args['continue'][0]) 16 handler.send_header('Location', url_args['continue'][0])
17 handler.end_headers() 17 handler.end_headers()
18 handler.wfile.write('Got form data:\n') 18 handler.wfile.write('Got form data:\n')
19 handler.wfile.write('%s:\n' % url_args) 19 handler.wfile.write('%s:\n' % url_args)
20 20
21 21
22 class login_ChromeProfileSanitary(test.test): 22 class login_ChromeProfileSanitary(site_ui_test.UITest):
23 version = 1 23 version = 1
24 24
25 def __wait_for_login_profile(self, timeout = 10): 25 def __wait_for_login_profile(self, timeout=10):
26 start_time = time.time() 26 start_time = time.time()
27 while time.time() - start_time < timeout: 27 while time.time() - start_time < timeout:
28 if os.path.exists(chromeos_constants.LOGIN_PROFILE + '/Cookies'): 28 if os.path.exists(chromeos_constants.LOGIN_PROFILE + '/Cookies'):
29 break; 29 break;
30 time.sleep(1) 30 time.sleep(1)
31 else: 31 else:
32 raise error.TestError('Login Profile took too long to populate') 32 raise error.TestError('Login Profile took too long to populate')
33 33
34 34
35 def initialize(self): 35 def initialize(self, creds='$default'):
36 spec = 'http://localhost:8000' 36 spec = 'http://localhost:8000'
37 path = '/set_cookie' 37 path = '/set_cookie'
38 self._wait_path = '/test_over' 38 self._wait_path = '/test_over'
39 self._test_url = spec + path + '?continue=' + spec + self._wait_path 39 self._test_url = spec + path + '?continue=' + spec + self._wait_path
40 self._testServer = site_httpd.HTTPListener(8000, docroot=self.srcdir) 40 self._testServer = site_httpd.HTTPListener(8000, docroot=self.srcdir)
41 self._testServer.add_url_handler('/set_cookie', respond_with_cookies) 41 self._testServer.add_url_handler('/set_cookie', respond_with_cookies)
42 self._testServer.run() 42 self._testServer.run()
43 43
44 44 site_ui_test.UITest.initialize(self, creds)
45 def setup(self):
46 site_login.setup_autox(self)
47 45
48 46
49 def cleanup(self): 47 def cleanup(self):
50 self._testServer.stop() 48 self._testServer.stop()
49 site_ui_test.UITest.cleanup(self)
51 50
52 51
53 def run_once(self, script = 'autox_script.json', timeout = 10): 52 def run_once(self, timeout = 10):
54 logged_in = site_login.logged_in()
55
56 if not logged_in:
57 # Test account information embedded into json file.
58 site_login.attempt_login(self, script)
59
60 # Get Default/Cookies mtime. 53 # Get Default/Cookies mtime.
61 cookies_info = os.stat(chromeos_constants.LOGIN_PROFILE + '/Cookies') 54 cookies_info = os.stat(chromeos_constants.LOGIN_PROFILE + '/Cookies')
62 cookies_mtime = cookies_info[stat.ST_MTIME] 55 cookies_mtime = cookies_info[stat.ST_MTIME]
63 56
64 # "crash" chrome. 57 # "crash" chrome.
65 site_login.wait_for_initial_chrome_window() 58 site_login.wait_for_initial_chrome_window()
66 site_login.nuke_process_by_name(chromeos_constants.BROWSER, 59 site_login.nuke_process_by_name(chromeos_constants.BROWSER,
67 with_prejudice = True) 60 with_prejudice = True)
68 site_login.wait_for_browser() 61 site_login.wait_for_browser()
69 62
70 # Navigate to site that leaves cookies. 63 # Navigate to site that leaves cookies.
71 latch = self._testServer.add_wait_url(self._wait_path) 64 latch = self._testServer.add_wait_url(self._wait_path)
72 cookie_fetch_args = ("--user-data-dir=" + 65 cookie_fetch_args = ("--user-data-dir=" +
73 chromeos_constants.USER_DATA_DIR + ' ' + 66 chromeos_constants.USER_DATA_DIR + ' ' +
74 self._test_url) 67 self._test_url)
75 session = site_ui.ChromeSession(args=cookie_fetch_args, 68 session = site_ui.ChromeSession(args=cookie_fetch_args,
76 clean_state=False) 69 clean_state=False)
77 logging.debug('Chrome session started.') 70 logging.debug('Chrome session started.')
78 latch.wait(timeout) 71 latch.wait(timeout)
79 72
80 # Ensure chrome writes state to disk. 73 # Ensure chrome writes state to disk.
81 site_login.attempt_logout() 74 self.logout()
82 site_login.attempt_login(self, script) 75 self.login()
83 76
84 if not latch.is_set(): 77 if not latch.is_set():
85 raise error.TestError('Never received callback from browser.') 78 raise error.TestError('Never received callback from browser.')
86 79
87 # Check mtime of Default/Cookies. If changed, KABLOOEY. 80 # Check mtime of Default/Cookies. If changed, KABLOOEY.
88 self.__wait_for_login_profile() 81 self.__wait_for_login_profile()
89 cookies_info = os.stat(chromeos_constants.LOGIN_PROFILE + '/Cookies') 82 cookies_info = os.stat(chromeos_constants.LOGIN_PROFILE + '/Cookies')
90 # TODO: Note that this currently (20100329) fails and will continue to 83 # TODO: Note that this currently (20100329) fails and will continue to
91 # do so until http://crosbug.com/1967 is fixed. 84 # do so until http://crosbug.com/1967 is fixed.
92 if cookies_mtime != cookies_info[stat.ST_MTIME]: 85 if cookies_mtime != cookies_info[stat.ST_MTIME]:
93 raise error.TestFail('Cookies in Default profile changed!') 86 raise error.TestFail('Cookies in Default profile changed!')
94
95 # If we started logged out, log back out.
96 if not logged_in:
97 site_login.attempt_logout()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698