Exemplo n.º 1
0
 def test_handlerWithArgsQuoting(self):
     self.assertEquals(
         self.flt(livepage.handler(argsHandler, '"')),
         livepage.ctsTemplate % (fakeId, ",'"'", livepage.handledEventPostlude))
     self.assertEquals(
         self.flt(livepage.handler(argsHandler, '&')),
         livepage.ctsTemplate % (fakeId, ",'&'", livepage.handledEventPostlude))
Exemplo n.º 2
0
    def test_handlerWithArgs(self):
        options = [
            dict(bubble=True, outsideAttribute=True),
            dict(bubble=False, outsideAttribute=True),
            dict(bubble=False, outsideAttribute=False),
            dict(bubble=True, outsideAttribute=False)]

        for opts in options:
            if opts['bubble']:
                postlude = ';'
            else:
                postlude = livepage.handledEventPostlude

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, 'hello', **opts)),
                livepage.ctsTemplate % (fakeId, ",'hello'", postlude))

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "'", **opts)),
                livepage.ctsTemplate % (fakeId, ",'\\''", postlude))

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "\\", **opts)),
                livepage.ctsTemplate % (fakeId, ",'\\\\'", postlude))

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "\n", **opts)),
                livepage.ctsTemplate % (fakeId, ",'\\n'", postlude))
Exemplo n.º 3
0
    def test_handlerWithArgs(self):
        options = [
            dict(bubble=True, outsideAttribute=True),
            dict(bubble=False, outsideAttribute=True),
            dict(bubble=False, outsideAttribute=False),
            dict(bubble=True, outsideAttribute=False),
        ]

        for opts in options:
            if opts["bubble"]:
                postlude = ""
            else:
                postlude = livepage.handledEventPostlude

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "hello", **opts)),
                livepage.ctsTemplate % (fakeId, ",'hello'", postlude),
            )

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "'", **opts)),
                livepage.ctsTemplate % (fakeId, ",'\\''", postlude),
            )

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "\\", **opts)),
                livepage.ctsTemplate % (fakeId, ",'\\\\'", postlude),
            )

            self.assertEquals(
                self.flt(livepage.handler(argsHandler, "\n", **opts)),
                livepage.ctsTemplate % (fakeId, ",'\\n'", postlude),
            )
Exemplo n.º 4
0
 def test_outsideAttributeArgsQuoting(self):
     self.assertEquals(
        self.flt( livepage.handler(argsHandler, '"', outsideAttribute=True)),
         livepage.ctsTemplate % (fakeId, ",'\"'", livepage.handledEventPostlude))
     self.assertEquals(
         self.flt(livepage.handler(argsHandler, '&', outsideAttribute=True)),
         livepage.ctsTemplate % (fakeId, ",'&'", livepage.handledEventPostlude))
