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 tempfile | 5 import tempfile |
6 import unittest | 6 import unittest |
7 | 7 |
8 from telemetry import browser_finder | 8 from telemetry.core import browser_finder |
9 from telemetry import page as page_module | 9 from telemetry.core import user_agent |
10 from telemetry import page_set | 10 from telemetry.page import page as page_module |
11 from telemetry import page_test | 11 from telemetry.page import page_set |
12 from telemetry import page_runner | 12 from telemetry.page import page_test |
13 from telemetry import options_for_unittests | 13 from telemetry.page import page_runner |
14 from telemetry import user_agent | 14 from telemetry.test import options_for_unittests |
15 | 15 |
16 SIMPLE_CREDENTIALS_STRING = """ | 16 SIMPLE_CREDENTIALS_STRING = """ |
17 { | 17 { |
18 "test": { | 18 "test": { |
19 "username": "example", | 19 "username": "example", |
20 "password": "asdf" | 20 "password": "asdf" |
21 } | 21 } |
22 } | 22 } |
23 """ | 23 """ |
24 class StubCredentialsBackend(object): | 24 class StubCredentialsBackend(object): |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 with page_runner.PageRunner(ps) as runner: | 107 with page_runner.PageRunner(ps) as runner: |
108 options = options_for_unittests.GetCopy() | 108 options = options_for_unittests.GetCopy() |
109 possible_browser = browser_finder.FindBrowser(options) | 109 possible_browser = browser_finder.FindBrowser(options) |
110 runner.Run(options, possible_browser, test, results) | 110 runner.Run(options, possible_browser, test, results) |
111 | 111 |
112 return did_run[0] | 112 return did_run[0] |
113 | 113 |
114 def testUserAgent(self): | 114 def testUserAgent(self): |
115 ps = page_set.PageSet() | 115 ps = page_set.PageSet() |
116 page = page_module.Page( | 116 page = page_module.Page( |
117 'file:///' + os.path.join('..', 'unittest_data', 'blank.html'), | 117 'file:///' + os.path.join('..', '..', 'unittest_data', 'blank.html'), |
118 ps, | 118 ps, |
119 base_dir=os.path.dirname(__file__)) | 119 base_dir=os.path.dirname(__file__)) |
120 ps.pages.append(page) | 120 ps.pages.append(page) |
121 ps.user_agent_type = 'tablet' | 121 ps.user_agent_type = 'tablet' |
122 | 122 |
123 class TestUserAgent(page_test.PageTest): | 123 class TestUserAgent(page_test.PageTest): |
124 def RunTest(self, page, tab, results): # pylint: disable=W0613,R0201 | 124 def RunTest(self, page, tab, results): # pylint: disable=W0613,R0201 |
125 actual_user_agent = tab.EvaluateJavaScript('window.navigator.userAgent') | 125 actual_user_agent = tab.EvaluateJavaScript('window.navigator.userAgent') |
126 expected_user_agent = user_agent.UA_TYPE_MAPPING['tablet'] | 126 expected_user_agent = user_agent.UA_TYPE_MAPPING['tablet'] |
127 assert actual_user_agent.strip() == expected_user_agent | 127 assert actual_user_agent.strip() == expected_user_agent |
128 | 128 |
129 # This is so we can check later that the test actually made it into this | 129 # This is so we can check later that the test actually made it into this |
130 # function. Previously it was timing out before even getting here, which | 130 # function. Previously it was timing out before even getting here, which |
131 # should fail, but since it skipped all the asserts, it slipped by. | 131 # should fail, but since it skipped all the asserts, it slipped by. |
132 self.hasRun = True # pylint: disable=W0201 | 132 self.hasRun = True # pylint: disable=W0201 |
133 | 133 |
134 test = TestUserAgent('RunTest') | 134 test = TestUserAgent('RunTest') |
135 with page_runner.PageRunner(ps) as runner: | 135 with page_runner.PageRunner(ps) as runner: |
136 options = options_for_unittests.GetCopy() | 136 options = options_for_unittests.GetCopy() |
137 possible_browser = browser_finder.FindBrowser(options) | 137 possible_browser = browser_finder.FindBrowser(options) |
138 results = page_test.PageTestResults() | 138 results = page_test.PageTestResults() |
139 runner.Run(options, possible_browser, test, results) | 139 runner.Run(options, possible_browser, test, results) |
140 | 140 |
141 self.assertTrue(hasattr(test, 'hasRun') and test.hasRun) | 141 self.assertTrue(hasattr(test, 'hasRun') and test.hasRun) |
OLD | NEW |