OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import os | 4 import os |
5 import re | 5 import re |
6 import time | |
7 import urlparse | 6 import urlparse |
8 | 7 |
9 from telemetry.core import util | 8 from telemetry.page.actions import navigate |
10 | 9 |
11 def _UrlPathJoin(*args): | 10 def _UrlPathJoin(*args): |
12 """Joins each path in |args| for insertion into a URL path. | 11 """Joins each path in |args| for insertion into a URL path. |
13 | 12 |
14 This is distinct from os.path.join in that: | 13 This is distinct from os.path.join in that: |
15 1. Forward slashes are always used. | 14 1. Forward slashes are always used. |
16 2. Paths beginning with '/' are not treated as absolute. | 15 2. Paths beginning with '/' are not treated as absolute. |
17 | 16 |
18 For example: | 17 For example: |
19 _UrlPathJoin('a', 'b') => 'a/b' | 18 _UrlPathJoin('a', 'b') => 'a/b' |
(...skipping 28 matching lines...) Expand all Loading... | |
48 else: | 47 else: |
49 raise Exception('URLs must be fully qualified: %s' % url) | 48 raise Exception('URLs must be fully qualified: %s' % url) |
50 self.url = url | 49 self.url = url |
51 self.page_set = page_set | 50 self.page_set = page_set |
52 self.base_dir = base_dir | 51 self.base_dir = base_dir |
53 | 52 |
54 # These attributes can be set dynamically by the page. | 53 # These attributes can be set dynamically by the page. |
55 self.credentials = None | 54 self.credentials = None |
56 self.disabled = False | 55 self.disabled = False |
57 self.script_to_evaluate_on_commit = None | 56 self.script_to_evaluate_on_commit = None |
57 self.navigate_actions = [navigate.NavigateAction()] | |
edmundyan
2013/08/20 23:02:40
This is to address the TODO in page_test to make a
| |
58 | 58 |
59 if attributes: | 59 if attributes: |
60 for k, v in attributes.iteritems(): | 60 for k, v in attributes.iteritems(): |
61 setattr(self, k, v) | 61 setattr(self, k, v) |
62 | 62 |
63 def __getattr__(self, name): | 63 def __getattr__(self, name): |
64 if self.page_set and hasattr(self.page_set, name): | 64 if self.page_set and hasattr(self.page_set, name): |
65 return getattr(self.page_set, name) | 65 return getattr(self.page_set, name) |
66 | 66 |
67 raise AttributeError() | 67 raise AttributeError() |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 for p in self.page_set if p.is_file] | 104 for p in self.page_set if p.is_file] |
105 common_prefix = os.path.commonprefix(url_paths) | 105 common_prefix = os.path.commonprefix(url_paths) |
106 return self.url[len(common_prefix):].strip('/') | 106 return self.url[len(common_prefix):].strip('/') |
107 | 107 |
108 @property | 108 @property |
109 def archive_path(self): | 109 def archive_path(self): |
110 return self.page_set.WprFilePathForPage(self) | 110 return self.page_set.WprFilePathForPage(self) |
111 | 111 |
112 def __str__(self): | 112 def __str__(self): |
113 return self.url | 113 return self.url |
114 | |
115 def WaitToLoad(self, tab, timeout, poll_interval=0.1): | |
116 Page.WaitForPageToLoad(self, tab, timeout, poll_interval) | |
117 | |
118 # TODO(dtu): Remove this method when no page sets use a click interaction | |
119 # with a wait condition. crbug.com/168431 | |
120 @staticmethod | |
121 def WaitForPageToLoad(obj, tab, timeout, poll_interval=0.1): | |
122 """Waits for various wait conditions present in obj.""" | |
123 if hasattr(obj, 'wait_seconds'): | |
124 time.sleep(obj.wait_seconds) | |
125 if hasattr(obj, 'wait_for_element_with_text'): | |
126 callback_code = 'function(element) { return element != null; }' | |
127 util.WaitFor( | |
128 lambda: util.FindElementAndPerformAction( | |
129 tab, obj.wait_for_element_with_text, callback_code), | |
130 timeout, poll_interval) | |
131 if hasattr(obj, 'wait_for_element_with_selector'): | |
132 util.WaitFor(lambda: tab.EvaluateJavaScript( | |
133 'document.querySelector(\'' + obj.wait_for_element_with_selector + | |
134 '\') != null'), timeout, poll_interval) | |
135 if hasattr(obj, 'post_navigate_javascript_to_execute'): | |
136 tab.EvaluateJavaScript(obj.post_navigate_javascript_to_execute) | |
137 if hasattr(obj, 'wait_for_javascript_expression'): | |
138 util.WaitFor( | |
139 lambda: tab.EvaluateJavaScript(obj.wait_for_javascript_expression), | |
140 timeout, poll_interval) | |
OLD | NEW |