summaryrefslogtreecommitdiff
path: root/rdf/tests
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commitad18d877ddd2a44d98fa12ccd3dbbcf4d0ac4299 (patch)
tree10027f336435511475e392454359edea8e25895d /rdf/tests
parent15477ed9af4859dacb069040b5d4de600803d3bc (diff)
downloaduxp-ad18d877ddd2a44d98fa12ccd3dbbcf4d0ac4299.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'rdf/tests')
-rw-r--r--rdf/tests/moz.build7
-rwxr-xr-xrdf/tests/unit/sample.rdf9
-rw-r--r--rdf/tests/unit/test_rdfredirect.js97
-rw-r--r--rdf/tests/unit/xpcshell.ini6
4 files changed, 119 insertions, 0 deletions
diff --git a/rdf/tests/moz.build b/rdf/tests/moz.build
new file mode 100644
index 0000000000..d8fb7519d5
--- /dev/null
+++ b/rdf/tests/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
diff --git a/rdf/tests/unit/sample.rdf b/rdf/tests/unit/sample.rdf
new file mode 100755
index 0000000000..42de8cd08b
--- /dev/null
+++ b/rdf/tests/unit/sample.rdf
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+
+ <rdf:Description about="urn:mozilla:sample-data"
+ dc:title="Sample" />
+
+</rdf:RDF>
diff --git a/rdf/tests/unit/test_rdfredirect.js b/rdf/tests/unit/test_rdfredirect.js
new file mode 100644
index 0000000000..40b01a49a1
--- /dev/null
+++ b/rdf/tests/unit/test_rdfredirect.js
@@ -0,0 +1,97 @@
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+var Cr = Components.results;
+
+Cu.import("resource://testing-common/httpd.js");
+
+function getRDFService()
+{
+ return Cc["@mozilla.org/rdf/rdf-service;1"].
+ getService(Ci.nsIRDFService);
+}
+
+var server1, server2;
+
+function run_test()
+{
+ var samplefile = do_get_file('sample.rdf');
+
+ server1 = new HttpServer();
+ server1.registerPathHandler("/sample-xs.rdf", xsRedirect);
+ server1.registerPathHandler("/sample-local.rdf", localRedirect);
+ server1.registerFile('/sample.rdf', samplefile);
+ server1.start(4444);
+
+ server2 = new HttpServer();
+ server2.registerFile('/sample.rdf', samplefile);
+ server2.start(4445);
+
+ do_test_pending();
+
+ new rdfLoadObserver('http://localhost:4444/sample.rdf', true);
+ new rdfLoadObserver('http://localhost:4445/sample.rdf', true);
+ new rdfLoadObserver('http://localhost:4444/sample-xs.rdf', false);
+ new rdfLoadObserver('http://localhost:4444/sample-local.rdf', true);
+}
+
+var gPending = 0;
+
+function rdfLoadObserver(uri, shouldPass)
+{
+ this.shouldPass = shouldPass;
+ this.uri = uri;
+
+ ++gPending;
+
+ var rdfService = getRDFService();
+ this.ds = rdfService.GetDataSource(uri).
+ QueryInterface(Ci.nsIRDFXMLSink);
+ this.ds.addXMLSinkObserver(this);
+}
+
+rdfLoadObserver.prototype =
+{
+ onBeginLoad : function() { },
+ onInterrupt : function() { },
+ onResume : function() { },
+ onEndLoad : function() {
+ print("Testing results of loading " + this.uri);
+
+ var rdfs = getRDFService();
+ var res = rdfs.GetResource("urn:mozilla:sample-data");
+ var arc = rdfs.GetResource("http://purl.org/dc/elements/1.1/title");
+ var answer = this.ds.GetTarget(res, arc, true);
+ if (answer !== null) {
+ do_check_true(this.shouldPass);
+ do_check_true(answer instanceof Ci.nsIRDFLiteral);
+ do_check_eq(answer.Value, "Sample");
+ }
+ else {
+ do_check_false(this.shouldPass);
+ }
+
+ gPending -= 1;
+
+ this.ds.removeXMLSinkObserver(this);
+
+ if (gPending == 0) {
+ do_test_pending();
+ server1.stop(do_test_finished);
+ server2.stop(do_test_finished);
+ }
+ },
+ onError : function() { }
+}
+
+function xsRedirect(metadata, response)
+{
+ response.setStatusLine(metadata.httpVersion, 301, "Moved Permanently");
+ response.setHeader("Location", "http://localhost:4445/sample.rdf", false);
+}
+
+function localRedirect(metadata, response)
+{
+ response.setStatusLine(metadata.httpVersion, 301, "Moved Permanently");
+ response.setHeader("Location", "http://localhost:4444/sample.rdf", false);
+}
diff --git a/rdf/tests/unit/xpcshell.ini b/rdf/tests/unit/xpcshell.ini
new file mode 100644
index 0000000000..99ab823953
--- /dev/null
+++ b/rdf/tests/unit/xpcshell.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+head =
+tail =
+support-files = sample.rdf
+
+[test_rdfredirect.js]