30 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
31 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
32 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
36 var builder =
Cc[
"@songbirdnest.com/Songbird/Library/ConstraintBuilder;1"]
37 .createInstance(
Ci.sbILibraryConstraintBuilder);
39 builder.includeConstraint(
LibraryUtils.standardFilterConstraint);
41 "constraint builder failed to include standard constraint");
43 builder.includeConstraint(
LibraryUtils.standardFilterConstraint);
45 builder.include(SBProperties.contentType,
"audio");
46 constraint = builder.get();
47 builder.parseFromString(
String(constraint));
49 "constraint builder failed to correctly unserialize");
51 builder.includeConstraint(
LibraryUtils.standardFilterConstraint);
53 builder.include(SBProperties.genre,
"\u6E2C \u8A66");
54 constraint = builder.get();
55 builder.parseFromString(
String(constraint));
57 "constraint builder failed to correctly unserialize non-ASCII");
60 builder.includeConstraint(
LibraryUtils.standardFilterConstraint);
62 builder.include(SBProperties.contentType,
"audio");
64 builder.includeList(SBProperties.trackName,
65 ArrayConverter.stringEnumerator([
"alpha",
"beta"]));
66 constraint = builder.get();
68 expected[SBProperties.isList] = [
"0"];
69 expected[SBProperties.hidden] = [
"0"];
70 expected[SBProperties.contentType] = [
"audio"];
71 expected[SBProperties.trackName] = [
"alpha",
"beta"];
72 for (let
group in ArrayConverter.JSEnum(constraint.groups)) {
73 group.QueryInterface(
Ci.sbILibraryConstraintGroup);
74 let props = ArrayConverter.JSArray(
group.properties);
75 assertEqual(1, props.length,
"unexpected property count");
76 assertTrue(props[0] in expected,
"unknown property " + props[0]);
77 let values = ArrayConverter.JSArray(
group.getValues(props[0]));
79 delete expected[props[0]];
81 for (let prop in expected) {
82 doFail(
"unexpected remaining property " + prop);
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function assertArraysEqual(a1, a2)
function runTest()
Advanced DataRemote unit tests.
Javascript wrappers for common library tasks.