Exemplo n.º 1
0
 def setUp(self):
   server_instance = ServerInstance.ForTest(
       TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS))
   # APIListDataSource takes a request but doesn't use it,
   # so put None
   self._api_list = APIListDataSource(server_instance, None)
   self.maxDiff = None
Exemplo n.º 2
0
 def setUp(self):
     server_instance = ServerInstance.ForTest(
         file_system=TestFileSystem({}))
     self._samples_model = server_instance.platform_bundle.GetSamplesModel(
         'apps')
     self._samples_model._samples_cache = _FakeCache(
         json.loads(_ReadLocalFile('samples.json')))
Exemplo n.º 3
0
 def setUp(self):
     server_instance = ServerInstance.ForTest(TestFileSystem(_TEST_DATA))
     self._factory = APIListDataSource.Factory(
         server_instance.compiled_fs_factory,
         server_instance.host_file_system_provider.GetTrunk(),
         server_instance.features_bundle,
         server_instance.object_store_creator)
Exemplo n.º 4
0
 def setUp(self):
     server_instance = ServerInstance.ForTest(
         file_system=TestFileSystem(_TEST_FS))
     # Don't randomize the owners to avoid testing issues.
     self._owners_ds = OwnersDataSource(server_instance,
                                        Request.ForTest('/'),
                                        randomize=False)
Exemplo n.º 5
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))
Exemplo n.º 6
0
    def setUp(self):
        self._base_path = Server2Path('test_data', 'test_json')

        server_instance = ServerInstance.ForTest(
            TestFileSystem(CANNED_TRUNK_FS_DATA, relative_to=EXTENSIONS))
        self._json_cache = server_instance.compiled_fs_factory.ForJson(
            server_instance.host_file_system_provider.GetTrunk())
        self._api_models = server_instance.api_models

        # Used for testGetApiAvailability() so that valid-ish data is processed.
        server_instance = ServerInstance.ForTest(
            file_system_provider=_FakeHostFileSystemProvider(
                CANNED_API_FILE_SYSTEM_DATA))
        self._avail_api_models = server_instance.api_models
        self._avail_json_cache = server_instance.compiled_fs_factory.ForJson(
            server_instance.host_file_system_provider.GetTrunk())
        self._avail_finder = server_instance.availability_finder
