OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium 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 """The testing Environment class.""" | 5 """The testing Environment class.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import shutil | 8 import shutil |
9 import sys | 9 import sys |
10 import time | 10 import time |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 self.passwords_tree = ElementTree.parse(passwords_path).getroot() | 111 self.passwords_tree = ElementTree.parse(passwords_path).getroot() |
112 else: | 112 else: |
113 raise Exception("Error: |passwords_path| needs to be provided if" | 113 raise Exception("Error: |passwords_path| needs to be provided if" |
114 "|chrome_path| is provided, otherwise the tests could not be run") | 114 "|chrome_path| is provided, otherwise the tests could not be run") |
115 # Password internals page. | 115 # Password internals page. |
116 self.internals_page = "chrome://password-manager-internals/" | 116 self.internals_page = "chrome://password-manager-internals/" |
117 # The Website window. | 117 # The Website window. |
118 self.website_window = None | 118 self.website_window = None |
119 # The WebsiteTests list. | 119 # The WebsiteTests list. |
120 self.websitetests = [] | 120 self.websitetests = [] |
121 # The enabled WebsiteTests list. | |
122 self.working_tests = [] | |
123 # The disabled WebsiteTests list. | |
124 self.disabled_tests = [] | |
125 # Map messages to the number of their appearance in the log. | 121 # Map messages to the number of their appearance in the log. |
126 self.message_count = dict() | 122 self.message_count = dict() |
127 self.message_count[MESSAGE_ASK] = 0 | 123 self.message_count[MESSAGE_ASK] = 0 |
128 self.message_count[MESSAGE_SAVE] = 0 | 124 self.message_count[MESSAGE_SAVE] = 0 |
129 # The tests needs two tabs to work. A new tab is opened with the first | 125 # The tests needs two tabs to work. A new tab is opened with the first |
130 # GoTo. This is why we store here whether or not it's the first time to | 126 # GoTo. This is why we store here whether or not it's the first time to |
131 # execute GoTo. | 127 # execute GoTo. |
132 self.first_go_to = True | 128 self.first_go_to = True |
133 # List of all tests results. | 129 # List of all tests results. |
134 self.tests_results = [] | 130 self.tests_results = [] |
135 | 131 |
136 def AddWebsiteTest(self, websitetest, disabled=False): | 132 def AddWebsiteTest(self, websitetest): |
137 """Adds a WebsiteTest to the testing Environment. | 133 """Adds a WebsiteTest to the testing Environment. |
138 | 134 |
139 Args: | 135 Args: |
140 websitetest: The WebsiteTest instance to be added. | 136 websitetest: The WebsiteTest instance to be added. |
141 disabled: Whether test is disabled. | |
142 """ | 137 """ |
143 websitetest.environment = self | 138 websitetest.environment = self |
144 if hasattr(self, "driver"): | 139 if hasattr(self, "driver"): |
145 websitetest.driver = self.driver | 140 websitetest.driver = self.driver |
146 if hasattr(self, "passwords_tree") and self.passwords_tree is not None: | 141 if hasattr(self, "passwords_tree") and self.passwords_tree is not None: |
147 if not websitetest.username: | 142 if not websitetest.username: |
148 username_tag = ( | 143 username_tag = ( |
149 self.passwords_tree.find( | 144 self.passwords_tree.find( |
150 ".//*[@name='%s']/username" % websitetest.name)) | 145 ".//*[@name='%s']/username" % websitetest.name)) |
151 if username_tag.text: | 146 if username_tag.text: |
152 websitetest.username = username_tag.text | 147 websitetest.username = username_tag.text |
153 if not websitetest.password: | 148 if not websitetest.password: |
154 password_tag = ( | 149 password_tag = ( |
155 self.passwords_tree.find( | 150 self.passwords_tree.find( |
156 ".//*[@name='%s']/password" % websitetest.name)) | 151 ".//*[@name='%s']/password" % websitetest.name)) |
157 if password_tag.text: | 152 if password_tag.text: |
158 websitetest.password = password_tag.text | 153 websitetest.password = password_tag.text |
159 self.websitetests.append(websitetest) | 154 self.websitetests.append(websitetest) |
160 if disabled: | |
161 self.disabled_tests.append(websitetest.name) | |
162 else: | |
163 self.working_tests.append(websitetest.name) | |
164 | 155 |
165 def ClearCache(self, clear_passwords): | 156 def ClearCache(self, clear_passwords): |
166 """Clear the browser cookies. If |clear_passwords| is true, clear all the | 157 """Clear the browser cookies. If |clear_passwords| is true, clear all the |
167 saved passwords too. | 158 saved passwords too. |
168 | 159 |
169 Args: | 160 Args: |
170 clear_passwords : Clear all the passwords if the bool value is true. | 161 clear_passwords : Clear all the passwords if the bool value is true. |
171 """ | 162 """ |
172 logging.info("\nClearCache\n") | 163 logging.info("\nClearCache\n") |
173 self.driver.get("chrome://settings/clearBrowserData") | 164 self.driver.get("chrome://settings/clearBrowserData") |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 the prompt are going to be run. | 300 the prompt are going to be run. |
310 | 301 |
311 Raises: | 302 Raises: |
312 Exception: An exception is raised if the tests fail. | 303 Exception: An exception is raised if the tests fail. |
313 """ | 304 """ |
314 if prompt_test: | 305 if prompt_test: |
315 self.PromptTestList(self.websitetests) | 306 self.PromptTestList(self.websitetests) |
316 else: | 307 else: |
317 self.TestList(self.websitetests) | 308 self.TestList(self.websitetests) |
318 | 309 |
319 def DisabledTests(self, prompt_test): | |
320 """Runs the tests on all the disabled WebsiteTests. | |
321 | |
322 Args: | |
323 prompt_test: If True, tests caring about showing the save-password | |
324 prompt are going to be run, otherwise tests which don't care about | |
325 the prompt are going to be executed. | |
326 | |
327 Raises: | |
328 Exception: An exception is raised if the tests fail. | |
329 """ | |
330 self.Test(self.disabled_tests, prompt_test) | |
331 | |
332 def WorkingTests(self, prompt_test): | |
333 """Runs the tests on all the enabled WebsiteTests. | |
334 | |
335 Args: | |
336 prompt_test: If True, tests caring about showing the save-password | |
337 prompt are going to be run, otherwise tests which don't care about | |
338 the prompt are going to be executed. | |
339 | |
340 Raises: | |
341 Exception: An exception is raised if the tests fail. | |
342 """ | |
343 self.Test(self.working_tests, prompt_test) | |
344 | |
345 def Test(self, tests, prompt_test): | 310 def Test(self, tests, prompt_test): |
346 """Runs the tests on websites named in |tests|. | 311 """Runs the tests on websites named in |tests|. |
347 | 312 |
348 Args: | 313 Args: |
349 tests: A list of the names of the WebsiteTests that are going to be | 314 tests: A list of the names of the WebsiteTests that are going to be |
350 tested. | 315 tested. |
351 prompt_test: If True, tests caring about showing the save-password | 316 prompt_test: If True, tests caring about showing the save-password |
352 prompt are going to be run, otherwise tests which don't care about | 317 prompt are going to be run, otherwise tests which don't care about |
353 the prompt are going to be executed. | 318 the prompt are going to be executed. |
354 | 319 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 except Exception as e: | 380 except Exception as e: |
416 successful = False | 381 successful = False |
417 error = e.message | 382 error = e.message |
418 self.tests_results.append(TestResult(websitetest.name, "prompt", | 383 self.tests_results.append(TestResult(websitetest.name, "prompt", |
419 successful, error)) | 384 successful, error)) |
420 | 385 |
421 def Quit(self): | 386 def Quit(self): |
422 """Closes the tests.""" | 387 """Closes the tests.""" |
423 # Close the webdriver. | 388 # Close the webdriver. |
424 self.driver.quit() | 389 self.driver.quit() |
OLD | NEW |