Exemplo n.º 5
0
    def test_handlerWithArgsQuoting(self):
        self.assertEquals(
            self.flt(livepage.handler(argsHandler, '"')),
            livepage.ctsTemplate % (fakeId, ",'"'", livepage.handledEventPostlude))

        self.assertEquals(
            self.flt(livepage.handler(argsHandler, '&')),
            livepage.ctsTemplate % (fakeId, ",'&'", livepage.handledEventPostlude))
Exemplo n.º 6
0
    def test_outsideAttributeArgsQuoting(self):
        self.assertEquals(
           self.flt(livepage.handler(argsHandler, '"', outsideAttribute=True)),
            livepage.ctsTemplate % (fakeId, ",'\"'", livepage.handledEventPostlude))

        self.assertEquals(
            self.flt(livepage.handler(argsHandler, '&', outsideAttribute=True)),
            livepage.ctsTemplate % (fakeId, ",'&'", livepage.handledEventPostlude))
Exemplo n.º 7
0
 def goingLive(self, ctx, client):
     """Called each time the page is served/refreshed"""
     inevow.IRequest(ctx).setHeader('content-type', 'application/vnd.mozilla.xul+xml')
     hndlr = handler(self.fillInField, identifier='fillInField')
     hndlr(ctx, client) # Stores it
     hndlr = handler(self.recieveFieldData, identifier='recieveFieldData')
     hndlr(ctx, client) # Stores it
     hndlr = handler(self.translate, identifier='translate')
     hndlr(ctx, client) # Stores it
Exemplo n.º 8
0
 def test_handlerWithIdentifier(self):
     gatherer = LiveGatherer()
     ctx = context.WovenContext()
     ctx.remember(gatherer, livepage.IClientHandle)
     oneQual = util.qual(oneHandler)
     twoQual = util.qual(twoHandler)
     livepage.handler(oneHandler, identifier='same')(ctx, None)
     livepage.handler(twoHandler, identifier='same')(ctx, None)
     gatherer.handleInput('same')
     self.assertEquals(gatherer.heard, ['one', 'two'])
Exemplo n.º 9
0
    def test_handlerWithIdentifier(self):
        lp = self.livepage
        gatherer = self.livepage = LiveGatherer()

        self.flt(livepage.handler(oneHandler, identifier='same'))
        gatherer.handleInput('--handler-same')
        self.assertEquals(gatherer.heard, ['one'])

        self.flt(livepage.handler(twoHandler, identifier='same'))
        gatherer.handleInput('--handler-same')
        self.assertEquals(gatherer.heard, ['one', 'two'])

        self.livepage = lp
Exemplo n.º 10
0
    def goingLive(self, ctx, client):
        """Called each time the page is served/refreshed"""
        inevow.IRequest(ctx).setHeader('content-type',
                                       'application/vnd.mozilla.xul+xml')

        hndlr = handler(self.fillInField, identifier='fillInField')
        hndlr(ctx, client)  # Stores it

        hndlr = handler(self.recieveFieldData, identifier='recieveFieldData')
        hndlr(ctx, client)  # Stores it

        hndlr = handler(self.translate, identifier='translate')
        hndlr(ctx, client)  # Stores it
Exemplo n.º 11
0
    def test_handlerWithIdentifier(self):
        gatherer = LiveGatherer()
        ctx = context.WovenContext()
        ctx.remember(gatherer, livepage.IClientHandle)

        oneQual = util.qual(oneHandler)
        twoQual = util.qual(twoHandler)

        ## Subscribe both handlers to the same identifier
        livepage.handler(oneHandler, identifier='same')(ctx, None)
        livepage.handler(twoHandler, identifier='same')(ctx, None)

        gatherer.handleInput('same')

        self.assertEquals(gatherer.heard, ['one', 'two'])
Exemplo n.º 12
0
    def test_handlerWithIdentifier(self):
        gatherer = LiveGatherer()
        ctx = context.WovenContext()
        ctx.remember(gatherer, livepage.IClientHandle)

        oneQual = util.qual(oneHandler)
        twoQual = util.qual(twoHandler)

        ## Subscribe both handlers to the same identifier
        livepage.handler(oneHandler, identifier="same")(ctx, None)
        livepage.handler(twoHandler, identifier="same")(ctx, None)

        gatherer.handleInput("same")

        self.assertEquals(gatherer.heard, ["one", "two"])
Exemplo n.º 13
0
 def test_handler(self):
     result = livepage.handler(onClick)
     self.assertEquals(
         self.flt(result),
         livepage.ctsTemplate % (fakeId, '', livepage.handledEventPostlude))
     self.livepage.handleInput(fakeId)
     self.assertEquals(self.livepage.sent, 'null;')
 def render_renNode(self, ctx, data):
     """Fills in the oncommand handler for the 
     rename node button and short cut key"""
     return ctx.tag(oncommand=handler(self.outlinePane.handleRenNode,
                                      js('currentOutlineId()'),
                                      js('askNodeName()'),
                                      bubble=True))
Exemplo n.º 15
0
def callMe(client):
    d = defer.Deferred()
    def callMePlease(client):
        d.callback('success')
    client.sendScript(client.flt(
        livepage.handler(callMePlease, bubble=True), quote=False))
    return d
Exemplo n.º 16
0
 def action_submit(self, action, target, parameter):
     def observeSubmission(client):
         self.passed()
     return self.action_post(action, target, parameter, self._handle.flt([
         "function() {",
             livepage.handler(observeSubmission),
         "}"], quote=False))
Exemplo n.º 17
0
 def setUpHandler(func, name, *args, **kwargs):
     """
     Convience function link funcs to hander ids
     and store them
     """
     kwargs['identifier'] = name
     hndlr = handler(func, *args, **kwargs)
     hndlr(ctx, client) # Stores it
Exemplo n.º 18
0
 def render_renNode(self, ctx, data):
     """Fills in the oncommand handler for the 
     rename node button and short cut key"""
     return ctx.tag(
         oncommand=handler(
             self.outlinePane.handleRenNode, js("currentOutlineId()"), js("askNodeName()"), bubble=True
         )
     )
 def setUpHandler(func, name, *args, **kwargs):
     """
     Convience function link funcs to hander ids
     and store them
     """
     kwargs['identifier'] = name
     hndlr = handler(func, *args, **kwargs)
     hndlr(ctx, client)  # Stores it
Exemplo n.º 20
0
 def test_closedOverHandler(self):
     closedOver = 'hello'
     def closuredHandler(client):
         client.sendScript(closedOver)
     result = livepage.handler(closuredHandler)(self.ctx, None)
     self.assertEquals(result.content,
         livepage.ctsTemplate % (fakeId, '', livepage.handledEventPostlude))
     self.livepage.handleInput(fakeId)
     self.assertEquals(self.livepage.sent, 'hello')
Exemplo n.º 21
0
 def action_assert(self, action, target, parameter):
     def observeNodeContents(client, contents):
         if contents == parameter:
             self.passed()
         else:
             self.failed()
     return [livepage.handler(
         observeNodeContents,
         contentDocument.getElementById(target).innerHTML, bubble=True)]
Exemplo n.º 22
0
def callMe(client):
    d = defer.Deferred()

    def callMePlease(client):
        d.callback('success')

    client.sendScript(
        client.flt(livepage.handler(callMePlease, bubble=True), quote=False))
    return d
Exemplo n.º 23
0
    def action_click(self, action, target, parameter):
        def observeClicking(client):
            self.passed()

        return [
            "var theClickObservation = function() {",
            livepage.handler(observeClicking), "};",
            js.sendClickEvent(target, js.theClickObservation)
        ]
Exemplo n.º 24
0
 def action_click(self, action, target, parameter):
     def observeClicking(client):
         self.passed()
     return [
         "var theClickObservation = function() {",
         livepage.handler(observeClicking), "};",
         js.sendClickEvent(
             target,
             js.theClickObservation)]
Exemplo n.º 25
0
    def action_submit(self, action, target, parameter):
        def observeSubmission(client):
            self.passed()

        return self.action_post(
            action, target, parameter,
            self._handle.flt(
                ["function() {",
                 livepage.handler(observeSubmission), "}"],
                quote=False))
Exemplo n.º 26
0
 def action_visit(self, action, target, parameter):
     def observeLoading(client, location):
         if location.endswith(target):
             self.passed()
         else:
             self.failed()
     return ["addLoadObserver(function() {", 
             livepage.handler(
                 observeLoading,
                 contentDocument.location),
             "});",
             js.setContentLocation(target)]
Exemplo n.º 27
0
    def action_assert(self, action, target, parameter):
        def observeNodeContents(client, contents):
            if contents == parameter:
                self.passed()
            else:
                self.failed()

        return [
            livepage.handler(observeNodeContents,
                             contentDocument.getElementById(target).innerHTML,
                             bubble=True)
        ]
Exemplo n.º 28
0
    def action_visit(self, action, target, parameter):
        ## TODO: Figure out how to detect a 404 using javascript
        def observeLoading(client, location):
            if location.endswith(target):
                self.passed()
            else:
                self.failed()

        return [
            "addLoadObserver(function() {",
            livepage.handler(observeLoading, contentDocument.location), "});",
            js.setContentLocation(target)
        ]
Exemplo n.º 29
0
    def test_closedOverHandler(self):
        closedOver = 'hello'
        def closuredHandler(client):
            client.sendScript(closedOver)

        ## We have to "render" the result because the event handler has to be
        ## subscribed to at render time.
        result = self.flt(livepage.handler(closuredHandler))
        ## The closured handler will have been assigned a unique id.
        self.assertEquals(result,
            livepage.ctsTemplate % (fakeId, '', livepage.handledEventPostlude))

        self.livepage.handleInput(fakeId)
        self.assertEquals(self.livepage.sent, 'hello')
Exemplo n.º 30
0
    def test_closedOverHandler(self):
        closedOver = "hello"

        def closuredHandler(client):
            client.sendScript(closedOver)

        ## We have to "render" the result because the event handler has to be
        ## subscribed to at render time.
        result = livepage.handler(closuredHandler)(self.ctx, None)
        ## The closured handler will have been assigned a unique id.
        self.assertEquals(result.content, livepage.ctsTemplate % (fakeId, "", livepage.handledEventPostlude))

        self.livepage.handleInput(fakeId)
        self.assertEquals(self.livepage.sent, "hello")
Exemplo n.º 31
0
    def action_follow(self, action, target, parameter):
        def observeFollowing(client, location, destination):
            if location.endswith(destination):
                self.passed()
            else:
                self.failed()

        return [
            "var theTargetNode = ",
            contentDocument.getElementById(target), ";",
            "var theDestinationAddress = theTargetNode.href;",
            "addLoadObserver(function() {",
            livepage.handler(observeFollowing, contentDocument.location,
                             js.theDestinationAddress), "});",
            js.setContentLocation(js.theDestinationAddress)
        ]
Exemplo n.º 32
0
 def action_follow(self, action, target, parameter):
     def observeFollowing(client, location, destination):
         if location.endswith(destination):
             self.passed()
         else:
             self.failed()
     return [
         "var theTargetNode = ",
         contentDocument.getElementById(target), ";",
         "var theDestinationAddress = theTargetNode.href;",
         "addLoadObserver(function() {",
         livepage.handler(
             observeFollowing,
             contentDocument.location,
             js.theDestinationAddress),
         "});",
         js.setContentLocation(js.theDestinationAddress)]
Exemplo n.º 33
0
    def action_post(self, action, target, parameter, callWhenDone=None):
        if callWhenDone is None:
            callWhenDone = "function (){}"

        def observePosting(client, location, destination):
            if location.endswith(destination):
                self.passed()
            else:
                self.failed()

        return [
            "var targetForm = ", contentDocument[target], ";",
            "var postTarget = ", js.targetForm.action, ";",
            [(js.targetForm[key].value, ' = "', value, '";')
             for (key, value) in parameter.items()],
            "addLoadObserver(function () {",
            livepage.handler(observePosting, contentDocument.location,
                             js.postTarget), "});",
            js.sendSubmitEvent(js.targetForm, js(callWhenDone))
        ]
Exemplo n.º 34
0
 def action_post(self, action, target, parameter, callWhenDone=None):
     if callWhenDone is None:
         callWhenDone = "function (){}"
     def observePosting(client, location, destination):
         if location.endswith(destination):
             self.passed()
         else:
             self.failed()
     return [
         "var targetForm = ", contentDocument[target], ";",
         "var postTarget = ", js.targetForm.action, ";",
         [(js.targetForm[key].value, ' = "', value, '";')
         for (key, value) in parameter.items()],
         "addLoadObserver(function () {",
         livepage.handler(
             observePosting,
             contentDocument.location,
             js.postTarget),
         "});",
         js.sendSubmitEvent(js.targetForm, js(callWhenDone))]
 def render_delNode(self, ctx, data):
     """Fills in the oncommand handler for the 
     delete child button and short cut key"""
     return ctx.tag(
         oncommand=handler(self.outlinePane.handleDelNode,
                           js("confirmDelete()"), js('currentOutlineId()')))
 def render_addChild(self, ctx, data):
     """Fills in the oncommand handler for the 
     add child button and short cut key"""
     return ctx.tag(oncommand=handler(self.outlinePane.handleAddChild,
                                      js('currentOutlineId()')))
Exemplo n.º 37
0
 def test_decoratorLike(self):
     decorator = livepage.handler(livepage.document)
     self.assertEquals(
         self.flt(decorator(argsHandler)),
         livepage.ctsTemplate % (fakeId, ',document', livepage.handledEventPostlude))
Exemplo n.º 38
0
 def test_decoratorLike(self):
     decorator = livepage.handler(livepage.document)
     self.assertEquals(
         self.flt(decorator(argsHandler)),
         livepage.ctsTemplate % (fakeId, ",document", livepage.handledEventPostlude),
     )
Exemplo n.º 39
0
    def __call__(self):
        self.client.set('head', str(self.now))
        self.now = self.now + self.tenths / 10.0
        if self.now < 10:
            reactor.callLater(self.tenths / 10.0, self)


def ping(client, payload):
    try:
        Blaster(client, float(payload))()
    except ValueError:
        client.set('head', payload)
        reactor.callLater(1, client.set, 'head', "Do it again!")


ping = livepage.handler(ping,
                        livepage.document.getElementById('payload').value)


class Twister(livepage.LivePage):
    addSlash = True

    def render_form(self, context, data):
        return context.tag(onsubmit=ping)  # livepage.handler(ping))

    docFactory = loaders.xmlfile('twist.html')


class FakeFeed:
    def __init__(self, name, url):
        self.name = name
        self.url = url
Exemplo n.º 40
0
 def test_bubble(self):
     self.assertEquals(self.flt(livepage.handler(onClick, bubble=True)), livepage.ctsTemplate % (fakeId, "", ""))
Exemplo n.º 41
0
 def test_handler(self):
     result = livepage.handler(onClick)
     self.assertEquals(self.flt(result), livepage.ctsTemplate % (fakeId, "", livepage.handledEventPostlude))
     self.livepage.handleInput(fakeId)
     self.assertEquals(self.livepage.sent, "null;")
Exemplo n.º 42
0
 def _passHandle(self, ctx, name):
     """Ties up a handler for the promote, demote,
     up and down buttons. (Called by below funcs)"""
     attr = getattr(self.outlinePane, 'handle%s' % name)
     return ctx.tag(oncommand=handler(attr, js('currentOutlineId()')))
Exemplo n.º 43
0
 def render_delNode(self, ctx, data):
     """Fills in the oncommand handler for the 
     delete child button and short cut key"""
     return ctx.tag(oncommand=handler(self.outlinePane.handleDelNode,
                    js("confirmDelete()"),
                    js('currentOutlineId()')))
Exemplo n.º 44
0
 def render_addChild(self, ctx, data):
     """Fills in the oncommand handler for the 
     add child button and short cut key"""
     return ctx.tag(oncommand=handler(self.outlinePane.handleAddChild,
                    js('currentOutlineId()')))
 def _passHandle(self, ctx, name):
     """Ties up a handler for the promote, demote,
     up and down buttons. (Called by below funcs)"""
     attr = getattr(self.outlinePane, 'handle%s' % name)
     return ctx.tag(oncommand=handler(attr, js('currentOutlineId()')))
Exemplo n.º 46
0
 def test_bubble(self):
     self.assertEquals(
         self.flt(livepage.handler(onClick, bubble=True)),
         livepage.ctsTemplate % (fakeId, '', ';'))