diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-01 00:48:25 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-01 00:48:25 +0000 |
commit | b3dcb3583020fb94d714f31dd422d2fdb3db5c35 (patch) | |
tree | f1960f096c7b6b03c8c2505081a6280edfd67071 | |
parent | 6a34dbff976daf41838e97a46b92509b333d0485 (diff) | |
download | chromium_src-b3dcb3583020fb94d714f31dd422d2fdb3db5c35.zip chromium_src-b3dcb3583020fb94d714f31dd422d2fdb3db5c35.tar.gz chromium_src-b3dcb3583020fb94d714f31dd422d2fdb3db5c35.tar.bz2 |
Docserver: Add a PatchServlet test which checks that hrefs are properly
qualified with _patch/<cl number>. Previously they were just testing
inequality. Fix a bug it found.
R=jyasskin@chromium.org
NOTRY=true
Review URL: https://codereview.chromium.org/55263003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232253 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 34 insertions, 4 deletions
diff --git a/chrome/common/extensions/docs/server2/patch_servlet_test.py b/chrome/common/extensions/docs/server2/patch_servlet_test.py index 182f87d..fbbaaee 100755 --- a/chrome/common/extensions/docs/server2/patch_servlet_test.py +++ b/chrome/common/extensions/docs/server2/patch_servlet_test.py @@ -3,6 +3,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +from HTMLParser import HTMLParser import unittest from empty_dir_file_system import EmptyDirFileSystem @@ -16,8 +17,28 @@ from servlet import Request from test_branch_utility import TestBranchUtility from test_util import DisableLogging + + _ALLOWED_HOST = 'https://chrome-apps-doc.appspot.com' + +def _CheckURLsArePatched(content, patch_servlet_path): + errors = [] + class LinkChecker(HTMLParser): + def handle_starttag(self, tag, attrs): + if tag != 'a': + return + tag_description = '<a %s .../>' % ' '.join('%s="%s"' % (key, val) + for key, val in attrs) + attrs = dict(attrs) + if ('href' in attrs and + attrs['href'].startswith('/') and + not attrs['href'].startswith('/%s/' % patch_servlet_path)): + errors.append('%s has an unqualified href' % tag_description) + LinkChecker().feed(content) + return errors + + class _RenderServletDelegate(RenderServlet.Delegate): def CreateServerInstance(self): return ServerInstance.ForLocal() @@ -32,6 +53,7 @@ class _PatchServletDelegate(RenderServlet.Delegate): def CreateGithubFileSystemProvider(self, object_store_creator): return GithubFileSystemProvider.ForEmpty() + class PatchServletTest(unittest.TestCase): def setUp(self): ConfigureFakeFetchers() @@ -54,10 +76,17 @@ class PatchServletTest(unittest.TestCase): unpatched_response = self._RenderWithoutPatch(path) patched_response.headers.pop('cache-control', None) unpatched_response.headers.pop('cache-control', None) - patched_content = patched_response.content.ToString().replace( - '/_patch/%s' % issue, '') unpatched_content = unpatched_response.content.ToString() + # Check that all links in the patched content are qualified with + # the patch URL, then strip them out for checking (in)equality. + patched_content = patched_response.content.ToString() + patch_servlet_path = '_patch/%s' % issue + errors = _CheckURLsArePatched(patched_content, patch_servlet_path) + self.assertFalse(errors, + '%s\nFound errors:\n * %s' % (patched_content, '\n * '.join(errors))) + patched_content = patched_content.replace('/%s' % patch_servlet_path, '') + self.assertEqual(patched_response.status, unpatched_response.status) self.assertEqual(patched_response.headers, unpatched_response.headers) if expected_equal: diff --git a/chrome/common/extensions/docs/server2/template_renderer.py b/chrome/common/extensions/docs/server2/template_renderer.py index c88b927..10ec0aa 100644 --- a/chrome/common/extensions/docs/server2/template_renderer.py +++ b/chrome/common/extensions/docs/server2/template_renderer.py @@ -23,6 +23,7 @@ class TemplateRenderer(object): 'api_list': server_instance.api_list_data_source_factory.Create(), 'apis': server_instance.api_data_source_factory.Create(request), 'apps_samples_url': GITHUB_BASE, + 'base_path': server_instance.base_path, 'extensions_samples_url': EXTENSIONS_SAMPLES, 'false': False, 'intros': server_instance.intro_data_source_factory.Create(), diff --git a/chrome/common/extensions/docs/templates/private/header_body.html b/chrome/common/extensions/docs/templates/private/header_body.html index c8f59ac..5c5502b 100644 --- a/chrome/common/extensions/docs/templates/private/header_body.html +++ b/chrome/common/extensions/docs/templates/private/header_body.html @@ -1,7 +1,7 @@ <div id="gc-topnav"> <table><tr> <td id="chrome-logo"> - <a href="/{{platform}}s/" title="Google Chrome {{title}}"> + <a href="{{base_path}}{{platform}}s/" title="Google Chrome {{title}}"> <img src="{{static}}/images/chrome-logo.png" alt=""> chrome </a> <div id="platform-chooser"> @@ -17,7 +17,7 @@ <td> <ul> <li> - <a href="/{{platform}}s/samples.html" + <a href="{{base_path}}{{platform}}s/samples.html" title="Sample {{title}} (with source code)">Samples</a> </li> <li> |