def setUp(self):
        SuperMoxTestBase.setUp(self)

        input_api = self.mox.CreateMockAnything()
        input_api.re = re
        output_api = self.mox.CreateMockAnything()
        self.checker = js_checker.JSChecker(input_api, output_api)
def _CommonChecks(input_api, output_api):
  results = []
  results.extend(input_api.canned_checks.PanProjectChecks(
      input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
  results.extend(_CheckIfAboutTracingIsOutOfdate(input_api, output_api))

  from web_dev_style import css_checker, js_checker

  src_dir = os.path.join(input_api.change.RepositoryRoot(), "src")
  FILES_TO_NOT_LINT = [
    input_api.os_path.join(src_dir, "about_tracing.js"),
    input_api.os_path.join(src_dir, "deps.js"),
  ]

  def IsResource(maybe_resource):
    f = maybe_resource.AbsoluteLocalPath()
    print f
    if not f.endswith(('.css', '.html', '.js')):
      return False
    for ignored in FILES_TO_NOT_LINT:
      if input_api.os_path.samefile(f, ignored):
        return False
    return True


  results.extend(css_checker.CSSChecker(input_api, output_api,
                                        file_filter=IsResource).RunChecks())
  results.extend(js_checker.JSChecker(input_api, output_api,
                                      file_filter=IsResource).RunChecks())

  return results
示例#3
0
def _CommonChecks(input_api, output_api):
  """Checks common to both upload and commit."""
  results = []

  path = input_api.os_path
  cwd = input_api.PresubmitLocalPath()
  resources = path.join(cwd, 'resources')
  webui = path.join(cwd, 'ui', 'webui')

  affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles())

  would_affect_tests = [
      path.join(cwd, 'PRESUBMIT.py'),
      path.join(cwd, 'test_presubmit.py'),
  ]
  would_affect_tests += input_api.glob(path.join(cwd, 'web_dev_style', '*.py'))

  if any(f for f in affected_files if f in would_affect_tests):
    tests = [path.join(cwd, 'test_presubmit.py')]
    results.extend(
        input_api.canned_checks.RunUnitTests(input_api, output_api, tests))

  import sys
  old_path = sys.path

  try:
    sys.path = [cwd] + old_path
    from web_dev_style import (resource_checker, css_checker, html_checker,
                               js_checker)

    search_dirs = (resources, webui)
    def _html_css_js_resource(p):
      return p.endswith(('.html', '.css', '.js')) and p.startswith(search_dirs)

    def _vulcanized_resource(p):
      return p.endswith(('vulcanized.html', 'crisper.js'))

    BLACKLIST = [
        'chrome/browser/resources/pdf/index.html',
        'chrome/browser/resources/pdf/index.js'
    ]
    def is_resource(maybe_resource):
      return (maybe_resource.LocalPath() not in BLACKLIST and
          not _vulcanized_resource(maybe_resource.LocalPath()) and
          _html_css_js_resource(maybe_resource.AbsoluteLocalPath()))

    results.extend(resource_checker.ResourceChecker(
        input_api, output_api, file_filter=is_resource).RunChecks())
    results.extend(css_checker.CSSChecker(
        input_api, output_api, file_filter=is_resource).RunChecks())
    results.extend(html_checker.HtmlChecker(
        input_api, output_api, file_filter=is_resource).RunChecks())
    results.extend(js_checker.JSChecker(
        input_api, output_api, file_filter=is_resource).RunChecks())
    results.extend(_RunHistogramChecks(input_api, output_api,
      "BadMessageReasonChrome"))
  finally:
    sys.path = old_path

  return results
示例#4
0
def _CommonChecks(input_api, output_api):
    """Checks common to both upload and commit."""
    results = []
    resources = input_api.PresubmitLocalPath()

    path = input_api.os_path
    affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles())
    would_affect_tests = (
        path.join(resources, 'PRESUBMIT.py'),
        path.join(resources, 'test_presubmit.py'),
        path.join(resources, 'web_dev_style', 'css_checker.py'),
        path.join(resources, 'web_dev_style', 'js_checker.py'),
    )
    if any(f for f in affected_files if f in would_affect_tests):
        tests = [path.join(resources, 'test_presubmit.py')]
        results.extend(
            input_api.canned_checks.RunUnitTests(input_api, output_api, tests))

    import sys
    old_path = sys.path

    try:
        sys.path = [resources] + old_path
        from web_dev_style import css_checker, js_checker

        def _html_css_js_resource(p):
            return p.endswith(
                ('.html', '.css', '.js')) and p.startswith(resources)

        def is_resource(maybe_resource):
            return _html_css_js_resource(maybe_resource.AbsoluteLocalPath())

        # TODO(samarth): remove this exception <http://crbug.com/222642>.
        instant_path = path.join(resources, 'local_omnibox_popup')

        def is_resource_no_instant(maybe_resource):
            f = maybe_resource.AbsoluteLocalPath()
            return _html_css_js_resource(f) and not f.startswith(instant_path)

        results.extend(
            css_checker.CSSChecker(
                input_api, output_api,
                file_filter=is_resource_no_instant).RunChecks())
        results.extend(
            js_checker.JSChecker(input_api,
                                 output_api,
                                 file_filter=is_resource).RunChecks())
    finally:
        sys.path = old_path

    return results
