def testSidenavDataSource(self):
    file_system = TestFileSystem({
      'apps_sidenav.json': json.dumps([{
        'title': 'H1',
        'href': 'H1.html',
        'items': [{
          'title': 'H2',
          'href': '/H2.html'
        }]
      }])
    })

    expected = [{
      'level': 2,
      'child_selected': True,
      'title': 'H1',
      'href': '/H1.html',
      'items': [{
        'level': 3,
        'selected': True,
        'title': 'H2',
        'href': '/H2.html'
      }]
    }]

    sidenav_data_source = SidenavDataSource(
        FakeServerInstance(file_system), Request.ForTest('/H2.html'))

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('apps')))

    self.assertEqual(1, len(log_output))
    self.assertTrue(
        log_output[0].msg.startswith('Paths in sidenav must be qualified.'))
Ejemplo n.º 2
0
  def testWithDifferentBasePath(self):
    file_system = TestFileSystem({
      'chrome_sidenav.json': json.dumps([
        { 'href': '/H1.html' },
        { 'href': '/H2.html' },
        { 'href': '/base/path/H2.html' },
        { 'href': 'https://qualified/X1.html' },
        {
          'href': 'H3.html',
          'items': [{
            'href': 'H4.html'
          }]
        },
      ])
    }, relative_to=JSON_TEMPLATES)

    expected = [
      {'href': '/base/path/H1.html', 'level': 2, 'related': True},
      {'href': '/base/path/H2.html', 'level': 2, 'selected': True, 'related': True},
      {'href': '/base/path/base/path/H2.html', 'level': 2, 'related': True},
      {'href': 'https://qualified/X1.html', 'level': 2, 'related': True},
      {'items': [
        {'href': '/base/path/H4.html', 'level': 3}
      ],
      'href': '/base/path/H3.html', 'level': 2, 'related': True}
    ]

    server_instance = ServerInstance.ForTest(file_system,
                                             base_path='/base/path/')
    sidenav_data_source = SidenavDataSource(server_instance,
                                            Request.ForTest('/H2.html'))

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('chrome')))
    self.assertEqual(2, len(log_output))
Ejemplo n.º 3
0
  def testWithDifferentBasePath(self):
    file_system = TestFileSystem({
      'chrome_sidenav.json': json.dumps([
        { 'href': '/H1.html' },
        { 'href': '/H2.html' },
        { 'href': '/base/path/H2.html' },
        { 'href': 'https://qualified/X1.html' },
        {
          'href': 'H3.html',
          'items': [{
            'href': 'H4.html'
          }]
        },
      ])
    }, relative_to=JSON_TEMPLATES)

    expected = [
      {'href': '/base/path/H1.html', 'level': 2, 'related': True},
      {'href': '/base/path/H2.html', 'level': 2, 'selected': True, 'related': True},
      {'href': '/base/path/base/path/H2.html', 'level': 2, 'related': True},
      {'href': 'https://qualified/X1.html', 'level': 2, 'related': True},
      {'items': [
        {'href': '/base/path/H4.html', 'level': 3}
      ],
      'href': '/base/path/H3.html', 'level': 2, 'related': True}
    ]

    server_instance = ServerInstance.ForTest(file_system,
                                             base_path='/base/path/')
    sidenav_data_source = SidenavDataSource(server_instance,
                                            Request.ForTest('/H2.html'))

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('chrome')))
    self.assertEqual(2, len(log_output))
    def testSidenavDataSource(self):
        file_system = MockFileSystem(
            TestFileSystem(
                {
                    'chrome_sidenav.json':
                    json.dumps([{
                        'title': 'H1',
                        'href': 'H1.html',
                        'items': [{
                            'title': 'H2',
                            'href': '/H2.html'
                        }]
                    }])
                },
                relative_to=JSON_TEMPLATES))

        expected = [{
            'level':
            2,
            'child_selected':
            True,
            'title':
            'H1',
            'href':
            '/H1.html',
            'items': [{
                'level': 3,
                'selected': True,
                'related': True,
                'title': 'H2',
                'href': '/H2.html',
                'parent': {
                    'href': '/H1.html',
                    'title': 'H1'
                }
            }]
        }]

        sidenav_data_source = SidenavDataSource(
            ServerInstance.ForTest(file_system), Request.ForTest('/H2.html'))
        self.assertTrue(*file_system.CheckAndReset())

        log_output = CaptureLogging(lambda: self.assertEqual(
            expected, sidenav_data_source.get('chrome')))

        self.assertEqual(1, len(log_output))
        self.assertTrue(log_output[0].msg.startswith(
            'Paths in sidenav must be qualified.'))

        # Test that only a single file is read when creating the sidenav, so that
        # we can be confident in the compiled_file_system.SingleFile annotation.
        self.assertTrue(*file_system.CheckAndReset(
            read_count=1, stat_count=1, read_resolve_count=1))
Ejemplo n.º 5
0
  def testSidenavDataSource(self):
    file_system = MockFileSystem(TestFileSystem({
      'chrome_sidenav.json': json.dumps([{
        'title': 'H1',
        'href': 'H1.html',
        'items': [{
          'title': 'H2',
          'href': '/H2.html'
        }]
      }])
    }, relative_to=JSON_TEMPLATES))

    expected = [{
      'level': 2,
      'child_selected': True,
      'title': 'H1',
      'href': '/H1.html',
      'items': [{
        'level': 3,
        'selected': True,
        'related': True,
        'title': 'H2',
        'href': '/H2.html',
        'parent': { 'href': '/H1.html', 'title': 'H1'}
      }]
    }]

    sidenav_data_source = SidenavDataSource(
        ServerInstance.ForTest(file_system), Request.ForTest('/H2.html'))
    self.assertTrue(*file_system.CheckAndReset())

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('chrome')))

    self.assertEqual(1, len(log_output))
    self.assertTrue(
        log_output[0].msg.startswith('Paths in sidenav must be qualified.'))

    # Test that only a single file is read when creating the sidenav, so that
    # we can be confident in the compiled_file_system.SingleFile annotation.
    self.assertTrue(*file_system.CheckAndReset(
        read_count=1, stat_count=1, read_resolve_count=1))