예제 #1
0
    def testErrorStackTraceHTML(self):
        file_path = self.GetTestFilePath('error_stack_test.html')
        # error_stack_test.html imports error_stack_test.js
        # error_stack_test.js imports load_simple_html.html
        # load_simple_html.html imports foo.html
        # foo.html imports error.js
        # error.js defines maybeRaiseException() method that can raise exception
        # foo.html defines maybeRaiseExceptionInFoo() method that calls
        # maybeRaiseException()
        # Finally, we call maybeRaiseExceptionInFoo() error_stack_test.js
        # Exception log should capture these method calls' stack trace.
        with self.assertRaises(RuntimeError) as context:
            d8_runner.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message
        self.assertIn(('error.js:7: Error: Throw ERROR\n'
                       "    throw new Error('Throw ERROR');"),
                      exception_message)

        self.AssertHasNamedFrame('maybeRaiseException', 'error.js:7',
                                 exception_message)
        self.AssertHasNamedFrame('global.maybeRaiseExceptionInFoo',
                                 'foo.html:34', exception_message)
        self.AssertHasFrame('error_stack_test.js:14', exception_message)
        self.AssertHasNamedFrame('eval', 'error_stack_test.html:22',
                                 exception_message)
예제 #2
0
 def testJsFileLoadJsFile(self):
     file_path = self.GetTestFilePath('load_simple_js.js')
     output = d8_runner.ExecuteFile(file_path,
                                    source_paths=[self.test_data_dir])
     expected_output = ('bar.js is loaded\n'
                        'load_simple_js.js is loaded\n')
     self.assertEquals(output, expected_output)
예제 #3
0
 def testSimpleJsExecution(self):
     file_path = self.GetTestFilePath('print_file_content.js')
     dummy_test_path = self.GetTestFilePath('dummy_test_file')
     output = d8_runner.ExecuteFile(file_path,
                                    source_paths=[self.test_data_dir],
                                    js_args=[dummy_test_path])
     self.assertIn('This is file contains only data for testing.\n1 2 3 4',
                   output)
예제 #4
0
 def testJsFileLoadHtmlFile(self):
     file_path = self.GetTestFilePath('load_simple_html.js')
     output = d8_runner.ExecuteFile(file_path,
                                    source_paths=[self.test_data_dir])
     expected_output = ('File foo.html is loaded\n'
                        'x = 1\n'
                        "File foo.html's second script is loaded\n"
                        'x = 2\n'
                        'load_simple_html.js is loaded\n')
     self.assertEquals(output, expected_output)
예제 #5
0
 def testExecuteFileStdoutPiping(self):
     file_path = self.GetTestFilePath('simple.js')
     tmp_dir = tempfile.mkdtemp()
     try:
         temp_file_name = os.path.join(tmp_dir, 'out_file')
         with open(temp_file_name, 'w') as f:
             d8_runner.ExecuteFile(file_path, stdout=f)
         with open(temp_file_name, 'r') as f:
             self.assertEquals(f.read(), 'Hello W0rld from simple.js\n')
     finally:
         shutil.rmtree(tmp_dir)
예제 #6
0
    def testStackTraceOfErroWhenSyntaxErrorOccurs(self):
        file_path = self.GetTestFilePath('syntax_error.html')
        with self.assertRaises(RuntimeError) as context:
            d8_runner.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message

        self.assertIn(
            'syntax_error.html:23: SyntaxError: Unexpected identifier',
            exception_message)
예제 #7
0
    def testStackTraceOfErroWhenLoadingJS(self):
        file_path = self.GetTestFilePath('load_js_error.html')
        with self.assertRaises(RuntimeError) as context:
            d8_runner.ExecuteFile(file_path, source_paths=[self.test_data_dir])

        # Assert error stack trace contain src files' info.
        exception_message = context.exception.message

        self.assertIn('Error: /does_not_exist.js not found', exception_message)
        self.AssertHasNamedFrame('eval', 'load_js_error_2.html:20',
                                 exception_message)
        self.AssertHasNamedFrame('eval', 'load_js_error.html:22',
                                 exception_message)