Ejemplo n.º 1
0
 def test_FilterPaths(self):
     """This verifies that _FilterPaths removes expected paths."""
     diff_file_chromium1_h = ['some diff']
     diff_web_tests_html = ['more diff']
     diff_presubmit = ['morer diff']
     diff_test_expectations = ['morest diff']
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('file_chromium1.h', diff_file_chromium1_h),
         MockAffectedFile('web_tests/some_tests.html', diff_web_tests_html),
         MockAffectedFile('web_tests/TestExpectations',
                          diff_test_expectations),
         MockAffectedFile('blink/PRESUBMIT', diff_presubmit),
     ]
     # Access to a protected member _FilterPaths
     # pylint: disable=W0212
     filtered = PRESUBMIT._FilterPaths(mock_input_api)
     self.assertEqual(2, len(filtered))
     self.assertEqual(
         mock_input_api.os_path.join('..', '..', 'file_chromium1.h'),
         filtered[0])
     self.assertEqual(
         mock_input_api.os_path.join('..', '..',
                                     'web_tests/TestExpectations'),
         filtered[1])
Ejemplo n.º 2
0
 def testModifiedWithoutReadme(self):
   input_api = MockInputApi()
   input_api.files = [
     MockAffectedFile('somefile.proto', 'some diff'),
     MockAffectedFile(PRESUBMIT.README, 'some diff'),
   ]
   self.assertEqual(0, len(PRESUBMIT.CheckChange(input_api, MockOutputApi())))
Ejemplo n.º 3
0
    def testCheckAndroidTestAnnotationUsage(self):
        mock_input_api = MockInputApi()
        mock_output_api = MockOutputApi()

        mock_input_api.files = [
            MockAffectedFile('LalaLand.java', ['random stuff']),
            MockAffectedFile('CorrectUsage.java', [
                'import org.junit.ABC',
                'import org.junit.XYZ;',
            ]),
            MockAffectedFile('UsedDeprecatedJUnit.java', [
                'import junit.framework.*;',
            ]),
            MockAffectedFile('UsedDeprecatedJUnitAssert.java', [
                'import junit.framework.Assert;',
            ]),
        ]
        msgs = PRESUBMIT._CheckAndroidTestJUnitFrameworkImport(
            mock_input_api, mock_output_api)
        self.assertEqual(
            1, len(msgs),
            'Expected %d items, found %d: %s' % (1, len(msgs), msgs))
        self.assertEqual(
            2, len(msgs[0].items), 'Expected %d items, found %d: %s' %
            (2, len(msgs[0].items), msgs[0].items))
        self.assertTrue('UsedDeprecatedJUnit.java:1' in msgs[0].items,
                        'UsedDeprecatedJUnit.java not found in errors')
        self.assertTrue('UsedDeprecatedJUnitAssert.java:1' in msgs[0].items,
                        'UsedDeprecatedJUnitAssert not found in errors')
Ejemplo n.º 4
0
 def testCheckHeadersOnlyOutsideThirdParty(self):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('somewhere/file.cc', ['class DummyClass;']),
         MockAffectedFile('third_party/header.h', ['class DummyClass;'])
     ]
     warnings = PRESUBMIT._CheckUselessForwardDeclarations(
         mock_input_api, MockOutputApi())
     self.assertEqual(0, len(warnings))
Ejemplo n.º 5
0
    def testConstLetWarningIos9Code(self):
        mock_input_api = MockInputApi()
        mock_output_api = MockOutputApi()

        mock_input_api.files = [
            MockAffectedFile('components/blah.js', [" const foo = 'bar';"]),
            MockAffectedFile('ui/webui/resources/blah.js', [" let foo = 3;"]),
        ]
        warnings = PRESUBMIT._CheckForRiskyJsFeatures(mock_input_api,
                                                      mock_output_api)
        self.assertEqual(2, len(warnings))
Ejemplo n.º 6
0
    def testInnocuousChangesAllowed(self):
        mock_input_api = MockInputApi()
        mock_input_api.files = [
            MockAffectedFile('test.cpp', '#include "header.h"'),
            MockAffectedFile('test2.cpp', '../'),
        ]

        mock_output_api = MockOutputApi()

        errors = PRESUBMIT._CheckForRelativeIncludes(mock_input_api,
                                                     mock_output_api)
        self.assertEqual(0, len(errors))
