     func testSeparators() {
         // Mistyped parentid.
         let invalidSeparator = JSON(["type": "separator", "arentid": "toolbar", "parentName": "Bookmarks Toolbar", "pos": 3])
-        XCTAssertNil(BookmarkType.payloadFromJSON(invalidSeparator))
+        let sep = BookmarkType.payloadFromJSON(invalidSeparator)
+        XCTAssertTrue(sep is SeparatorPayload)
+        XCTAssertFalse(sep!.isValid())
 
         // This one's right.
         let validSeparator = JSON(["id": "abcabcabcabc", "type": "separator", "parentid": "toolbar", "parentName": "Bookmarks Toolbar", "pos": 3])


        print(clientPayload, terminator: "\n")

        // Only payloads that parse as JSON are valid.
        XCTAssertNil(Record<CleartextPayloadJSON>.fromEnvelope(EnvelopeJSON(invalidPayload), payloadFactory: clearFactory))

        // Missing ID.
        XCTAssertNil(Record<CleartextPayloadJSON>.fromEnvelope(EnvelopeJSON(emptyPayload), payloadFactory: clearFactory))

        // Only valid ClientPayloads are valid.
        XCTAssertNil(Record<ClientPayload>.fromEnvelope(EnvelopeJSON(invalidPayload), payloadFactory: cleartextClientsFactory))
        XCTAssertNotNil(Record<ClientPayload>.fromEnvelope(EnvelopeJSON(clientPayload), payloadFactory: cleartextClientsFactory))
    }

    func testEncryptedClientRecord() {

        let m = (livemark as MirrorItemable).toMirrorItem(NSDate.now())
        XCTAssertEqual("http://fxfeeds.mozilla.com/en-US/firefox/headlines.xml", m.feedURI)
        XCTAssertEqual("http://www.bbc.co.uk/go/rss/int/news/-/news/", m.siteURI)
    }

    func testDeletedRecord() {
        let json = JSON([
            "id": "abcdefghijkl",
            "deleted": true,
            "type": "bookmark",
        ])

        guard let payload = BookmarkType.payloadFromJSON(json) else {
            XCTFail()
            return
        }

        XCTAssertFalse(payload is BookmarkPayload)    // Only BookmarkBasePayload.
        XCTAssertTrue(payload.isValid())
    }

    func testUnknownRecordType() {
        // It'll return a base payload that's invalid because its type is unknown.
        let json = JSON([
            "parentid": "mobile",
            "tags": [],
            "title": "Dispozitivul meu",
            "id": "pQSMHiA7fD0Z",
            "type": "something",
            "parentName": "mobile",
        ])

        XCTAssertNil(BookmarkType.payloadFromJSON(json))

        let payload = BookmarkType.somePayloadFromJSON(json)
        XCTAssertFalse(payload.isValid())        // Not valid because type is unknown.
    }

    func testInvalidRecordWithType() {
        // It should still return the right payload type, even if it's not valid.
        let json = JSON([
            "parentid": "mobile",
            "bmkUri": JSON.null,
            "tags": [],
            "title": "Dispozitivul meu",
            "id": "pQSMHiA7fD0Z",
            "type": "bookmark",
            "parentName": "mobile",
        ])

        guard let payload = BookmarkType.payloadFromJSON(json) else {
            XCTFail()
            return
        }

        XCTAssertFalse(payload.isValid())
        XCTAssertTrue(payload is BookmarkPayload)
    }

    func testLivemark() {
