1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #831 from kkujala/dev

Make unit tests runnable from command line.
This commit is contained in:
Artur Adib 2012-01-11 08:21:57 -08:00
commit ec030c06c4
12 changed files with 583 additions and 829 deletions

116
test/unit/Makefile Normal file
View file

@ -0,0 +1,116 @@
# Create temporary profile directory name.
TEMP_PROFILE:=$(shell echo `pwd`)/test_reports/temp_profile
# These are the Firefox command line arguments.
FIREFOX_ARGS:=-no-remote -profile $(TEMP_PROFILE)
# These are the Chrome command line arguments.
CHROME_ARGS:=--user-data-dir=$(TEMP_PROFILE) --no-first-run --disable-sync
# Unit test uses the manifest from ref test to determine which browsers will
# be used for running the unit tests.
MANIFEST:=../resources/browser_manifests/browser_manifest.json
# This is a helper command to separate multiple browsers to their own lines
# for an easier sed operation.
SPLIT_LINES:=sed 's|,|,@|g' | tr '@' '\n'
# This is a helper command to join multiple lines together.
JOIN_LINES:=tr -d '\n'
# Fetch the paths to browsers that are going to be used in testing.
# For OS X the path to the binary needs to be added.
# Add the browser arguments for each browser.
# Create random profile directory for each browser.
BROWSERS_PATHS:=$(shell echo `\
sed -n 's|.*"path":\(.*\)|\1,|p' $(MANIFEST) | \
$(JOIN_LINES) \
`)
# The browser_manifest.json file has only the app directory for mac browsers.
# The absolute path to the browser binary needs to be used.
BROWSERS_PATHS_WITH_MAC_CORRECTION:=$(shell echo '$(BROWSERS_PATHS)' | \
$(SPLIT_LINES) | \
sed 's|\(Aurora\.app\)|\1/Contents/MacOS/firefox-bin|' | \
sed 's|\(Firefox.*\.app\)|\1/Contents/MacOS/firefox-bin|' | \
sed 's|\(Google Chrome\.app\)|\1/Contents/MacOS/Google Chrome|' | \
$(JOIN_LINES) \
)
# Replace " with @@@@ so that echoing do not destroy the quotation marks.
QUOTATION_MARK:=\"
SUBSTITUTE_FOR_QUOTATION_MARK:=@@@@
# Each of the browser can have their own separate arguments.
BROWSERS_WITH_ARGUMENTS:=$(shell echo '$(BROWSERS_PATHS_WITH_MAC_CORRECTION)' | \
$(SPLIT_LINES) | \
sed "s|\(irefox.*\)\($(QUOTATION_MARK)\),|\1;$(FIREFOX_ARGS)\2,|" | \
sed "s|\(hrome.*\)\($(QUOTATION_MARK)\),|\1;$(CHROME_ARGS)\2,|" | \
$(JOIN_LINES) \
)
# A temporary profile directory is needed for each of the browser. In this way
# a unit test run will not disturb the main browsing session of the user. The
# $RANDOM shell variable is used to generate non-conflicting temporary
# directories.
BROWSERS_WITH_UKNOWN_RANDOM_PROFILE_PATHS:=$(shell echo '$(BROWSERS_WITH_ARGUMENTS)' | \
$(SPLIT_LINES) | \
sed 's|\(temp_profile\)|\1_$$RANDOM$$RANDOM|' | \
sed "s|$(QUOTATION_MARK)|$(SUBSTITUTE_FOR_QUOTATION_MARK)|g" | \
$(JOIN_LINES) \
)
# Echo the variable so that the unknown random directories become known.
# Replace @@@@ with " so that jsTestDriver will work properly.
BROWSERS:=$(shell echo "$(BROWSERS_WITH_UKNOWN_RANDOM_PROFILE_PATHS)" | \
sed "s|$(SUBSTITUTE_FOR_QUOTATION_MARK)|$(QUOTATION_MARK)|g" \
)
# Get the known random directories for browsers. This information will be used
# to create the profile directories beforehand. Create also the dummy temp
# profile directory so that the mkdir command would not fail for browsers that
# do not need it.
PROFILES:=$(TEMP_PROFILE) $(shell echo '$(BROWSERS)' | \
$(SPLIT_LINES) | \
sed -n "s|.*\( $(TEMP_PROFILE)_[0-9]\+\).*|\1|p" | \
$(JOIN_LINES) \
)
# This is the command to invoke the unit test.
PROG:=java \
-Xms512m \
-Xmx1024m \
-jar ../../external/jsTestDriver/JsTestDriver-1.3.3d.jar \
--config ./jsTestDriver.conf \
--reset \
--port 4224 \
--browser $(BROWSERS) \
--tests all \
--testOutput ./test_reports/
# This default rule runs the unit tests with the constructed command.
test:
@mkdir -p $(PROFILES)
$(PROG)
@rm -rf $(PROFILES)
# In case this Makefile needs to be debugged then this rule will provide all
# the information from intermediate steps.
debug:
@echo 'Debug browsers paths: $(BROWSERS_PATHS)'
@echo
@echo 'Debug browsers paths with mac correction: $(BROWSERS_PATHS_WITH_MAC_CORRECTION)'
@echo
@echo 'Debug browsers with arguments: $(BROWSERS_WITH_ARGUMENTS)'
@echo
@echo 'Debug browsers random profile paths: $(BROWSERS_WITH_UKNOWN_RANDOM_PROFILE_PATHS)'
@echo
@echo 'Debug browsers: $(BROWSERS)'
@echo
@echo 'Debug profiles: $(PROFILES)'
@echo
@echo 'Command to be run: $(PROG)'
@echo
.phony:: test

