def testGetIntroList(self):
        fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability)
        model = _JSCModel(
            self._api_models.GetModel("tester").Get(),
            fake_avail_finder,
            self._json_cache,
            _FakeTemplateCache(),
            self._features_bundle,
            None,
        )
        expected_list = [
            {"title": "Description", "content": [{"text": "a test api"}]},
            {
                "title": "Availability",
                "content": [
                    {
                        "partial": "handlebar chrome/common/extensions/docs/"
                        + "templates/private/intro_tables/stable_message.html",
                        "version": 5,
                        "scheduled": None,
                    }
                ],
            },
            {
                "title": "Permissions",
                "content": [{"class": "override", "text": '"tester"'}, {"text": "is an API for testing things."}],
            },
            {"title": "Manifest", "content": [{"class": "code", "text": '"tester": {...}'}]},
            {"title": "Learn More", "content": [{"link": "https://tester.test.com/welcome.html", "text": "Welcome!"}]},
        ]
        self.assertEquals(model._GetIntroTableList(), expected_list)

        # Tests the same data with a scheduled availability.
        fake_avail_finder = _FakeAvailabilityFinder(AvailabilityInfo(ChannelInfo("beta", "1453", 27), scheduled=28))
        model = _JSCModel(
            self._api_models.GetModel("tester").Get(),
            fake_avail_finder,
            self._json_cache,
            _FakeTemplateCache(),
            self._features_bundle,
            None,
        )
        expected_list[1] = {
            "title": "Availability",
            "content": [
                {
                    "partial": "handlebar chrome/common/extensions/docs/"
                    + "templates/private/intro_tables/beta_message.html",
                    "version": 27,
                    "scheduled": 28,
                }
            ],
        }
        self.assertEquals(model._GetIntroTableList(), expected_list)
  def testAddRules(self):
    data_source = FakeAPIAndListDataSource(
        self._LoadJSON('test_file_data_source.json'))
    dict_ = _JSCModel(self._LoadJSON('add_rules_test.json')[0],
                      self._CreateRefResolver('test_file_data_source.json'),
                      False,
                      FakeAvailabilityFinder(),
                      TestBranchUtility.CreateWithCannedData(),
                      self._json_cache,
                      FakeTemplateDataSource(),
                      self._FakeLoadAddRulesSchema).ToDict()
    # Check that the first event has the addRulesFunction defined.
    self.assertEquals('tester', dict_['name'])
    self.assertEquals('rules', dict_['events'][0]['name'])
    self.assertEquals('notable_name_to_check_for',
                      dict_['events'][0]['addRulesFunction'][
                          'parameters'][0]['name'])

    # Check that the second event has no addRulesFunction defined.
    self.assertEquals('noRules', dict_['events'][1]['name'])
    self.assertFalse('addRulesFunction' in dict_['events'][1])
    # But addListener should be defined.
    self.assertEquals('tester', dict_['name'])
    self.assertEquals('noRules', dict_['events'][1]['name'])
    self.assertEquals('callback',
                      dict_['events'][0]['addListenerFunction'][
                          'parameters'][0]['name'])
  def testAddRules(self):
    dict_ = _JSCModel('add_rules_tester',
                      self._api_models,
                      self._CreateRefResolver('test_file_data_source.json'),
                      False,
                      _FakeAvailabilityFinder(),
                      self._json_cache,
                      _FakeTemplateCache(),
                      self._features_bundle,
                      self._FakeLoadAddRulesSchema).ToDict()

    # Check that the first event has the addRulesFunction defined.
    self.assertEquals('add_rules_tester', dict_['name'])
    self.assertEquals('rules', dict_['events'][0]['name'])
    self.assertEquals('notable_name_to_check_for',
                      dict_['events'][0]['byName']['addRules'][
                          'parameters'][0]['name'])

    # Check that the second event has addListener defined.
    self.assertEquals('noRules', dict_['events'][1]['name'])
    self.assertEquals('add_rules_tester', dict_['name'])
    self.assertEquals('noRules', dict_['events'][1]['name'])
    self.assertEquals('callback',
                      dict_['events'][0]['byName']['addListener'][
                          'parameters'][0]['name'])