Exemplo n.º 7
0
 def setUp(self):
     server_instance = ServerInstance.ForTest(
         file_system_provider=FakeHostFileSystemProvider(
             CANNED_API_FILE_SYSTEM_DATA))
     self._api_models = server_instance.platform_bundle.GetAPIModels(
         'extensions')
     self._json_cache = server_instance.compiled_fs_factory.ForJson(
         server_instance.host_file_system_provider.GetMaster())
     self._avail_finder = server_instance.platform_bundle.GetAvailabilityFinder(
         'extensions')
 def setUp(self):
     server_instance = ServerInstance.ForTest(
         TestFileSystem(_TEST_DATA, relative_to=EXTENSIONS))
     self._factory = APIListDataSource.Factory(
         server_instance.compiled_fs_factory,
         server_instance.host_file_system_provider.GetTrunk(),
         server_instance.features_bundle,
         server_instance.object_store_creator, server_instance.api_models,
         server_instance.availability_finder,
         server_instance.api_categorizer)
     self.maxDiff = None
    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))
  def setUp(self):
    self._base_path = Server2Path('test_data', 'test_json')

    server_instance = ServerInstance.ForTest(
        TestFileSystem(CANNED_MASTER_FS_DATA, relative_to=CHROME_EXTENSIONS))
    file_system = server_instance.host_file_system_provider.GetMaster()
    self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system)
    self._features_bundle = FeaturesBundle(file_system,
                                           server_instance.compiled_fs_factory,
                                           server_instance.object_store_creator,
                                           'extensions')
    self._api_models = server_instance.platform_bundle.GetAPIModels(
        'extensions')
    self._fake_availability = AvailabilityInfo(ChannelInfo('stable', '396', 5))
    def testRefresh(self):
        file_system = TestFileSystem(
            {'chrome_sidenav.json': '[{ "title": "H1" }]'},
            relative_to=JSON_TEMPLATES)

        # Ensure Refresh doesn't rely on request.
        sidenav_data_source = SidenavDataSource(
            ServerInstance.ForTest(file_system), request=None)
        sidenav_data_source.Refresh().Get()

        # If Refresh fails, chrome_sidenav.json will not be cached, and the
        # cache_data access will fail.
        # TODO(jshumway): Make a non hack version of this check.
        sidenav_data_source._cache._file_object_store.Get(
            '%schrome_sidenav.json' % JSON_TEMPLATES).Get().cache_data
  def testCron(self):
    file_system = TestFileSystem({
      'apps_sidenav.json': '[{ "title": "H1" }]' ,
      'extensions_sidenav.json': '[{ "title": "H2" }]'
    }, relative_to=JSON_TEMPLATES)

    # Ensure Cron doesn't rely on request.
    sidenav_data_source = SidenavDataSource(
        ServerInstance.ForTest(file_system), request=None)
    sidenav_data_source.Cron().Get()

    # If Cron fails, apps_sidenav.json will not be cached, and the _cache_data
    # access will fail.
    # TODO(jshumway): Make a non hack version of this check.
    sidenav_data_source._cache._file_object_store.Get(
        '%s/apps_sidenav.json' % JSON_TEMPLATES).Get()._cache_data
  def setUp(self):
    tabs_unmodified_versions = (16, 20, 23, 24)
    self._branch_utility = BranchUtility(
        os.path.join('branch_utility', 'first.json'),
        os.path.join('branch_utility', 'second.json'),
        FakeUrlFetcher(Server2Path('test_data')),
        ObjectStoreCreator.ForTest())
    self._node_fs_creator = FakeHostFileSystemProvider(TABS_SCHEMA_BRANCHES)
    self._node_fs_iterator = HostFileSystemIterator(self._node_fs_creator,
                                                    self._branch_utility)
    test_object_store = ObjectStoreCreator.ForTest()
    self._avail_finder = AvailabilityFinder(
        self._branch_utility,
        CompiledFileSystem.Factory(test_object_store),
        self._node_fs_iterator,
        self._node_fs_creator.GetMaster(),
        test_object_store,
        'extensions',
        SchemaProcessorFactoryForTest())

    server_instance = ServerInstance.ForTest(
        file_system_provider=FakeHostFileSystemProvider(
            TABS_SCHEMA_BRANCHES))
    self._api_models = server_instance.platform_bundle.GetAPIModels(
        'extensions')
    self._json_cache = server_instance.compiled_fs_factory.ForJson(
        server_instance.host_file_system_provider.GetMaster())

    # Imitate the actual SVN file system by incrementing the stats for paths
    # where an API schema has changed.
    last_stat = type('last_stat', (object,), {'val': 0})

    def stat_paths(file_system, channel_info):
      if channel_info.version not in tabs_unmodified_versions:
        last_stat.val += 1
      # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem.
      # Increment the TestFileSystem stat count.
      file_system._file_system.IncrementStat(by=last_stat.val)
      # Continue looping. The iterator will stop after 'master' automatically.
      return True

    # Use the HostFileSystemIterator created above to change global stat values
    # for the TestFileSystems that it creates.
    self._node_fs_iterator.Ascending(
        # The earliest version represented with the tabs' test data is 13.
        self._branch_utility.GetStableChannelInfo(13),
        stat_paths)
Exemplo n.º 14
0
 def CreateServerInstanceForChannel(self, channel):
     return ServerInstance.ForTest(LocalFileSystem.Create())
Exemplo n.º 15
0
    def testCreatePermissionsDataSource(self):
        expected_extensions = [
            {
                'anchor': 'custom-anchor',
                'description': 'host permissions',
                'literal_name': True,
                'name': 'match pattern',
                'platforms': ['apps', 'extensions']
            },
            {
                'anchor': 'activeTab',
                'description': 'active tab',
                'name': 'activeTab',
                'platforms': ['extensions'],
            },
            {
                'anchor': 'alarms',
                'description': 'generic description',
                'name': 'alarms',
                'platforms': ['apps', 'extensions'],
            },
        ]

        expected_apps = [
            {
                'anchor': 'custom-anchor',
                'description': 'host permissions',
                'literal_name': True,
                'name': 'match pattern',
                'platforms': ['apps', 'extensions'],
            },
            {
                'anchor': 'alarms',
                'description': 'generic description',
                'name': 'alarms',
                'platforms': ['apps', 'extensions'],
            },
            {
                'anchor': 'cookies',
                'description': 'generic description',
                'name': 'cookies',
                'platforms': ['apps'],
            },
        ]

        test_file_system = TestFileSystem({
            'api': {
                '_api_features.json': json.dumps(_API_FEATURES),
                '_manifest_features.json': '{}',
                '_permission_features.json': json.dumps(_PERMISSION_FEATURES),
            },
            'docs': {
                'templates': {
                    'json': {
                        'manifest.json': '{}',
                        'permissions.json': json.dumps(_PERMISSIONS_JSON),
                    },
                    'private': {
                        'permissions': _PERMISSIONS_PARTIALS
                    },
                }
            }
        })

        permissions_data_source = PermissionsDataSource(
            ServerInstance.ForTest(test_file_system), None)

        actual_extensions = permissions_data_source.get('declare_extensions')
        actual_apps = permissions_data_source.get('declare_apps')

        # Normalise all test data.
        #   - Sort keys. Since the tests don't use OrderedDicts we can't make
        #     assertions about the order, which is unfortunate. Oh well.
        #   - Render all of the Handlerbar instances so that we can use ==.
        #     Handlebars don't implement __eq__, but they probably should.
        for lst in (actual_apps, actual_extensions, expected_apps,
                    expected_extensions):
            lst.sort(key=itemgetter('name'))
            for mapping in lst:
                for key, value in mapping.iteritems():
                    if isinstance(value, Handlebar):
                        mapping[key] = value.Render().text

        self.assertEqual(expected_extensions, actual_extensions)
        self.assertEqual(expected_apps, actual_apps)