View file

@ -0,0 +1,30 @@
server: http://localhost:4224
load:
- ../../external/jasmine/jasmine.js
- ../../external/jasmineAdapter/JasmineAdapter.js
- ../../src/obj.js
- ../../src/core.js
- ../../src/util.js
- ../../src/canvas.js
- ../../src/obj.js
- ../../src/function.js
- ../../src/charsets.js
- ../../src/cidmaps.js
- ../../src/colorspace.js
- ../../src/crypto.js
- ../../src/evaluator.js
- ../../src/fonts.js
- ../../src/glyphlist.js
- ../../src/image.js
- ../../src/metrics.js
- ../../src/parser.js
- ../../src/pattern.js
- ../../src/stream.js
- ../../src/worker.js
- ../../external/jpgjs/jpg.js
- ../unit/obj_spec.js
- ../unit/function_spec.js
- ../unit/crypto_spec.js
- ../unit/stream_spec.js

3
test/unit/test_reports/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
TEST*
temp*

View file

@ -1,72 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>pdf.js unit test</title>
<link rel="shortcut icon" type="image/png" href="../../external/jasmine/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="../../external/jasmine/jasmine.css">
<script type="text/javascript" src="../../external/jasmine/jasmine.js"></script>
<script type="text/javascript" src="../../external/jasmine/jasmine-html.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="obj_spec.js"></script>
<script type="text/javascript" src="function_spec.js"></script>
<script type="text/javascript" src="crypto_spec.js"></script>
<script type="text/javascript" src="stream_spec.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="../../src/core.js"></script>
<script type="text/javascript" src="../../src/util.js"></script>
<script type="text/javascript" src="../../src/canvas.js"></script>
<script type="text/javascript" src="../../src/obj.js"></script>
<script type="text/javascript" src="../../src/function.js"></script>
<script type="text/javascript" src="../../src/charsets.js"></script>
<script type="text/javascript" src="../../src/cidmaps.js"></script>
<script type="text/javascript" src="../../src/colorspace.js"></script>
<script type="text/javascript" src="../../src/crypto.js"></script>
<script type="text/javascript" src="../../src/evaluator.js"></script>
<script type="text/javascript" src="../../src/fonts.js"></script>
<script type="text/javascript" src="../../src/glyphlist.js"></script>
<script type="text/javascript" src="../../src/image.js"></script>
<script type="text/javascript" src="../../src/metrics.js"></script>
<script type="text/javascript" src="../../src/parser.js"></script>
<script type="text/javascript" src="../../src/pattern.js"></script>
<script type="text/javascript" src="../../src/stream.js"></script>
<script type="text/javascript" src="../../src/worker.js"></script>
<script type="text/javascript" src="../../external/jpgjs/jpg.js"></script>
<script type="text/javascript">
'use strict';
(function pdfJsUnitTest() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function pdfJsUnitTestSpecFilter(spec) {
return trivialReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function pdfJsUnitTestOnload() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>