Ejemplo n.º 7
0
 def testBaseMacrosInHeadersBad(self):
   mock_input_api = MockInputApi()
   mock_input_api.files = [
     MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')),
     MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')),
     MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')),
     MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')),
   ]
   warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api,
                                                  MockOutputApi())
   self.assertEqual(1, len(warnings))
   self.assertEqual(4, len(warnings[0].items))
Ejemplo n.º 8
0
    def testThirdPartyNotWebKitIgnored(self):
        mock_input_api = MockInputApi()
        mock_input_api.files = [
            MockAffectedFile('third_party/test.cpp', '#include "../header.h"'),
            MockAffectedFile('third_party/test/test.cpp',
                             '#include "../header.h"'),
        ]

        mock_output_api = MockOutputApi()

        errors = PRESUBMIT._CheckForRelativeIncludes(mock_input_api,
                                                     mock_output_api)
        self.assertEqual(0, len(errors))
Ejemplo n.º 9
0
    def testCheckWamMintTriggerRule(self):
        COMMON_SRC_FILE_PATH = (
            'libs/common/src/org/chromium/webapk/lib/common/A.java')
        COMMON_JUNIT_FILE_PATH = (
            'libs/common/junit/src/org/chromium/webapk/lib/common/B.java')
        SHELL_APK_SRC_FILE_PATH = (
            'shell_apk/src/org/chromium/webapk/shell_apk/C.java')
        SHELL_APK_JUNIT_FILE_PATH = (
            'shell_apk/junit/src/org/chromium/webapk/shell_apk/D.java')
        changed_java_file_paths = [
            COMMON_SRC_FILE_PATH, COMMON_JUNIT_FILE_PATH,
            SHELL_APK_SRC_FILE_PATH, SHELL_APK_JUNIT_FILE_PATH
        ]

        SHELL_APK_RES_FILE_PATH = 'shell_apk/res/mipmap-xxxxxxhdpi/app_icon.png'
        CURRENT_VERSION_FILE_PATH = 'shell_apk/current_version/current_version.gni'

        # template_shell_apk_version not updated. There should be a warning about
        # template_shell_apk_version needing to be updated.
        input_api = CustomMockInputApi()
        input_api.files = input_api.makeMockAffectedFiles(
            changed_java_file_paths + [SHELL_APK_RES_FILE_PATH])
        input_api.files += [
            MockAffectedFile(CURRENT_VERSION_FILE_PATH,
                             'variable=O',
                             'variable=N',
                             action='M')
        ]
        warnings = PRESUBMIT._CheckCurrentVersionIncreaseRule(
            input_api, MockOutputApi())
        self.assertEqual(1, len(warnings))
        self.assertEqual(self.UPDATE_CURRENT_VERSION_MESSAGE,
                         warnings[0].message)
        self.assertEqual([
            COMMON_SRC_FILE_PATH, SHELL_APK_SRC_FILE_PATH,
            SHELL_APK_RES_FILE_PATH
        ], warnings[0].items)

        # template_shell_apk_version updated. There should be no warnings.
        input_api.files = input_api.makeMockAffectedFiles(
            changed_java_file_paths + [SHELL_APK_RES_FILE_PATH])
        input_api.files += [
            MockAffectedFile(CURRENT_VERSION_FILE_PATH,
                             ['current_shell_apk_version=1'],
                             ['current_shell_apk_version=2'],
                             action='M')
        ]
        warnings = PRESUBMIT._CheckCurrentVersionIncreaseRule(
            input_api, MockOutputApi())
        self.assertEqual([], warnings)
Ejemplo n.º 10
0
 def testBlinkHeaders(self):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('third_party/WebKit/header.h', [
             'class DummyClass;',
             'struct DummyStruct;',
         ]),
         MockAffectedFile('third_party\\WebKit\\header.h', [
             'class DummyClass;',
             'struct DummyStruct;',
         ])
     ]
     warnings = PRESUBMIT._CheckUselessForwardDeclarations(
         mock_input_api, MockOutputApi())
     self.assertEqual(4, len(warnings))
Ejemplo n.º 11
0
 def testSingletonInArbitraryHeader(self):
   diff_singleton_h = ['base::subtle::AtomicWord '
                       'Singleton<Type, Traits, DifferentiatingType>::']
   diff_foo_h = ['// Singleton<Foo> in comment.',
                 'friend class Singleton<Foo>']
   diff_bad_h = ['Foo* foo = Singleton<Foo>::get();']
   mock_input_api = MockInputApi()
   mock_input_api.files = [MockAffectedFile('base/memory/singleton.h',
                                    diff_singleton_h),
                           MockAffectedFile('foo.h', diff_foo_h),
                           MockAffectedFile('bad.h', diff_bad_h)]
   warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
                                                 MockOutputApi())
   self.assertEqual(1, len(warnings))
   self.assertEqual('error', warnings[0].type)
   self.assertTrue('Found Singleton<T>' in warnings[0].message)
