File: WindowTest.py

package info (click to toggle)
pyjamas 0.7~%2Bpre2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,656 kB
  • ctags: 12,331
  • sloc: python: 74,493; php: 805; sh: 291; makefile: 59; xml: 9
file content (52 lines) | stat: -rw-r--r-- 1,765 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from UnitTest import UnitTest, IN_BROWSER
from pyjamas import Window

class WindowTest(UnitTest):

    """tests for javascript object conversion"""

    def onWindowResized(self, width, height):

        if not self.resize_test:
            self.fail("onWindowResized called after WindowListener removed")
            return

        nh = Window.getClientHeight()
        nw = Window.getClientWidth()
        # TODO: we cannot assert the exact size, because, we have toolbars
        self.assertTrue(nw!=self.w)
        self.assertTrue(nh!=self.h)
        self.assertTrue(isinstance(nw, int))
        self.assertTrue(isinstance(nh, int))

        # put the window back to its original size
        # but make sure to switch off resize notify!
        self.resize_test = False
        Window.removeWindowResizeListener(self)
        Window.resize(self.w, self.h)

    def testResize(self):
        # TODO: window resizing does not work accuratly in browser
        # because getClientWidth etc does not really match GWT. We
        # need to copy the GWT implementation
        if IN_BROWSER:
            return
        self.resize_test = True
        Window.addWindowResizeListener(self)
        self.h = Window.getClientHeight()
        self.w = Window.getClientWidth()
        Window.resize(800, 600)

    def testClientDimensions(self):
        h = Window.getClientHeight()
        w = Window.getClientWidth()
        self.assertTrue(isinstance(w, int))
        self.assertTrue(isinstance(h, int))

    def testLocation(self):
        self.assertTrue(Window.getLocation().getHref().endswith(
            'LibTest.html'))

    def testTitle(self):
        self.assertEquals(Window.getTitle(),
                          'PyJamas Auto-Generated HTML file LibTest')