| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import unittest |
| 7 |
| 8 from link_error_detector import LinkErrorDetector |
| 9 from servlet import Response |
| 10 from test_file_system import TestFileSystem |
| 11 |
| 12 file_system = TestFileSystem({ |
| 13 'docs': { |
| 14 'templates': { |
| 15 'public': { |
| 16 'apps': { |
| 17 '404.html': '404', |
| 18 'index.html': ''' |
| 19 <h1 id="actual-top">Hello</h1> |
| 20 <a href="#top">world</p> |
| 21 <a href="#actual-top">!</a> |
| 22 <a href="broken.json"></a> |
| 23 <a href="crx.html"></a> |
| 24 ''', |
| 25 'crx.html': ''' |
| 26 <a href="index.html#actual-top">back</a> |
| 27 <a href="broken.html"></a> |
| 28 <a href="devtools.events.html">do to underscore translation</a> |
| 29 ''', |
| 30 'devtools_events.html': ''' |
| 31 <a href=" http://www.google.com/">leading space in href</a> |
| 32 <a href=" index.html">home</a> |
| 33 <a href="index.html#invalid"></a> |
| 34 <a href="fake.html#invalid"></a> |
| 35 ''', |
| 36 'unreachable.html': ''' |
| 37 <p>so lonely</p> |
| 38 <a href="#aoesu"></a> |
| 39 <a href="invalid.html"></a> |
| 40 ''', |
| 41 'devtools_disconnected.html': '' |
| 42 } |
| 43 } |
| 44 }, |
| 45 'static': {}, |
| 46 'examples': {}, |
| 47 } |
| 48 }) |
| 49 |
| 50 class LinkErrorDetectorTest(unittest.TestCase): |
| 51 def render(self, path): |
| 52 try: |
| 53 return Response( |
| 54 content=file_system.ReadSingle('docs/templates/public/' + path), |
| 55 status=200) |
| 56 except AttributeError: |
| 57 return Response(status=404) |
| 58 |
| 59 def testGetBrokenLinks(self): |
| 60 expected_broken_links = set([ |
| 61 ('apps/crx.html', 'apps/broken.html'), |
| 62 ('apps/index.html', 'apps/broken.json'), |
| 63 ('apps/unreachable.html', 'apps/invalid.html'), |
| 64 ('apps/devtools_events.html', 'apps/fake.html#invalid')]) |
| 65 |
| 66 expected_broken_anchors = set([ |
| 67 ('apps/devtools_events.html', 'apps/index.html#invalid'), |
| 68 ('apps/unreachable.html', '#aoesu')]) |
| 69 |
| 70 link_error_detector = LinkErrorDetector( |
| 71 file_system, self.render, 'templates/public', ('apps/index.html')) |
| 72 broken_links, broken_anchors = link_error_detector.GetBrokenLinks() |
| 73 |
| 74 self.assertEqual(expected_broken_links, set(broken_links)) |
| 75 self.assertEqual(expected_broken_anchors, set(broken_anchors)) |
| 76 |
| 77 def testGetOrphanedPages(self): |
| 78 expected_orphaned_pages = set([ |
| 79 'apps/unreachable.html', |
| 80 'apps/devtools_disconnected.html']) |
| 81 |
| 82 link_error_detector = LinkErrorDetector( |
| 83 file_system, self.render, 'templates/public', ('apps/crx.html',)) |
| 84 orphaned_pages = link_error_detector.GetOrphanedPages() |
| 85 |
| 86 self.assertEqual(expected_orphaned_pages, set(orphaned_pages)) |
| 87 |
| 88 if __name__ == '__main__': |
| 89 unittest.main() |
| OLD | NEW |