* attempt to insert the target id at a given insertion point. That insertion
* should cause a SecurityException. If so, the test passes. Otherwise, the test
* will fail
*/
public TestReport runImpl() throws Exception{
DefaultTestReport report
= new DefaultTestReport(this);
//
// First step:
//
// Load the input SVG into a Document object
//
String parserClassName = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parserClassName);
Document doc = null;
try {
doc = f.createDocument(svgURL);
} catch(IOException e){
report.setErrorCode(ERROR_CANNOT_LOAD_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
e.getMessage());
report.setPassed(false);
return report;
} catch(Exception e){
report.setErrorCode(ERROR_CANNOT_LOAD_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
e.getMessage());
report.setPassed(false);
return report;
}
Vector failures = new Vector();
//
// Do an initial processing to validate that the external
// stylesheet causes a SecurityException
//
MyUserAgent userAgent = buildUserAgent();
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
ctx.setDynamic(true);
// We expect either a SecurityException or a BridgeException
// with ERR_URI_UNSECURE.
Throwable th = null;
try {
GraphicsNode gn = builder.build(ctx, doc);
gn.getBounds();
th = userAgent.getDisplayError();
} catch (BridgeException e){
th = e;
} catch (SecurityException e) {
th = e;
} catch (Throwable t) {
th = t;
}
if (th == null) {
if (secure)
failures.addElement(EXTERNAL_STYLESHEET_ID);
} else if (th instanceof SecurityException) {
if (!secure)
failures.addElement(EXTERNAL_STYLESHEET_ID);
} else if (th instanceof BridgeException) {
BridgeException be = (BridgeException)th;
if (!secure ||
(secure && !ERR_URI_UNSECURE.equals(be.getCode()))) {
report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
be.getMessage());
report.setPassed(false);
return report;
}
}
//
// Remove the stylesheet from the document
//
Node child = doc.getFirstChild();
Node next = null;
while (child != null) {
next = child.getNextSibling();
if (child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
doc.removeChild(child);
}
child = next;
}
//
// Now, get the list of ids to be checked
//
Element root = doc.getDocumentElement();
String idList = root.getAttributeNS(testNS, "targetids");
if (idList == null || "".equals(idList)) {
report.setErrorCode(ERROR_NO_ID_LIST);
report.setPassed(false);
return report;
}
StringTokenizer st = new StringTokenizer(idList, ",");
String[] ids = new String[st.countTokens()];
for (int i=0; i<ids.length; i++) {
ids[i] = st.nextToken().toString().trim();
}
for (int i=0; i<ids.length; i++) {
String id = ids[i];
userAgent = buildUserAgent();
builder = new GVTBuilder();
ctx = new BridgeContext(userAgent);
ctx.setDynamic(true);
Document cloneDoc = (Document)doc.cloneNode(true);
Element insertionPoint = cloneDoc.getElementById(INSERTION_POINT_ID);
if (insertionPoint == null) {
report.setErrorCode(ERROR_NO_INSERTION_POINT_IN_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_INSERTION_POINT_ID,
INSERTION_POINT_ID);
report.setPassed(false);
return report;
}
Element target = cloneDoc.getElementById(id);
if (target == null) {
report.setErrorCode(ERROR_TARGET_ID_NOT_FOUND);
report.addDescriptionEntry(ENTRY_KEY_TARGET_ID,
id);
report.setPassed(false);
return report;
}
insertionPoint.appendChild(target);
th = null;
try {
GraphicsNode gn = builder.build(ctx, cloneDoc);
gn.getBounds();
th = userAgent.getDisplayError();
} catch (BridgeException e){
th = e;
} catch (SecurityException e) {
th = e;
} catch (Throwable t) {
th = t;
}
if (th == null) {
if (secure)
failures.addElement(id);
} else if (th instanceof SecurityException) {
if (!secure)
failures.addElement(id);
} else if (th instanceof BridgeException) {
BridgeException be = (BridgeException)th;
if (!secure ||
(secure && !ERR_URI_UNSECURE.equals(be.getCode()))) {
report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
be.getMessage());
report.setPassed(false);
return report;
}
} else {
// Some unknown exception was displayed...
report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
th.getMessage());
report.setPassed(false);
return report;
}
}
if (failures.size() == 0) {
return reportSuccess();
}
if (secure) {
report.setErrorCode(ERROR_UNTHROWN_SECURITY_EXCEPTIONS);
for (int i=0; i<failures.size(); i++) {
report.addDescriptionEntry(ENTRY_KEY_EXPECTED_EXCEPTION_ON,
failures.elementAt(i));
}
} else {
report.setErrorCode(ERROR_THROWN_SECURITY_EXCEPTIONS);
for (int i=0; i<failures.size(); i++) {
report.addDescriptionEntry(ENTRY_KEY_UNEXPECTED_EXCEPTION_ON,
failures.elementAt(i));
}
}
report.setPassed(false);
return report;
}