void tst_IdentityInterface::expectedUsage()
{
    // we expect Identity to be used in QML as a creatable type.
    // eg:
    // Item {
    //     Identity {
    //         id: ident
    //         userName: "******"
    //         secret: "secret"
    //         caption: "caption"
    //         onStatusChanged: {
    //             if (status == Identity.Synced) {
    //                 console.log("successfully created identity with id: " + identifier)
    //             }
    //         }
    //     }
    //
    //     Component.onCompleted: ident.sync() // usually triggered by button press/etc
    // }

    // new identity creation
    QScopedPointer<IdentityInterface> newIdentity(new IdentityInterface);
    newIdentity->classBegin();
    newIdentity->setUserName("test-username");
    newIdentity->setSecret("test-secret");
    newIdentity->setCaption("test-caption");
    newIdentity->componentComplete();
    QTRY_COMPARE(newIdentity->status(), IdentityInterface::Modified);
    newIdentity->sync();
    QTRY_COMPARE(newIdentity->status(), IdentityInterface::Synced);
    //QCOMPARE(newIdentity->userName(), QString(QLatin1String("test-username")));//can't read back after sync.
    //QCOMPARE(newIdentity->secret(), QString(QLatin1String("test-secret")));//can't read back after sync.
    QCOMPARE(newIdentity->caption(), QString(QLatin1String("test-caption")));
    QVERIFY(newIdentity->identifier() > 0); // saved; valid id.

    // existing identity creation
    QScopedPointer<IdentityInterface> existingIdentity(new IdentityInterface);
    existingIdentity->classBegin();
    existingIdentity->setIdentifier(newIdentity->identifier());
    existingIdentity->setCaption("test-caption-modified");
    existingIdentity->componentComplete();
    QTRY_COMPARE(existingIdentity->status(), IdentityInterface::Modified);
    existingIdentity->sync();
    QTRY_COMPARE(existingIdentity->status(), IdentityInterface::Synced);
    QCOMPARE(existingIdentity->caption(), QString(QLatin1String("test-caption-modified")));

    // sadly, newIdentity->caption() won't automatically update.  It needs refresh.
    QCOMPARE(newIdentity->caption(), QString(QLatin1String("test-caption")));
    newIdentity->refresh();
    QTRY_COMPARE(newIdentity->status(), IdentityInterface::Synced);
    QCOMPARE(newIdentity->caption(), QString(QLatin1String("test-caption-modified")));

    // clean up.
    newIdentity->remove();
    existingIdentity->remove(); // may cause issues.  We don't get the signal from the backend :-/
}
示例#2
0
JSObject *
TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target)
{
    RootedObject oldWaiver(cx, WrapperFactory::GetXrayWaiver(origobj));
    RootedObject newIdentity(cx, JS_TransplantObject(cx, origobj, target));
    if (!newIdentity || !oldWaiver)
       return newIdentity;

    if (!FixWaiverAfterTransplant(cx, oldWaiver, newIdentity))
        return nullptr;
    return newIdentity;
}
示例#3
0
    TorInstanceImpl(const TorSettings* settings):
      settings_(settings),
      locationFinder_(settings_),
      control_(settings_)
    {
        connect(&launcher_, SIGNAL(started()), SLOT(onStarted()));
        connect(&control_, SIGNAL(connected()), SLOT(onConnected()));
        connect(&control_, SIGNAL(newIdentity()), SLOT(onNewIdentity()));
        connect(&locationFinder_,
                SIGNAL(locationFound(QString,QString,QString,QPixmap)),
                SLOT(onLocationFound(QString,QString,QString,QPixmap)));

        control_.connectToTor();
    }
示例#4
0
JSObject *
TransplantObjectWithWrapper(JSContext *cx,
                            JSObject *origobj, JSObject *origwrapper,
                            JSObject *targetobj, JSObject *targetwrapper)
{
    RootedObject oldWaiver(cx, WrapperFactory::GetXrayWaiver(origobj));
    RootedObject newSameCompartmentWrapper(cx,
      js_TransplantObjectWithWrapper(cx, origobj, origwrapper, targetobj,
                                     targetwrapper));
    if (!newSameCompartmentWrapper || !oldWaiver)
        return newSameCompartmentWrapper;

    RootedObject newIdentity(cx, Wrapper::wrappedObject(newSameCompartmentWrapper));
    MOZ_ASSERT(js::IsWrapper(newIdentity));
    if (!FixWaiverAfterTransplant(cx, oldWaiver, newIdentity))
        return NULL;
    return newSameCompartmentWrapper;
}