示例#5
0
def common_checks(input_api, output_api):
    import sys
    web_dev_style_path = input_api.os_path.join(
        input_api.change.RepositoryRoot(), 'tools')
    oldpath = sys.path
    sys.path = [input_api.PresubmitLocalPath(), web_dev_style_path] + sys.path
    from web_dev_style import js_checker
    sys.path = oldpath

    def is_resource(maybe_resource):
        return maybe_resource.AbsoluteLocalPath().endswith('.js')

    return js_checker.JSChecker(input_api, output_api,
                                file_filter=is_resource).RunChecks()
示例#6
0
def _CommonChecks(input_api, output_api):
    """Checks common to both upload and commit."""
    results = []
    resources = input_api.PresubmitLocalPath()

    path = input_api.os_path
    affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles())
    would_affect_tests = (
        path.join(resources, 'PRESUBMIT.py'),
        path.join(resources, 'test_presubmit.py'),
        path.join(resources, 'web_dev_style', 'css_checker.py'),
        path.join(resources, 'web_dev_style', 'js_checker.py'),
    )
    if any(f for f in affected_files if f in would_affect_tests):
        tests = [path.join(resources, 'test_presubmit.py')]
        results.extend(
            input_api.canned_checks.RunUnitTests(input_api, output_api, tests))

    import sys
    old_path = sys.path

    try:
        sys.path = [resources] + old_path
        from web_dev_style import css_checker, js_checker

        def _html_css_js_resource(p):
            return p.endswith(
                ('.html', '.css', '.js')) and p.startswith(resources)

        BLACKLIST = [
            'chrome/browser/resources/pdf/index.html',
            'chrome/browser/resources/pdf/index.js'
        ]

        def is_resource(maybe_resource):
            return (maybe_resource.LocalPath() not in BLACKLIST and
                    _html_css_js_resource(maybe_resource.AbsoluteLocalPath()))

        results.extend(
            css_checker.CSSChecker(input_api,
                                   output_api,
                                   file_filter=is_resource).RunChecks())
        results.extend(
            js_checker.JSChecker(input_api,
                                 output_api,
                                 file_filter=is_resource).RunChecks())
    finally:
        sys.path = old_path

    return results
示例#7
0
def _CommonChecks(input_api, output_api):
  resources = input_api.PresubmitLocalPath()

  def _html_css_js_resource(p):
    return p.endswith(('.js')) and p.startswith(resources)

  def is_resource(maybe_resource):
    return _html_css_js_resource(maybe_resource.AbsoluteLocalPath())

  from web_dev_style import js_checker

  results = []
  results.extend(js_checker.JSChecker(
      input_api, output_api, file_filter=is_resource).RunChecks())

  return results
    def setUp(self):
        SuperMoxTestBase.setUp(self)

        input_api = self.mox.CreateMockAnything()
        input_api.os_path = os.path
        input_api.re = re

        input_api.change = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(input_api.change, 'RepositoryRoot')
        src_root = os.path.join(os.path.dirname(__file__), '..', '..')
        input_api.change.RepositoryRoot().MultipleTimes().AndReturn(src_root)

        output_api = self.mox.CreateMockAnything()

        self.mox.ReplayAll()

        self.checker = js_checker.JSChecker(input_api, output_api)
示例#9
0
def _CommonChecks(input_api, output_api):
    """Checks common to both upload and commit."""
    results = []
    resources = input_api.PresubmitLocalPath()

    path = input_api.os_path
    affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles())
    would_affect_tests = (
        path.join(resources, 'PRESUBMIT.py'),
        path.join(resources, 'test_presubmit.py'),
        path.join(resources, 'web_dev_style', 'css_checker.py'),
        path.join(resources, 'web_dev_style', 'js_checker.py'),
    )
    if any(f for f in affected_files if f in would_affect_tests):
        tests = [path.join(resources, 'test_presubmit.py')]
        results.extend(
            input_api.canned_checks.RunUnitTests(input_api, output_api, tests))

    import sys
    old_path = sys.path

    try:
        sys.path.insert(0, resources)
        from web_dev_style import css_checker, js_checker

        def is_resource(f):
            return f.LocalPath().endswith(('.css', '.html', '.js'))

        results.extend(
            css_checker.CSSChecker(input_api,
                                   output_api,
                                   file_filter=is_resource).RunChecks())
        results.extend(
            js_checker.JSChecker(input_api,
                                 output_api,
                                 file_filter=is_resource).RunChecks())
    finally:
        sys.path = old_path

    return results
示例#10
0
def _CommonChecks(input_api, output_api):
    results = []
    results.extend(
        input_api.canned_checks.PanProjectChecks(
            input_api, output_api, excluded_paths=_EXCLUDED_PATHS))

    src_dir = os.path.join(input_api.change.RepositoryRoot(), "src")

    def IsResource(maybe_resource):
        f = maybe_resource.AbsoluteLocalPath()
        if not f.endswith(('.css', '.html', '.js')):
            return False
        return True

    from web_dev_style import css_checker, js_checker
    results.extend(
        css_checker.CSSChecker(input_api, output_api,
                               file_filter=IsResource).RunChecks())
    results.extend(
        js_checker.JSChecker(input_api, output_api,
                             file_filter=IsResource).RunChecks())

    from build import check_gyp
    gyp_result = check_gyp.GypCheck()
    if len(gyp_result) > 0:
        results.extend([output_api.PresubmitError(gyp_result)])

    from build import check_grit
    grit_result = check_grit.GritCheck()
    if len(grit_result) > 0:
        results.extend([output_api.PresubmitError(grit_result)])

    black_list = input_api.DEFAULT_BLACK_LIST
    sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
    results.extend(
        input_api.canned_checks.CheckLicense(input_api,
                                             output_api,
                                             _LICENSE_HEADER,
                                             source_file_filter=sources))
    return results