Example #4
0
    def testGetApiAvailability(self):
        model = _JSCModel(
            self._LoadJSON('test_file.json')[0],
            self._CreateRefResolver('test_file_data_source.json'), False,
            _FakeAvailabilityFinder(),
            TestBranchUtility.CreateWithCannedData(), self._json_cache,
            _FakeTemplateCache(), None)
        # The model namespace is "tester". No predetermined availability is found,
        # so the _FakeAvailabilityFinder instance is used to find availability.
        self.assertEqual(ChannelInfo('stable', '396', 5),
                         model._GetApiAvailability())

        # These APIs have predetermined availabilities in the
        # api_availabilities.json file within CANNED_DATA.
        model._namespace.name = 'trunk_api'
        self.assertEqual(ChannelInfo('trunk', 'trunk', 'trunk'),
                         model._GetApiAvailability())

        model._namespace.name = 'dev_api'
        self.assertEqual(ChannelInfo('dev', '1500', 28),
                         model._GetApiAvailability())

        model._namespace.name = 'beta_api'
        self.assertEqual(ChannelInfo('beta', '1453', 27),
                         model._GetApiAvailability())

        model._namespace.name = 'stable_api'
        self.assertEqual(ChannelInfo('stable', '1132', 20),
                         model._GetApiAvailability())
  def testGetApiAvailability(self):
    model = _JSCModel(self._LoadJSON('test_file.json')[0],
                      self._CreateRefResolver('test_file_data_source.json'),
                      False,
                      _FakeAvailabilityFinder(),
                      TestBranchUtility.CreateWithCannedData(),
                      self._json_cache,
                      _FakeTemplateCache(),
                      None)
    # The model namespace is "tester". No predetermined availability is found,
    # so the _FakeAvailabilityFinder instance is used to find availability.
    self.assertEqual(ChannelInfo('stable', '396', 5),
                     model._GetApiAvailability())

    # These APIs have predetermined availabilities in the
    # api_availabilities.json file within CANNED_DATA.
    model._namespace.name = 'trunk_api'
    self.assertEqual(ChannelInfo('trunk', 'trunk', 'trunk'),
                     model._GetApiAvailability())

    model._namespace.name = 'dev_api'
    self.assertEqual(ChannelInfo('dev', '1500', 28),
                     model._GetApiAvailability())

    model._namespace.name = 'beta_api'
    self.assertEqual(ChannelInfo('beta', '1453', 27),
                     model._GetApiAvailability())

    model._namespace.name = 'stable_api'
    self.assertEqual(ChannelInfo('stable', '1132', 20),
                     model._GetApiAvailability())
Example #6
0
 def DISABLED_testToDict(self):
     expected_json = self._LoadJSON('expected_tester.json')
     dict_ = _JSCModel(
         self._api_models.GetModel('tester').Get(),
         _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
         self._features_bundle, None).ToDict()
     self.assertEquals(expected_json, dict_)
Example #7
0
 def DISABLED_testToDict(self):
     expected_json = self._LoadJSON('expected_tester.json')
     dict_ = _JSCModel(
         'tester', self._api_models, False,
         self._CreateRefResolver('test_file_data_source.json'),
         _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
         None).ToDict()
     self.assertEquals(expected_json, dict_)
Example #8
0
 def testToDict(self):
     filename = "test_file.json"
     expected_json = self._LoadJSON("expected_" + filename)
     data_source = FakeAPIAndListDataSource(self._LoadJSON("test_file_data_source.json"))
     dict_ = _JSCModel(
         self._LoadJSON(filename)[0], self._CreateRefResolver("test_file_data_source.json"), False
     ).ToDict()
     self.assertEquals(expected_json, dict_)
 def DISABLED_testToDict(self):
   expected_json = self._LoadJSON('expected_tester.json')
   dict_ = _JSCModel(self._api_models.GetModel('tester').Get(),
                     self._fake_availability,
                     self._json_cache,
                     _FakeTemplateCache(),
                     self._features_bundle,
                     None).ToDict()
   self.assertEquals(expected_json, dict_)