Ejemplo n.º 12
0
 def testSingletonInCC(self):
   diff_cc = ['Foo* foo = Singleton<Foo>::get();']
   mock_input_api = MockInputApi()
   mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)]
   warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
                                                 MockOutputApi())
   self.assertEqual(0, len(warnings))
Ejemplo n.º 13
0
  def testRandomPyIgnored(self):
    self.mock_input_api.files = [
      MockAffectedFile('random.py', []),
    ]

    results = self._RunCheck()
    self.assertEqual(0, len(results), 'Unexpected results: %r' % results)
Ejemplo n.º 14
0
 def testCheckChangeOnUploadWithEmptyAffectedFileList(self, _):
     """This verifies that CheckChangeOnUpload will skip calling
     check-webkit-style if the affected file list is empty.
     """
     diff_file_chromium1_h = ['some diff']
     diff_file_chromium2_h = ['another diff']
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('first_file_chromium.h', diff_file_chromium1_h),
         MockAffectedFile('second_file_chromium.h', diff_file_chromium2_h)
     ]
     # Access to a protected member _CheckStyle
     # pylint: disable=W0212
     PRESUBMIT._CheckStyle(mock_input_api, MockOutputApi())
     # pylint: disable=E1101
     subprocess.Popen.assert_not_called()
Ejemplo n.º 15
0
 def testAdditionOfUnwantedDependency(self):
     input_api = self.makeInputApi(
         [MockAffectedFile('DEPS', [_INVALID_DEP], [], action='M')])
     warnings = PRESUBMIT._CheckUnwantedDependencies(
         input_api, MockOutputApi())
     self.assertEqual(1, len(warnings))
     self.assertEqual(self.INVALID_DEPS_MESSAGE, warnings[0].message)
     self.assertEqual(1, len(warnings[0].items))
 def testNewUsageSequencedTaskRunnerHandleGet(self):
   diff = ['scoped_refptr<SequencedThreadTaskRunner> task_runner =',
            '    base::SequencedTaskRunnerHandle::Get()']
   input_api = MockInputApi()
   input_api.files = [MockAffectedFile('content/renderer/foo.cc', diff)]
   errors = PRESUBMIT._CheckForUseOfGlobalTaskRunnerGetter(input_api,
                                                           MockOutputApi())
   self.assertEqual(1, len(errors))
Ejemplo n.º 17
0
  def testAddedPydep(self):
    self.mock_input_api.files = [
      MockAffectedFile('new.pydeps', [], action='A'),
    ]

    results = self._RunCheck()
    self.assertEqual(1, len(results))
    self.assertTrue('PYDEPS_FILES' in str(results[0]))
Ejemplo n.º 18
0
    def testAndroidChangeIncluded(self):
        mock_input_api = MockInputApi()

        mock_input_api.files = [
            MockAffectedFile('content/test/data/accessibility/event/foo.html',
                             [''],
                             action='A'),
            MockAffectedFile(
                'accessibility/WebContentsAccessibilityEventsTest.java', [''],
                action='M')
        ]

        msgs = PRESUBMIT.CheckAccessibilityEventsTestIncludesAndroid(
            mock_input_api, MockOutputApi())
        self.assertEqual(
            0, len(msgs),
            'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))
Ejemplo n.º 19
0
 def runCheck(self, filename, file_contents):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile(filename, file_contents),
     ]
     # Access to a protected member
     # pylint: disable=W0212
     return PRESUBMIT._CheckForForbiddenNamespace(mock_input_api, MockOutputApi())
Ejemplo n.º 20
0
  def testRemovedPydep(self):
    self.mock_input_api.files = [
      MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'),
    ]

    results = self._RunCheck()
    self.assertEqual(1, len(results))
    self.assertTrue('PYDEPS_FILES' in str(results[0]))
Ejemplo n.º 21
0
 def testArrowsAllowedInChromeCode(self):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('chrome/browser/resources/blah.js',
                          'arrow => OK here'),
     ]
     warnings = PRESUBMIT._CheckForRiskyJsFeatures(mock_input_api,
                                                   MockOutputApi())
     self.assertEqual(0, len(warnings))
