Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: chrome/browser/test_presubmit.py

Issue 410603002: web_dev_style: add presubmit for superfluous </include> tags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/PRESUBMIT.py ('k') | chrome/browser/web_dev_style/js_checker.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/test_presubmit.py
diff --git a/chrome/browser/test_presubmit.py b/chrome/browser/test_presubmit.py
index 1f7e939199c08f713be9063acf8c8b465a4889e8..018991f0b7673cd7c69503f522d506b4189c5ef4 100755
--- a/chrome/browser/test_presubmit.py
+++ b/chrome/browser/test_presubmit.py
@@ -18,7 +18,56 @@ sys.path.extend([
import find_depot_tools # pylint: disable=W0611
from testing_support.super_mox import SuperMoxTestBase
-from web_dev_style import css_checker, js_checker # pylint: disable=F0401
+from web_dev_style import resource_checker, css_checker, js_checker # pylint: disable=F0401
+
+
+def GetHighlight(line, error):
+ """Returns the substring of |line| that is highlighted in |error|."""
+ error_lines = error.split('\n')
+ highlight = error_lines[error_lines.index(line) + 1]
+ return ''.join(ch1 for (ch1, ch2) in zip(line, highlight) if ch2 == '^')
+
+
+class ResourceStyleGuideTest(SuperMoxTestBase):
+ def setUp(self):
+ SuperMoxTestBase.setUp(self)
+
+ input_api = self.mox.CreateMockAnything()
+ input_api.re = re
+ output_api = self.mox.CreateMockAnything()
+ self.checker = resource_checker.ResourceChecker(input_api, output_api)
+
+ def ShouldFailIncludeCheck(self, line):
+ """Checks that the '</include>' checker flags |line| as a style error."""
+ error = self.checker.IncludeCheck(1, line)
+ self.assertNotEqual('', error,
+ 'Should be flagged as style error: ' + line)
+ self.assertEqual(GetHighlight(line, error), '</include>')
+
+ def ShouldPassIncludeCheck(self, line):
+ """Checks that the '</include>' checker doesn't flag |line| as an error."""
+ self.assertEqual('', self.checker.IncludeCheck(1, line),
+ 'Should not be flagged as style error: ' + line)
+
+ def testIncludeFails(self):
+ lines = [
+ "</include> ",
+ " </include>",
+ " </include> ",
+ ]
+ for line in lines:
+ self.ShouldFailIncludeCheck(line)
+
+ def testIncludePasses(self):
+ lines = [
+ '<include src="assert.js">',
+ "<include src='../../assert.js'>",
+ "<i>include src='blah'</i>",
+ "</i>nclude",
+ "</i>include",
+ ]
+ for line in lines:
+ self.ShouldPassIncludeCheck(line)
class JsStyleGuideTest(SuperMoxTestBase):
@@ -30,18 +79,12 @@ class JsStyleGuideTest(SuperMoxTestBase):
output_api = self.mox.CreateMockAnything()
self.checker = js_checker.JSChecker(input_api, output_api)
- def GetHighlight(self, line, error):
- """Returns the substring of |line| that is highlighted in |error|."""
- error_lines = error.split('\n')
- highlight = error_lines[error_lines.index(line) + 1]
- return ''.join(ch1 for (ch1, ch2) in zip(line, highlight) if ch2 == '^')
-
def ShouldFailConstCheck(self, line):
"""Checks that the 'const' checker flags |line| as a style error."""
error = self.checker.ConstCheck(1, line)
self.assertNotEqual('', error,
'Should be flagged as style error: ' + line)
- self.assertEqual(self.GetHighlight(line, error), 'const')
+ self.assertEqual(GetHighlight(line, error), 'const')
def ShouldPassConstCheck(self, line):
"""Checks that the 'const' checker doesn't flag |line| as a style error."""
@@ -100,7 +143,7 @@ class JsStyleGuideTest(SuperMoxTestBase):
error = self.checker.ChromeSendCheck(1, line)
self.assertNotEqual('', error,
'Should be flagged as style error: ' + line)
- self.assertEqual(self.GetHighlight(line, error), ', []')
+ self.assertEqual(GetHighlight(line, error), ', []')
def ShouldPassChromeSendCheck(self, line):
"""Checks that the 'chrome.send' checker doesn't flag |line| as a style
@@ -132,7 +175,7 @@ class JsStyleGuideTest(SuperMoxTestBase):
error = self.checker.EndJsDocCommentCheck(1, line)
self.assertNotEqual('', error,
'Should be flagged as style error: ' + line)
- self.assertEqual(self.GetHighlight(line, error), '**/')
+ self.assertEqual(GetHighlight(line, error), '**/')
def ShouldPassEndJsDocCommentCheck(self, line):
"""Checks that the **/ checker doesn't flag |line| as a style error."""
@@ -167,7 +210,7 @@ class JsStyleGuideTest(SuperMoxTestBase):
error = self.checker.GetElementByIdCheck(1, line)
self.assertNotEqual('', error,
'Should be flagged as style error: ' + line)
- self.assertEqual(self.GetHighlight(line, error), 'document.getElementById')
+ self.assertEqual(GetHighlight(line, error), 'document.getElementById')
def ShouldPassGetElementByIdCheck(self, line):
"""Checks that the 'getElementById' checker doesn't flag |line| as a style
@@ -207,7 +250,7 @@ class JsStyleGuideTest(SuperMoxTestBase):
error = self.checker.InheritDocCheck(1, line)
self.assertNotEqual('', error,
msg='Should be flagged as style error: ' + line)
- self.assertEqual(self.GetHighlight(line, error), '@inheritDoc')
+ self.assertEqual(GetHighlight(line, error), '@inheritDoc')
def ShouldPassInheritDocCheck(self, line):
"""Checks that the '@inheritDoc' checker doesn't flag |line| as a style
@@ -241,7 +284,7 @@ class JsStyleGuideTest(SuperMoxTestBase):
error = self.checker.WrapperTypeCheck(1, line)
self.assertNotEqual('', error,
msg='Should be flagged as style error: ' + line)
- highlight = self.GetHighlight(line, error)
+ highlight = GetHighlight(line, error)
self.assertTrue(highlight in ('Boolean', 'Number', 'String'))
def ShouldPassWrapperTypeCheck(self, line):
@@ -283,7 +326,7 @@ class JsStyleGuideTest(SuperMoxTestBase):
error = self.checker.VarNameCheck(1, line)
self.assertNotEqual('', error,
msg='Should be flagged as style error: ' + line)
- highlight = self.GetHighlight(line, error)
+ highlight = GetHighlight(line, error)
self.assertFalse('var ' in highlight);
def ShouldPassVarNameCheck(self, line):
« no previous file with comments | « chrome/browser/PRESUBMIT.py ('k') | chrome/browser/web_dev_style/js_checker.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698