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))
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))
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), )
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))
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))
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
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'])
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
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'])
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"])
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))
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
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))
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
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 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')
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)]
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
def action_click(self, action, target, parameter): def observeClicking(client): self.passed() return [ "var theClickObservation = function() {", livepage.handler(observeClicking), "};", js.sendClickEvent(target, js.theClickObservation) ]
def action_click(self, action, target, parameter): def observeClicking(client): self.passed() return [ "var theClickObservation = function() {", livepage.handler(observeClicking), "};", js.sendClickEvent( target, js.theClickObservation)]
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))
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)]
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) ]
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) ]
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')
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")
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) ]
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)]
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 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()')))
def test_decoratorLike(self): decorator = livepage.handler(livepage.document) self.assertEquals( self.flt(decorator(argsHandler)), livepage.ctsTemplate % (fakeId, ',document', livepage.handledEventPostlude))
def test_decoratorLike(self): decorator = livepage.handler(livepage.document) self.assertEquals( self.flt(decorator(argsHandler)), livepage.ctsTemplate % (fakeId, ",document", livepage.handledEventPostlude), )
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
def test_bubble(self): self.assertEquals(self.flt(livepage.handler(onClick, bubble=True)), livepage.ctsTemplate % (fakeId, "", ""))
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 _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()')))
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 test_bubble(self): self.assertEquals( self.flt(livepage.handler(onClick, bubble=True)), livepage.ctsTemplate % (fakeId, '', ';'))