Example #10
0
 def DISABLED_testToDict(self):
   filename = 'test_file.json'
   expected_json = self._LoadJSON('expected_' + filename)
   data_source = FakeAPIAndListDataSource(
       self._LoadJSON('test_file_data_source.json'))
   dict_ = _JSCModel(self._LoadJSON(filename)[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False).ToDict()
   self.assertEquals(expected_json, dict_)
Example #11
0
 def DISABLED_testToDict(self):
   filename = 'test_file.json'
   expected_json = self._LoadJSON('expected_' + filename)
   data_source = FakeAPIAndListDataSource(
       self._LoadJSON('test_file_data_source.json'))
   dict_ = _JSCModel(self._LoadJSON(filename)[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False).ToDict()
   self.assertEquals(expected_json, dict_)
Example #12
0
 def testCreateId(self):
     data_source = FakeAPIAndListDataSource(self._LoadJSON("test_file_data_source.json"))
     dict_ = _JSCModel(
         self._LoadJSON("test_file.json")[0], self._CreateRefResolver("test_file_data_source.json"), False
     ).ToDict()
     self.assertEquals("type-TypeA", dict_["types"][0]["id"])
     self.assertEquals("property-TypeA-b", dict_["types"][0]["properties"][0]["id"])
     self.assertEquals("method-get", dict_["functions"][0]["id"])
     self.assertEquals("event-EventA", dict_["events"][0]["id"])
Example #13
0
 def testCreateId(self):
     dict_ = _JSCModel(
         self._api_models.GetModel('tester').Get(),
         _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
         self._features_bundle, None).ToDict()
     self.assertEquals('type-TypeA', dict_['types'][0]['id'])
     self.assertEquals('property-TypeA-b',
                       dict_['types'][0]['properties'][0]['id'])
     self.assertEquals('method-get', dict_['functions'][0]['id'])
     self.assertEquals('event-EventA', dict_['events'][0]['id'])
Example #14
0
 def DISABLED_testToDict(self):
     filename = 'test_file.json'
     expected_json = self._LoadJSON('expected_' + filename)
     dict_ = _JSCModel(
         self._LoadJSON(filename)[0],
         self._CreateRefResolver('test_file_data_source.json'), False,
         _FakeAvailabilityFinder(),
         TestBranchUtility.CreateWithCannedData(), self._json_cache,
         _FakeTemplateCache(), None).ToDict()
     self.assertEquals(expected_json, dict_)
Example #15
0
 def testCreateId(self):
     dict_ = _JSCModel(
         'tester', self._api_models,
         self._CreateRefResolver('test_file_data_source.json'), False,
         _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
         None).ToDict()
     self.assertEquals('type-TypeA', dict_['types'][0]['id'])
     self.assertEquals('property-TypeA-b',
                       dict_['types'][0]['properties'][0]['id'])
     self.assertEquals('method-get', dict_['functions'][0]['id'])
     self.assertEquals('event-EventA', dict_['events'][0]['id'])
Example #16
0
 def testCreateId(self):
   data_source = FakeAPIAndListDataSource(
       self._LoadJSON('test_file_data_source.json'))
   dict_ = _JSCModel(self._LoadJSON('test_file.json')[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False).ToDict()
   self.assertEquals('type-TypeA', dict_['types'][0]['id'])
   self.assertEquals('property-TypeA-b',
                     dict_['types'][0]['properties'][0]['id'])
   self.assertEquals('method-get', dict_['functions'][0]['id'])
   self.assertEquals('event-EventA', dict_['events'][0]['id'])
Example #17
0
 def testCreateId(self):
   data_source = FakeAPIAndListDataSource(
       self._LoadJSON('test_file_data_source.json'))
   dict_ = _JSCModel(self._LoadJSON('test_file.json')[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False).ToDict()
   self.assertEquals('type-TypeA', dict_['types'][0]['id'])
   self.assertEquals('property-TypeA-b',
                     dict_['types'][0]['properties'][0]['id'])
   self.assertEquals('method-get', dict_['functions'][0]['id'])
   self.assertEquals('event-EventA', dict_['events'][0]['id'])
 def DISABLED_testToDict(self):
   expected_json = self._LoadJSON('expected_tester.json')
   dict_ = _JSCModel('tester',
                     self._api_models,
                     False,
                     self._CreateRefResolver('test_file_data_source.json'),
                     _FakeAvailabilityFinder(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     None).ToDict()
   self.assertEquals(expected_json, dict_)
 def DISABLED_testToDict(self):
   filename = 'test_file.json'
   expected_json = self._LoadJSON('expected_' + filename)
   dict_ = _JSCModel(self._LoadJSON(filename)[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     _FakeAvailabilityFinder(),
                     TestBranchUtility.CreateWithCannedData(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     None).ToDict()
   self.assertEquals(expected_json, dict_)
Example #20
0
 def testCreateId(self):
     dict_ = _JSCModel(
         self._LoadJSON('test_file.json')[0],
         self._CreateRefResolver('test_file_data_source.json'), False,
         _FakeAvailabilityFinder(),
         TestBranchUtility.CreateWithCannedData(), self._json_cache,
         _FakeTemplateCache(), None).ToDict()
     self.assertEquals('type-TypeA', dict_['types'][0]['id'])
     self.assertEquals('property-TypeA-b',
                       dict_['types'][0]['properties'][0]['id'])
     self.assertEquals('method-get', dict_['functions'][0]['id'])
     self.assertEquals('event-EventA', dict_['events'][0]['id'])
 def DISABLED_testToDict(self):
     fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability)
     expected_json = self._LoadJSON("expected_tester.json")
     dict_ = _JSCModel(
         self._api_models.GetModel("tester").Get(),
         fake_avail_finder,
         self._json_cache,
         _FakeTemplateCache(),
         self._features_bundle,
         None,
     ).ToDict()
     self.assertEquals(expected_json, dict_)
 def testCreateId(self):
   dict_ = _JSCModel(self._api_models.GetModel('tester').Get(),
                     self._fake_availability,
                     self._json_cache,
                     _FakeTemplateCache(),
                     self._features_bundle,
                     None).ToDict()
   self.assertEquals('type-TypeA', dict_['types'][0]['id'])
   self.assertEquals('property-TypeA-b',
                     dict_['types'][0]['properties'][0]['id'])
   self.assertEquals('method-get', dict_['functions'][0]['id'])
   self.assertEquals('event-EventA', dict_['events'][0]['id'])
Example #23
0
 def testFormatDescription(self):
   dict_ = _JSCModel(self._LoadJSON('ref_test.json')[0],
                     self._CreateRefResolver('ref_test_data_source.json'),
                     False).ToDict()
   self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
                     _GetType(dict_, 'type1')['description'])
   self.assertEquals(
       'A %s, or %s' % (_MakeLink('ref_test.html#type-type3', 'type3'),
                        _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type2')['description'])
   self.assertEquals(
       '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
                     _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type3')['description'])
 def testCreateId(self):
     fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability)
     dict_ = _JSCModel(
         self._api_models.GetModel("tester").Get(),
         fake_avail_finder,
         self._json_cache,
         _FakeTemplateCache(),
         self._features_bundle,
         None,
     ).ToDict()
     self.assertEquals("type-TypeA", dict_["types"][0]["id"])
     self.assertEquals("property-TypeA-b", dict_["types"][0]["properties"][0]["id"])
     self.assertEquals("method-get", dict_["functions"][0]["id"])
     self.assertEquals("event-EventA", dict_["events"][0]["id"])
Example #25
0
 def testFormatDescription(self):
   dict_ = _JSCModel(self._LoadJSON('ref_test.json')[0],
                     self._CreateRefResolver('ref_test_data_source.json'),
                     False).ToDict()
   self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
                     _GetType(dict_, 'type1')['description'])
   self.assertEquals(
       'A %s, or %s' % (_MakeLink('ref_test.html#type-type3', 'type3'),
                        _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type2')['description'])
   self.assertEquals(
       '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
                     _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type3')['description'])
 def testCreateId(self):
   dict_ = _JSCModel('tester',
                     self._api_models,
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     _FakeAvailabilityFinder(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     None).ToDict()
   self.assertEquals('type-TypeA', dict_['types'][0]['id'])
   self.assertEquals('property-TypeA-b',
                     dict_['types'][0]['properties'][0]['id'])
   self.assertEquals('method-get', dict_['functions'][0]['id'])
   self.assertEquals('event-EventA', dict_['events'][0]['id'])
 def testCreateId(self):
   dict_ = _JSCModel(self._LoadJSON('test_file.json')[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     _FakeAvailabilityFinder(),
                     TestBranchUtility.CreateWithCannedData(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     None).ToDict()
   self.assertEquals('type-TypeA', dict_['types'][0]['id'])
   self.assertEquals('property-TypeA-b',
                     dict_['types'][0]['properties'][0]['id'])
   self.assertEquals('method-get', dict_['functions'][0]['id'])
   self.assertEquals('event-EventA', dict_['events'][0]['id'])
Example #28
0
 def testFormatDescription(self):
     dict_ = _JSCModel(
         self._LoadJSON("ref_test.json")[0], self._CreateRefResolver("ref_test_data_source.json"), False
     ).ToDict()
     self.assertEquals(_MakeLink("ref_test.html#type-type2", "type2"), _GetType(dict_, "type1")["description"])
     self.assertEquals(
         "A %s, or %s"
         % (_MakeLink("ref_test.html#type-type3", "type3"), _MakeLink("ref_test.html#type-type2", "type2")),
         _GetType(dict_, "type2")["description"],
     )
     self.assertEquals(
         "%s != %s"
         % (_MakeLink("other.html#type-type2", "other.type2"), _MakeLink("ref_test.html#type-type2", "type2")),
         _GetType(dict_, "type3")["description"],
     )
Example #29
0
 def testFormatDescription(self):
     dict_ = _JSCModel('ref_test', self._api_models,
                       self._CreateRefResolver('ref_test_data_source.json'),
                       False, _FakeAvailabilityFinder(), self._json_cache,
                       _FakeTemplateCache(), None).ToDict()
     self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
                       _GetType(dict_, 'type1')['description'])
     self.assertEquals(
         'A %s, or %s' % (_MakeLink('ref_test.html#type-type3', 'type3'),
                          _MakeLink('ref_test.html#type-type2', 'type2')),
         _GetType(dict_, 'type2')['description'])
     self.assertEquals(
         '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
                       _MakeLink('ref_test.html#type-type2', 'type2')),
         _GetType(dict_, 'type3')['description'])
Example #30
0
 def testGetApiAvailability(self):
     api_availabilities = {
         'bluetooth': ChannelInfo('dev', CANNED_BRANCHES[28], 28),
         'contextMenus': ChannelInfo('trunk', CANNED_BRANCHES['trunk'],
                                     'trunk'),
         'jsonStableAPI': ChannelInfo('stable', CANNED_BRANCHES[20], 20),
         'idle': ChannelInfo('stable', CANNED_BRANCHES[5], 5),
         'input.ime': ChannelInfo('stable', CANNED_BRANCHES[18], 18),
         'tabs': ChannelInfo('stable', CANNED_BRANCHES[18], 18)
     }
     for api_name, availability in api_availabilities.iteritems():
         model = _JSCModel(api_name, self._avail_api_models, None, True,
                           self._avail_finder, self._avail_json_cache,
                           _FakeTemplateCache(), None)
         self.assertEquals(availability, model._GetApiAvailability())
 def testGetIntroList(self):
   model = _JSCModel('tester',
                     self._api_models,
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     _FakeAvailabilityFinder(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     self._features_bundle,
                     None)
   expected_list = [
     { 'title': 'Description',
       'content': [
         { 'text': 'a test api' }
       ]
     },
     { 'title': 'Availability',
       'content': [
         { 'partial': 'handlebar chrome/common/extensions/docs/' +
                      'templates/private/intro_tables/stable_message.html',
           'version': 5
         }
       ]
     },
     { 'title': 'Permissions',
       'content': [
         { 'class': 'override',
           'text': '"tester"'
         },
         { 'text': 'is an API for testing things.' }
       ]
     },
     { 'title': 'Manifest',
       'content': [
         { 'class': 'code',
           'text': '"tester": {...}'
         }
       ]
     },
     { 'title': 'Learn More',
       'content': [
         { 'link': 'https://tester.test.com/welcome.html',
           'text': 'Welcome!'
         }
       ]
     }
   ]
   self.assertEquals(model._GetIntroTableList(), expected_list)
 def testGetIntroList(self):
   model = _JSCModel(self._LoadJSON('test_file.json')[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     FakeAvailabilityFinder(),
                     TestBranchUtility.CreateWithCannedData(),
                     self._json_cache,
                     FakeTemplateDataSource(),
                     None)
   expected_list = [
     { 'title': 'Description',
       'content': [
         { 'text': 'a test api' }
       ]
     },
     { 'title': 'Availability',
       'content': [
         { 'partial': 'handlebar intro_tables/stable_message.html',
           'version': 5
         }
       ]
     },
     { 'title': 'Permissions',
       'content': [
         { 'class': 'override',
           'text': '"tester"'
         },
         { 'text': 'is an API for testing things.' }
       ]
     },
     { 'title': 'Manifest',
       'content': [
         { 'class': 'code',
           'text': '"tester": {...}'
         }
       ]
     },
     { 'title': 'Learn More',
       'content': [
         { 'link': 'https://tester.test.com/welcome.html',
           'text': 'Welcome!'
         }
       ]
     }
   ]
   self.assertEquals(json.dumps(model._GetIntroTableList()),
                     json.dumps(expected_list))
 def testGetIntroList(self):
   model = _JSCModel('tester',
                     self._api_models,
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     _FakeAvailabilityFinder(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     None)
   expected_list = [
     { 'title': 'Description',
       'content': [
         { 'text': 'a test api' }
       ]
     },
     { 'title': 'Availability',
       'content': [
         { 'partial': 'handlebar chrome/common/extensions/docs/' +
                      'templates/private/intro_tables/stable_message.html',
           'version': 5
         }
       ]
     },
     { 'title': 'Permissions',
       'content': [
         { 'class': 'override',
           'text': '"tester"'
         },
         { 'text': 'is an API for testing things.' }
       ]
     },
     { 'title': 'Manifest',
       'content': [
         { 'class': 'code',
           'text': '"tester": {...}'
         }
       ]
     },
     { 'title': 'Learn More',
       'content': [
         { 'link': 'https://tester.test.com/welcome.html',
           'text': 'Welcome!'
         }
       ]
     }
   ]
   self.assertEquals(model._GetIntroTableList(), expected_list)
Example #34
0
 def testGetIntroList(self):
   model = _JSCModel(self._LoadJSON('test_file.json')[0],
                     self._CreateRefResolver('test_file_data_source.json'),
                     False,
                     FakeAvailabilityFinder(),
                     self._json_cache,
                     FakeTemplateDataSource())
   expected_list = [
     { 'title': 'Description',
       'content': [
         { 'text': 'a test api' }
       ]
     },
     { 'title': 'Availability',
       'content': [
         { 'partial': 'handlebar intro_tables/trunk_message.html',
           'version': 'trunk'
         }
       ]
     },
     { 'title': 'Permissions',
       'content': [
         { 'class': 'override',
           'text': '"tester"'
         },
         { 'text': 'is an API for testing things.' }
       ]
     },
     { 'title': 'Manifest',
       'content': [
         { 'class': 'code',
           'text': '"tester": {...}'
         }
       ]
     },
     { 'title': 'Learn More',
       'content': [
         { 'link': 'https://tester.test.com/welcome.html',
           'text': 'Welcome!'
         }
       ]
     }
   ]
   self.assertEquals(json.dumps(model._GetIntroTableList()),
                     json.dumps(expected_list))
    def testGetAPINodeAvailability(self):
        def assertEquals(node, actual):
            node_availabilities = {
                "tabs.Tab": None,
                "tabs.fakeTabsProperty1": None,
                "tabs.get": None,
                "tabs.onUpdated": None,
                "tabs.InjectDetails": 25,
                "tabs.fakeTabsProperty2": 15,
                "tabs.getCurrent": 19,
                "tabs.onActivated": 27,
            }
            self.assertEquals(node_availabilities[node], actual)

        model_dict = _JSCModel(
            self._api_models.GetModel("tabs").Get(),
            self._avail_finder,
            self._json_cache,
            _FakeTemplateCache(),
            _FakeFeaturesBundle(),
            None,
        ).ToDict()

        # Test nodes that have the same availability as their parent.

        # Test type.
        assertEquals("tabs.Tab", model_dict["types"][0]["availability"])
        # Test property.
        assertEquals("tabs.fakeTabsProperty1", model_dict["properties"][0]["availability"])
        # Test function.
        assertEquals("tabs.get", model_dict["functions"][1]["availability"])
        # Test event.
        assertEquals("tabs.onUpdated", model_dict["events"][1]["availability"])

        # Test nodes with varying availabilities.

        # Test type.
        assertEquals("tabs.InjectDetails", model_dict["types"][1]["availability"]["version"])
        # Test property.
        assertEquals("tabs.fakeTabsProperty2", model_dict["properties"][2]["availability"]["version"])
        # Test function.
        assertEquals("tabs.getCurrent", model_dict["functions"][0]["availability"]["version"])
        # Test event.
        assertEquals("tabs.onActivated", model_dict["events"][0]["availability"]["version"])
 def testFormatDescription(self):
   dict_ = _JSCModel(self._LoadJSON('ref_test.json')[0],
                     self._CreateRefResolver('ref_test_data_source.json'),
                     False,
                     FakeAvailabilityFinder(),
                     TestBranchUtility.CreateWithCannedData(),
                     self._json_cache,
                     FakeTemplateDataSource(),
                     None).ToDict()
   self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
                     _GetType(dict_, 'type1')['description'])
   self.assertEquals(
       'A %s, or %s' % (_MakeLink('ref_test.html#type-type3', 'type3'),
                        _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type2')['description'])
   self.assertEquals(
       '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
                     _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type3')['description'])
 def testGetApiAvailability(self):
   api_availabilities = {
     'bluetooth': ChannelInfo('dev', CANNED_BRANCHES[28], 28),
     'contextMenus': ChannelInfo('trunk', CANNED_BRANCHES['trunk'], 'trunk'),
     'jsonStableAPI': ChannelInfo('stable', CANNED_BRANCHES[20], 20),
     'idle': ChannelInfo('stable', CANNED_BRANCHES[5], 5),
     'input.ime': ChannelInfo('stable', CANNED_BRANCHES[18], 18),
     'tabs': ChannelInfo('stable', CANNED_BRANCHES[18], 18)
   }
   for api_name, availability in api_availabilities.iteritems():
     model = _JSCModel(api_name,
                       self._avail_api_models,
                       None,
                       True,
                       self._avail_finder,
                       self._avail_json_cache,
                       _FakeTemplateCache(),
                       None)
     self.assertEquals(availability, model._GetApiAvailability())
 def testGetAPIAvailability(self):
   api_availabilities = {
     'bluetooth': 28,
     'contextMenus': 'trunk',
     'jsonStableAPI': 20,
     'idle': 5,
     'input.ime': 18,
     'tabs': 18
   }
   for api_name, availability in api_availabilities.iteritems():
     model_dict = _JSCModel(
         self._avail_api_models.GetModel(api_name).Get(),
         self._avail_finder.GetAPIAvailability(api_name),
         self._avail_json_cache,
         _FakeTemplateCache(),
         _FakeFeaturesBundle(),
         None).ToDict()
     self.assertEquals(availability,
                       model_dict['introList'][1]['content'][0]['version'])
 def testGetAPIAvailability(self):
     api_availabilities = {
         "bluetooth": 28,
         "contextMenus": "trunk",
         "jsonStableAPI": 20,
         "idle": 5,
         "input.ime": 18,
         "tabs": 18,
     }
     for api_name, availability in api_availabilities.iteritems():
         model_dict = _JSCModel(
             self._api_models.GetModel(api_name).Get(),
             self._avail_finder,
             self._json_cache,
             _FakeTemplateCache(),
             _FakeFeaturesBundle(),
             None,
         ).ToDict()
         self.assertEquals(availability, model_dict["introList"][1]["content"][0]["version"])
 def testFormatDescription(self):
   dict_ = _JSCModel('ref_test',
                     self._api_models,
                     self._CreateRefResolver('ref_test_data_source.json'),
                     False,
                     _FakeAvailabilityFinder(),
                     self._json_cache,
                     _FakeTemplateCache(),
                     None).ToDict()
   self.assertEquals(_MakeLink('ref_test.html#type-type2', 'type2'),
                     _GetType(dict_, 'type1')['description'])
   self.assertEquals(
       'A %s, or %s' % (_MakeLink('ref_test.html#type-type3', 'type3'),
                        _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type2')['description'])
   self.assertEquals(
       '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
                     _MakeLink('ref_test.html#type-type2', 'type2')),
       _GetType(dict_, 'type3')['description'])
Example #41
0
    def testAddRules(self):
        dict_ = _JSCModel(
            self._api_models.GetModel('add_rules_tester').Get(),
            _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
            self._features_bundle, self._FakeLoadAddRulesSchema).ToDict()

        # Check that the first event has the addRulesFunction defined.
        self.assertEquals('add_rules_tester', dict_['name'])
        self.assertEquals('rules', dict_['events'][0]['name'])
        self.assertEquals(
            'notable_name_to_check_for',
            dict_['events'][0]['byName']['addRules']['parameters'][0]['name'])

        # Check that the second event has addListener defined.
        self.assertEquals('noRules', dict_['events'][1]['name'])
        self.assertEquals('add_rules_tester', dict_['name'])
        self.assertEquals('noRules', dict_['events'][1]['name'])
        self.assertEquals(
            'callback', dict_['events'][0]['byName']['addListener']
            ['parameters'][0]['name'])
Example #42
0
    def testAddRules(self):
        dict_ = _JSCModel(
            'add_rules_tester', self._api_models,
            self._CreateRefResolver('test_file_data_source.json'), False,
            _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
            self._FakeLoadAddRulesSchema).ToDict()

        # Check that the first event has the addRulesFunction defined.
        self.assertEquals('add_rules_tester', dict_['name'])
        self.assertEquals('rules', dict_['events'][0]['name'])
        self.assertEquals(
            'notable_name_to_check_for',
            dict_['events'][0]['byName']['addRules']['parameters'][0]['name'])

        # Check that the second event has addListener defined.
        self.assertEquals('noRules', dict_['events'][1]['name'])
        self.assertEquals('add_rules_tester', dict_['name'])
        self.assertEquals('noRules', dict_['events'][1]['name'])
        self.assertEquals(
            'callback', dict_['events'][0]['byName']['addListener']
            ['parameters'][0]['name'])
  def testAddRules(self):
    dict_ = _JSCModel(self._api_models.GetModel('add_rules_tester').Get(),
                      self._fake_availability,
                      self._json_cache,
                      _FakeTemplateCache(),
                      self._features_bundle,
                      self._FakeLoadAddRulesSchema()).ToDict()

    # Check that the first event has the addRulesFunction defined.
    self.assertEquals('add_rules_tester', dict_['name'])
    self.assertEquals('rules', dict_['events'][0]['name'])
    self.assertEquals('notable_name_to_check_for',
                      dict_['events'][0]['byName']['addRules'][
                          'parameters'][0]['name'])

    # Check that the second event has addListener defined.
    self.assertEquals('noRules', dict_['events'][1]['name'])
    self.assertEquals('add_rules_tester', dict_['name'])
    self.assertEquals('noRules', dict_['events'][1]['name'])
    self.assertEquals('callback',
                      dict_['events'][0]['byName']['addListener'][
                          'parameters'][0]['name'])
    def testAddRules(self):
        fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability)
        dict_ = _JSCModel(
            self._api_models.GetModel("add_rules_tester").Get(),
            fake_avail_finder,
            self._json_cache,
            _FakeTemplateCache(),
            self._features_bundle,
            self._FakeLoadAddRulesSchema(),
        ).ToDict()

        # Check that the first event has the addRulesFunction defined.
        self.assertEquals("add_rules_tester", dict_["name"])
        self.assertEquals("rules", dict_["events"][0]["name"])
        self.assertEquals(
            "notable_name_to_check_for", dict_["events"][0]["byName"]["addRules"]["parameters"][0]["name"]
        )

        # Check that the second event has addListener defined.
        self.assertEquals("noRules", dict_["events"][1]["name"])
        self.assertEquals("add_rules_tester", dict_["name"])
        self.assertEquals("noRules", dict_["events"][1]["name"])
        self.assertEquals("callback", dict_["events"][0]["byName"]["addListener"]["parameters"][0]["name"])
Example #45
0
    def testGetIntroList(self):
        model = _JSCModel(
            self._api_models.GetModel('tester').Get(),
            _FakeAvailabilityFinder(), self._json_cache, _FakeTemplateCache(),
            self._features_bundle, None)
        expected_list = [{
            'title': 'Description',
            'content': [{
                'text': 'a test api'
            }]
        }, {
            'title':
            'Availability',
            'content': [{
                'partial':
                'handlebar chrome/common/extensions/docs/' +
                'templates/private/intro_tables/stable_message.html',
                'version':
                5,
                'scheduled':
                None
            }]
        }, {
            'title':
            'Permissions',
            'content': [{
                'class': 'override',
                'text': '"tester"'
            }, {
                'text': 'is an API for testing things.'
            }]
        }, {
            'title':
            'Manifest',
            'content': [{
                'class': 'code',
                'text': '"tester": {...}'
            }]
        }, {
            'title':
            'Learn More',
            'content': [{
                'link': 'https://tester.test.com/welcome.html',
                'text': 'Welcome!'
            }]
        }]
        self.assertEquals(model._GetIntroTableList(), expected_list)

        # Tests the same data with a scheduled availability.
        model = _JSCModel(
            self._api_models.GetModel('tester').Get(),
            _FakeScheduledAvailabilityFinder(), self._json_cache,
            _FakeTemplateCache(), self._features_bundle, None)
        expected_list[1] = {
            'title':
            'Availability',
            'content': [{
                'partial':
                'handlebar chrome/common/extensions/docs/' +
                'templates/private/intro_tables/beta_message.html',
                'version':
                27,
                'scheduled':
                28
            }]
        }
        self.assertEquals(model._GetIntroTableList(), expected_list)
  def testGetIntroList(self):
    model = _JSCModel(self._api_models.GetModel('tester').Get(),
                      self._fake_availability,
                      self._json_cache,
                      _FakeTemplateCache(),
                      self._features_bundle,
                      None)
    expected_list = [
      { 'title': 'Description',
        'content': [
          { 'text': 'a test api' }
        ]
      },
      { 'title': 'Availability',
        'content': [
          { 'partial': 'handlebar chrome/common/extensions/docs/' +
                       'templates/private/intro_tables/stable_message.html',
            'version': 5,
            'scheduled': None
          }
        ]
      },
      { 'title': 'Permissions',
        'content': [
          { 'class': 'override',
            'text': '"tester"'
          },
          { 'text': 'is an API for testing things.' }
        ]
      },
      { 'title': 'Manifest',
        'content': [
          { 'class': 'code',
            'text': '"tester": {...}'
          }
        ]
      },
      { 'title': 'Learn More',
        'content': [
          { 'link': 'https://tester.test.com/welcome.html',
            'text': 'Welcome!'
          }
        ]
      }
    ]
    self.assertEquals(model._GetIntroTableList(), expected_list)

    # Tests the same data with a scheduled availability.
    model = _JSCModel(self._api_models.GetModel('tester').Get(),
        AvailabilityInfo(ChannelInfo('beta', '1453', 27), scheduled=28),
        self._json_cache,
        _FakeTemplateCache(),
        self._features_bundle,
        None)
    expected_list[1] = {
      'title': 'Availability',
      'content': [
        { 'partial': 'handlebar chrome/common/extensions/docs/' +
                     'templates/private/intro_tables/beta_message.html',
          'version': 27,
          'scheduled': 28
        }
      ]
    }
    self.assertEquals(model._GetIntroTableList(), expected_list)