Exemplo n.º 16
0
 def setUp(self):
     self._server = ServerInstance.ForTest(TestFileSystem(_TEST_DATA))
Exemplo n.º 17
0
 def setUp(self):
     self._server = ServerInstance.ForTest(TestFileSystem(_TEST_FILESYSTEM))
Exemplo n.º 18
0
 def setUp(self):
   self._renderer = ServerInstance.ForTest(
       TestFileSystem(CANNED_TEST_FILE_SYSTEM_DATA)).document_renderer
   self._path = 'apps/some/path/to/document.html'
Exemplo n.º 19
0
 def setUp(self):
     self.server_instance = ServerInstance.ForTest(
         TestFileSystem(CANNED_TRUNK_FS_DATA,
                        relative_to=CHROME_EXTENSIONS))
 def setUp(self):
     mock_file_system = MockFileSystem(
         TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS))
     server_instance = ServerInstance.ForTest(file_system=mock_file_system)
     self._platform_bundle = server_instance.platform_bundle
 def setUp(self):
     self._server = ServerInstance.ForTest(
         TestFileSystem(_TEST_FILESYSTEM, relative_to=EXTENSIONS))
Exemplo n.º 22
0
 def setUp(self):
   self._server = ServerInstance.ForTest(
       TestFileSystem(CANNED_TEST_FILE_SYSTEM_DATA))
Exemplo n.º 23
0
 def setUp(self):
     self._renderer = ServerInstance.ForTest(
         TestFileSystem(CANNED_TEST_FILE_SYSTEM_DATA)).document_renderer
Exemplo n.º 24
0
 def CreateServerInstance(self):
     return ServerInstance.ForTest(LocalFileSystem.Create())
Exemplo n.º 25
0
    def testCreateWhatsNewDataSource(self):
        api_fs_creator = FakeHostFileSystemProvider(
            CANNED_API_FILE_SYSTEM_DATA)
        server_instance = ServerInstance.ForTest(
            file_system_provider=api_fs_creator)

        whats_new_data_source = WhatsNewDataSource(server_instance, None)
        expected_whats_new_changes_list = [{
            'version':
            22,
            'additionsToExistingApis': [{
                'version':
                22,
                'type':
                'additionsToExistingApis',
                'id':
                'backgroundpages.to-be-non-persistent',
                'description':
                'backgrounds to be non persistent'
            }],
        }, {
            'version':
            21,
            'additionsToExistingApis': [{
                'version':
                21,
                'type':
                'additionsToExistingApis',
                'id':
                'chromeSetting.set-regular-only-scope',
                'description':
                'ChromeSetting.set now has a regular_only scope.'
            }],
        }, {
            'version':
            20,
            'manifestChanges': [{
                'version':
                20,
                'type':
                'manifestChanges',
                'id':
                'manifest-v1-deprecated',
                'description':
                'Manifest version 1 was deprecated in Chrome 18'
            }],
        }]

        expected_new_info_of_apps = [{
            'version':
            26,
            'apis': [{
                'version': 26,
                'type': 'apis',
                'name': u'alarm',
                'description': u'<code>alarm</code>'
            }, {
                'version': 26,
                'type': 'apis',
                'name': u'app.window',
                'description': u'<code>app.window</code>'
            }]
        }]
        expected_new_info_of_apps.extend(expected_whats_new_changes_list)

        expected_new_info_of_extensions = [{
            'version':
            26,
            'apis': [{
                'version': 26,
                'type': 'apis',
                'name': u'alarm',
                'description': u'<code>alarm</code>'
            }, {
                'version': 26,
                'type': 'apis',
                'name': u'browserAction',
                'description': u'<code>browserAction</code>'
            }]
        }]
        expected_new_info_of_extensions.extend(expected_whats_new_changes_list)

        whats_new_for_apps = whats_new_data_source.get('apps')
        whats_new_for_extension = whats_new_data_source.get('extensions')
        self.assertEqual(expected_new_info_of_apps, whats_new_for_apps)
        self.assertEqual(expected_new_info_of_extensions,
                         whats_new_for_extension)