Add --disable-javascript flag to test_runner.py

test_runner.py then passes a flag of the same name on each run of
pdfium_test.

Bug: pdfium:1411
Change-Id: I7ce74a26569ce5dc144dc9606e29f2305e99e41b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62510
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/testing/tools/suppressor.py b/testing/tools/suppressor.py
index a9f9508..a2e39a1 100755
--- a/testing/tools/suppressor.py
+++ b/testing/tools/suppressor.py
@@ -11,10 +11,10 @@
 
 class Suppressor:
 
-  def __init__(self, finder, feature_string):
+  def __init__(self, finder, feature_string, js_disabled):
     feature_vector = feature_string.strip().split(",")
-    self.has_v8 = "V8" in feature_vector
-    self.has_xfa = "XFA" in feature_vector
+    self.has_v8 = not js_disabled and "V8" in feature_vector
+    self.has_xfa = not js_disabled and "XFA" in feature_vector
     self.suppression_set = self._LoadSuppressedSet('SUPPRESSIONS', finder)
     self.image_suppression_set = self._LoadSuppressedSet(
         'SUPPRESSIONS_IMAGE_DIFF', finder)
diff --git a/testing/tools/test_runner.py b/testing/tools/test_runner.py
index 714bbd8..3a055ba 100644
--- a/testing/tools/test_runner.py
+++ b/testing/tools/test_runner.py
@@ -93,7 +93,8 @@
     results = []
     if self.test_type in TEXT_TESTS:
       expected_txt_path = os.path.join(source_dir, input_root + '_expected.txt')
-      raised_exception = self.TestText(input_root, expected_txt_path, pdf_path)
+      raised_exception = self.TestText(input_filename, input_root,
+                                       expected_txt_path, pdf_path)
     else:
       use_ahem = 'use_ahem' in source_dir
       raised_exception, results = self.TestPixel(pdf_path, use_ahem)
@@ -149,19 +150,31 @@
         input_path
     ])
 
-  def TestText(self, input_root, expected_txt_path, pdf_path):
+  def TestText(self, input_filename, input_root, expected_txt_path, pdf_path):
     txt_path = os.path.join(self.working_dir, input_root + '.txt')
 
     with open(txt_path, 'w') as outfile:
       cmd_to_run = [
-          self.pdfium_test_path, '--send-events', '--time=' + TEST_SEED_TIME,
-          pdf_path
+          self.pdfium_test_path, '--send-events', '--time=' + TEST_SEED_TIME
       ]
+
+      if self.options.disable_javascript:
+        cmd_to_run.append('--disable-javascript')
+
+      cmd_to_run.append(pdf_path)
       subprocess.check_call(cmd_to_run, stdout=outfile)
 
+    # If the expected file does not exist, the output is expected to be empty.
     if not os.path.exists(expected_txt_path):
       return self._VerifyEmptyText(txt_path)
 
+    # If JavaScript is disabled, the output should be empty.
+    # However, if the test is suppressed and JavaScript is disabled, do not
+    # verify that the text is empty so the suppressed test does not surprise.
+    if (self.options.disable_javascript and
+        not self.test_suppressor.IsResultSuppressed(input_filename)):
+      return self._VerifyEmptyText(txt_path)
+
     cmd = [sys.executable, self.text_diff_path, expected_txt_path, txt_path]
     return common.RunCommand(cmd)
 
@@ -190,6 +203,9 @@
     if use_ahem:
       cmd_to_run.append('--font-dir=%s' % self.font_dir)
 
+    if self.options.disable_javascript:
+      cmd_to_run.append('--disable-javascript')
+
     if self.options.reverse_byte_order:
       cmd_to_run.append('--reverse-byte-order')
 
@@ -245,6 +261,12 @@
         help='run NUM_WORKERS jobs in parallel')
 
     parser.add_option(
+        '--disable-javascript',
+        action="store_true",
+        dest="disable_javascript",
+        help='Prevents JavaScript from executing in PDF files.')
+
+    parser.add_option(
         '--gold_properties',
         default='',
         dest="gold_properties",
@@ -323,7 +345,8 @@
 
     self.feature_string = subprocess.check_output(
         [self.pdfium_test_path, '--show-config'])
-    self.test_suppressor = suppressor.Suppressor(finder, self.feature_string)
+    self.test_suppressor = suppressor.Suppressor(
+        finder, self.feature_string, self.options.disable_javascript)
     self.image_differ = pngdiffer.PNGDiffer(finder,
                                             self.options.reverse_byte_order)
     error_message = self.image_differ.CheckMissingTools(