Ejemplo n.º 22
0
 def testCheckChangeOnUploadWithWebKitAndChromiumFiles(self, _):
     """This verifies that CheckChangeOnUpload will only call check-webkit-style
     on WebKit files.
     """
     diff_file_webkit_h = ['some diff']
     diff_file_chromium_h = ['another diff']
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('FileWebkit.h', diff_file_webkit_h),
         MockAffectedFile('file_chromium.h', diff_file_chromium_h)
     ]
     # Access to a protected member _CheckStyle
     # pylint: disable=W0212
     PRESUBMIT._CheckStyle(mock_input_api, MockOutputApi())
     capture = Capture()
     # pylint: disable=E1101
     subprocess.Popen.assert_called_with(capture, stderr=-1)
     self.assertEqual(4, len(capture.value))
     self.assertEqual('../../FileWebkit.h', capture.value[3])
Ejemplo n.º 23
0
    def testIgnoreNonRelatedHtmlFiles(self):
        mock_input_api = MockInputApi()

        mock_input_api.files = [
            MockAffectedFile('content/test/data/accessibility/aria/foo.html',
                             [''],
                             action='A'),
            MockAffectedFile('content/test/data/accessibility/html/foo.html',
                             [''],
                             action='A'),
            MockAffectedFile('chrome/tests/data/accessibility/foo.html', [''],
                             action='A')
        ]

        msgs = PRESUBMIT.CheckAccessibilityEventsTestIncludesAndroid(
            mock_input_api, MockOutputApi())
        self.assertEqual(
            0, len(msgs),
            'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))
Ejemplo n.º 24
0
 def testNoNestedDeclaration(self):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('somewhere/header.h', [
             'class SomeClass {', ' protected:', '  class NotAMatch;', '};'
         ])
     ]
     warnings = PRESUBMIT._CheckUselessForwardDeclarations(
         mock_input_api, MockOutputApi())
     self.assertEqual(0, len(warnings))
Ejemplo n.º 25
0
 def testUselessForwardDeclaration(self):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('somewhere/header.h', [
             'class DummyClass;', 'struct DummyStruct;',
             'class UsefulClass;', 'std::unique_ptr<UsefulClass> p;'
         ])
     ]
     warnings = PRESUBMIT._CheckUselessForwardDeclarations(
         mock_input_api, MockOutputApi())
     self.assertEqual(2, len(warnings))
Ejemplo n.º 26
0
 def testSubStrings(self):
     mock_input_api = MockInputApi()
     mock_input_api.files = [
         MockAffectedFile('somewhere/header.h', [
             'class NotUsefulClass;', 'struct SomeStruct;',
             'UsefulClass *p1;', 'SomeStructPtr *p2;'
         ])
     ]
     warnings = PRESUBMIT._CheckUselessForwardDeclarations(
         mock_input_api, MockOutputApi())
     self.assertEqual(2, len(warnings))
Ejemplo n.º 27
0
    def testNonCppFileIgnored(self):
        mock_input_api = MockInputApi()
        mock_input_api.files = [
            MockAffectedFile('test.py', '#include "../header.h"'),
        ]

        mock_output_api = MockOutputApi()

        errors = PRESUBMIT._CheckForRelativeIncludes(mock_input_api,
                                                     mock_output_api)
        self.assertEqual(0, len(errors))
Ejemplo n.º 28
0
    def testRandomPyIgnored(self):
        # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android.
        if self.mock_input_api.platform != 'linux2':
            return []

        self.mock_input_api.files = [
            MockAffectedFile('random.py', []),
        ]

        results = self._RunCheck()
        self.assertEqual(0, len(results), 'Unexpected results: %r' % results)
Ejemplo n.º 29
0
    def testRelativeIncludeNonWebKitProducesError(self):
        mock_input_api = MockInputApi()
        mock_input_api.files = [
            MockAffectedFile('test.cpp', ['#include "../header.h"']),
        ]

        mock_output_api = MockOutputApi()

        errors = PRESUBMIT._CheckForRelativeIncludes(mock_input_api,
                                                     mock_output_api)
        self.assertEqual(1, len(errors))
Ejemplo n.º 30
0
    def testRemovedPydep(self):
        # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android.
        if self.mock_input_api.platform != 'linux2':
            return []

        self.mock_input_api.files = [
            MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'),
        ]

        results = self._RunCheck()
        self.assertEqual(1, len(results))
        self.assertTrue('PYDEPS_FILES' in str(results[0]))