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 import logging | 5 import logging |
6 import os | 6 import os |
7 import unittest | 7 import unittest |
8 | 8 |
9 from telemetry.core import browser_credentials | 9 from telemetry.core import browser_credentials |
10 from telemetry.core import discover | 10 from telemetry.core import discover |
11 from telemetry.page import page_set as page_set_module | 11 from telemetry.page import page_set as page_set_module |
12 from telemetry.page import page_set_archive_info | 12 from telemetry.page import page_set_archive_info |
13 from telemetry.util import classes | |
13 | 14 |
14 | 15 |
15 class PageSetSmokeTest(unittest.TestCase): | 16 class PageSetSmokeTest(unittest.TestCase): |
16 | 17 |
17 def CheckArchive(self, page_set): | 18 def CheckArchive(self, page_set): |
18 """Verify that all URLs of pages in page_set have an associated archive. """ | 19 """Verify that all URLs of pages in page_set have an associated archive. """ |
19 # TODO: Eventually these should be fatal. | 20 # TODO: Eventually these should be fatal. |
20 if not page_set.archive_data_file: | 21 if not page_set.archive_data_file: |
21 logging.warning('Skipping %s: no archive data file', page_set.file_path) | 22 logging.warning('Skipping %s: no archive data file', page_set.file_path) |
22 return | 23 return |
(...skipping 10 matching lines...) Expand all Loading... | |
33 archive_data_file_path, ignore_archive=True) | 34 archive_data_file_path, ignore_archive=True) |
34 for page in page_set.pages: | 35 for page in page_set.pages: |
35 if not page.url.startswith('http'): | 36 if not page.url.startswith('http'): |
36 continue | 37 continue |
37 self.assertTrue(wpr_archive_info.WprFilePathForPage(page), | 38 self.assertTrue(wpr_archive_info.WprFilePathForPage(page), |
38 msg='No archive found for %s in %s' % ( | 39 msg='No archive found for %s in %s' % ( |
39 page.url, page_set.archive_data_file)) | 40 page.url, page_set.archive_data_file)) |
40 | 41 |
41 def CheckCredentials(self, page_set): | 42 def CheckCredentials(self, page_set): |
42 """Verify that all pages in page_set use proper credentials""" | 43 """Verify that all pages in page_set use proper credentials""" |
43 credentials = browser_credentials.BrowserCredentials() | |
44 if page_set.credentials_path: | |
45 credentials.credentials_path = ( | |
46 os.path.join(page_set.base_dir, page_set.credentials_path)) | |
47 for page in page_set.pages: | 44 for page in page_set.pages: |
45 credentials = browser_credentials.BrowserCredentials() | |
46 if page.credentials_path: | |
47 credentials.credentials_path = ( | |
48 os.path.join(page.base_dir, page.credentials_path)) | |
48 fail_message = ('page %s of %s has invalid credentials %s' % | 49 fail_message = ('page %s of %s has invalid credentials %s' % |
49 (page.url, page_set.file_path, page.credentials)) | 50 (page.url, page_set.file_path, page.credentials)) |
50 if page.credentials: | 51 if page.credentials: |
51 try: | 52 try: |
52 self.assertTrue(credentials.CanLogin(page.credentials), fail_message) | 53 self.assertTrue(credentials.CanLogin(page.credentials), fail_message) |
53 except browser_credentials.CredentialsError: | 54 except browser_credentials.CredentialsError: |
54 self.fail(fail_message) | 55 self.fail(fail_message) |
55 | 56 |
56 def CheckAttributes(self, page_set): | 57 def CheckAttributes(self, page_set): |
57 """Verify that page_set and its page's base attributes have the right types. | 58 """Verify that page_set and its page's base attributes have the right types. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 """Run smoke test on all page sets in page_sets_dir. | 101 """Run smoke test on all page sets in page_sets_dir. |
101 | 102 |
102 Subclass of PageSetSmokeTest is supposed to call this in some test | 103 Subclass of PageSetSmokeTest is supposed to call this in some test |
103 method to run smoke test. | 104 method to run smoke test. |
104 """ | 105 """ |
105 page_sets = discover.DiscoverClasses(page_sets_dir, top_level_dir, | 106 page_sets = discover.DiscoverClasses(page_sets_dir, top_level_dir, |
106 page_set_module.PageSet).values() | 107 page_set_module.PageSet).values() |
107 for page_set_class in page_sets: | 108 for page_set_class in page_sets: |
108 try: | 109 try: |
109 page_set = page_set_class() | 110 page_set = page_set_class() |
110 except TypeError: | 111 except TypeError: |
dtu
2014/10/06 21:30:22
What is this except block for in the first place?
nednguyen
2014/10/07 20:11:09
There are some page_set that aren't directly const
dtu
2014/10/08 21:34:18
Interesting, okay.
| |
112 if classes.IsDirectlyConstructable(page_set_class): | |
113 raise | |
111 continue | 114 continue |
112 logging.info('Testing %s', page_set.file_path) | 115 logging.info('Testing %s', page_set.file_path) |
113 self.CheckArchive(page_set) | 116 self.CheckArchive(page_set) |
114 self.CheckCredentials(page_set) | 117 self.CheckCredentials(page_set) |
115 self.CheckAttributes(page_set) | 118 self.CheckAttributes(page_set) |
OLD | NEW |