summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-12 18:49:02 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-12 18:49:02 +0000
commit88dbd543bd0efe6acac20438037616e66b35e47b (patch)
treee5ea722802e9d276a259127708417834edd68ac8
parent96b124c8143753b0103f93029a1bfe8cc9d5ca36 (diff)
downloadpdfium-88dbd543bd0efe6acac20438037616e66b35e47b.tar.xz
Add test for CJS_Color properties.
Return a more precise error in one case. Change-Id: I21e4ef6b30be5f44d35922640643bffb9cb4b5e4 Reviewed-on: https://pdfium-review.googlesource.com/c/43950 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--fxjs/cjs_color.cpp5
-rw-r--r--testing/resources/javascript/color_props.in76
-rw-r--r--testing/resources/javascript/color_props_expected.txt85
3 files changed, 165 insertions, 1 deletions
diff --git a/fxjs/cjs_color.cpp b/fxjs/cjs_color.cpp
index bba4513b67..06c61f87d4 100644
--- a/fxjs/cjs_color.cpp
+++ b/fxjs/cjs_color.cpp
@@ -258,9 +258,12 @@ CJS_Result CJS_Color::GetPropertyHelper(CJS_Runtime* pRuntime, CFX_Color* var) {
CJS_Result CJS_Color::SetPropertyHelper(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp,
CFX_Color* var) {
- if (vp.IsEmpty() || !vp->IsArray())
+ if (vp.IsEmpty())
return CJS_Result::Failure(JSMessage::kParamError);
+ if (!vp->IsArray())
+ return CJS_Result::Failure(JSMessage::kTypeError);
+
*var = ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(vp));
return CJS_Result::Success();
}
diff --git a/testing/resources/javascript/color_props.in b/testing/resources/javascript/color_props.in
new file mode 100644
index 0000000000..7d0965697d
--- /dev/null
+++ b/testing/resources/javascript/color_props.in
@@ -0,0 +1,76 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /OpenAction 10 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 1
+ /Kids [
+ 3 0 R
+ ]
+>>
+endobj
+% Page number 0.
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Contents [21 0 R]
+ /MediaBox [0 0 612 792]
+>>
+% OpenAction action
+{{object 10 0}} <<
+ /Type /Action
+ /S /JavaScript
+ /JS 11 0 R
+>>
+endobj
+% JS program to exexute
+{{object 11 0}} <<
+ {{streamlen}}
+>>
+stream
+var colorNames = [
+ "transparent", "black", "white", "red", "green", "blue", "cyan",
+ "magenta", "yellow", "dkGray", "gray", "ltGray"
+];
+var newValues = [
+ ["T"], ["G", 20], ["RGB", 10, 20, 30], ["CMYK", 10, 20, 30, 40], ["BOGUS", 4]
+];
+try {
+ var x, y, c, v;
+ app.alert("Original values");
+ for (x = 0; x < colorNames.length; ++x) {
+ c = colorNames[x];
+ app.alert(c + ": " + color[c]);
+ }
+ for (y = 0; y < newValues.length; ++y) {
+ v = newValues[y];
+ app.alert("Setting to " + v);
+ for (x = 0; x < colorNames.length; ++x) {
+ c = colorNames[x];
+ color[c] = v;
+ }
+ app.alert("Updated values");
+ for (x = 0; x < colorNames.length; ++x) {
+ c = colorNames[x];
+ app.alert(c + ": " + color[c]);
+ }
+ }
+} catch (e) {
+ app.alert("FAILURE" + e);
+}
+try {
+ app.alert("Testing wrong parameter type");
+ color.red = 42;
+} catch (e) {
+ app.alert("SUCCESS: " + e);
+}
+endstream
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/color_props_expected.txt b/testing/resources/javascript/color_props_expected.txt
new file mode 100644
index 0000000000..98e9e4502e
--- /dev/null
+++ b/testing/resources/javascript/color_props_expected.txt
@@ -0,0 +1,85 @@
+Alert: Original values
+Alert: transparent: T
+Alert: black: G,0
+Alert: white: G,1
+Alert: red: RGB,1,0,0
+Alert: green: RGB,0,1,0
+Alert: blue: RGB,0,0,1
+Alert: cyan: CMYK,1,0,0,0
+Alert: magenta: CMYK,0,1,0,0
+Alert: yellow: CMYK,0,0,1,0
+Alert: dkGray: G,0.25
+Alert: gray: G,0.5
+Alert: ltGray: G,0.75
+Alert: Setting to T
+Alert: Updated values
+Alert: transparent: T
+Alert: black: T
+Alert: white: T
+Alert: red: T
+Alert: green: T
+Alert: blue: T
+Alert: cyan: T
+Alert: magenta: T
+Alert: yellow: T
+Alert: dkGray: T
+Alert: gray: T
+Alert: ltGray: T
+Alert: Setting to G,20
+Alert: Updated values
+Alert: transparent: G,20
+Alert: black: G,20
+Alert: white: G,20
+Alert: red: G,20
+Alert: green: G,20
+Alert: blue: G,20
+Alert: cyan: G,20
+Alert: magenta: G,20
+Alert: yellow: G,20
+Alert: dkGray: G,20
+Alert: gray: G,20
+Alert: ltGray: G,20
+Alert: Setting to RGB,10,20,30
+Alert: Updated values
+Alert: transparent: RGB,10,20,30
+Alert: black: RGB,10,20,30
+Alert: white: RGB,10,20,30
+Alert: red: RGB,10,20,30
+Alert: green: RGB,10,20,30
+Alert: blue: RGB,10,20,30
+Alert: cyan: RGB,10,20,30
+Alert: magenta: RGB,10,20,30
+Alert: yellow: RGB,10,20,30
+Alert: dkGray: RGB,10,20,30
+Alert: gray: RGB,10,20,30
+Alert: ltGray: RGB,10,20,30
+Alert: Setting to CMYK,10,20,30,40
+Alert: Updated values
+Alert: transparent: CMYK,10,20,30,40
+Alert: black: CMYK,10,20,30,40
+Alert: white: CMYK,10,20,30,40
+Alert: red: CMYK,10,20,30,40
+Alert: green: CMYK,10,20,30,40
+Alert: blue: CMYK,10,20,30,40
+Alert: cyan: CMYK,10,20,30,40
+Alert: magenta: CMYK,10,20,30,40
+Alert: yellow: CMYK,10,20,30,40
+Alert: dkGray: CMYK,10,20,30,40
+Alert: gray: CMYK,10,20,30,40
+Alert: ltGray: CMYK,10,20,30,40
+Alert: Setting to BOGUS,4
+Alert: Updated values
+Alert: transparent: T
+Alert: black: T
+Alert: white: T
+Alert: red: T
+Alert: green: T
+Alert: blue: T
+Alert: cyan: T
+Alert: magenta: T
+Alert: yellow: T
+Alert: dkGray: T
+Alert: gray: T
+Alert: ltGray: T
+Alert: Testing wrong parameter type
+Alert: SUCCESS: color.red: Incorrect parameter type.