OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 from HTMLParser import HTMLParser | 6 from HTMLParser import HTMLParser |
7 import unittest | 7 import unittest |
8 | 8 |
9 from fake_fetchers import ConfigureFakeFetchers | 9 from fake_fetchers import ConfigureFakeFetchers |
10 from github_file_system_provider import GithubFileSystemProvider | 10 from github_file_system_provider import GithubFileSystemProvider |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 def testRender(self): | 123 def testRender(self): |
124 # '_patch' is not included in paths below because it's stripped by Handler. | 124 # '_patch' is not included in paths below because it's stripped by Handler. |
125 issue = '14096030' | 125 issue = '14096030' |
126 | 126 |
127 # TODO(kalman): Test with chrome_sidenav.json once the sidenav logic has | 127 # TODO(kalman): Test with chrome_sidenav.json once the sidenav logic has |
128 # stabilised. | 128 # stabilised. |
129 | 129 |
130 # extensions/runtime.html is removed in the patch, should redirect to the | 130 # extensions/runtime.html is removed in the patch, should redirect to the |
131 # apps version. | 131 # apps version. |
132 self._AssertRedirect('extensions/runtime.html', issue, | 132 self._AssertRedirect('extensions/runtime', issue, 'apps/runtime') |
133 'apps/runtime.html') | |
134 | 133 |
135 # apps/runtime.html is not removed. | 134 # apps/runtime.html is not removed. |
136 self._RenderAndAssertEqual('apps/runtime.html', issue) | 135 self._RenderAndAssertEqual('apps/runtime', issue) |
137 | 136 |
138 # test_foo.html is added in the patch. | 137 # test_foo.html is added in the patch. |
139 self._AssertOk('extensions/test_foo.html', issue) | 138 self._AssertOk('extensions/test_foo', issue) |
140 | 139 |
141 # Invalid issue number results in a 404. | 140 # Invalid issue number results in a 404. |
142 self._AssertNotFound('extensions/index.html', '11111') | 141 self._AssertNotFound('extensions/index', '11111') |
143 | 142 |
144 def testXssRedirect(self): | 143 def testXssRedirect(self): |
145 def is_redirect(from_host, from_path, to_url): | 144 def is_redirect(from_host, from_path, to_url): |
146 response = PatchServlet(Request.ForTest(from_path, host=from_host), | 145 response = PatchServlet(Request.ForTest(from_path, host=from_host), |
147 _PatchServletDelegate()).Get() | 146 _PatchServletDelegate()).Get() |
148 redirect_url, _ = response.GetRedirect() | 147 redirect_url, _ = response.GetRedirect() |
149 if redirect_url is None: | 148 if redirect_url is None: |
150 return (False, '%s/%s did not cause a redirect' % ( | 149 return (False, '%s/%s did not cause a redirect' % ( |
151 from_host, from_path)) | 150 from_host, from_path)) |
152 if redirect_url != to_url: | 151 if redirect_url != to_url: |
153 return (False, '%s/%s redirected to %s not %s' % ( | 152 return (False, '%s/%s redirected to %s not %s' % ( |
154 from_host, from_path, redirect_url, to_url)) | 153 from_host, from_path, redirect_url, to_url)) |
155 return (True, '%s/%s redirected to %s' % ( | 154 return (True, '%s/%s redirected to %s' % ( |
156 from_host, from_path, redirect_url)) | 155 from_host, from_path, redirect_url)) |
157 self.assertTrue(*is_redirect('http://developer.chrome.com', '12345', | 156 self.assertTrue(*is_redirect('http://developer.chrome.com', '12345', |
158 '%s/_patch/12345' % _ALLOWED_HOST)) | 157 '%s/_patch/12345' % _ALLOWED_HOST)) |
159 self.assertTrue(*is_redirect('http://developers.google.com', '12345', | 158 self.assertTrue(*is_redirect('http://developers.google.com', '12345', |
160 '%s/_patch/12345' % _ALLOWED_HOST)) | 159 '%s/_patch/12345' % _ALLOWED_HOST)) |
161 self.assertFalse(*is_redirect('http://chrome-apps-doc.appspot.com', '12345', | 160 self.assertFalse(*is_redirect('http://chrome-apps-doc.appspot.com', '12345', |
162 None)) | 161 None)) |
163 self.assertFalse(*is_redirect('http://some-other-app.appspot.com', '12345', | 162 self.assertFalse(*is_redirect('http://some-other-app.appspot.com', '12345', |
164 None)) | 163 None)) |
165 | 164 |
166 if __name__ == '__main__': | 165 if __name__ == '__main__': |
167 unittest.main() | 166 unittest.main() |
OLD | NEW |