[Checkins] SVN: zc.testbrowser/trunk/ Merge Sebastian's branch that enables (and requires) MozLab 0.1.9 and supports Firefox

Christian Theune ct at gocept.com
Thu Oct 2 09:14:49 EDT 2008


Log message for revision 91660:
  Merge Sebastian's branch that enables (and requires) MozLab 0.1.9 and supports Firefox
  3.
  

Changed:
  U   zc.testbrowser/trunk/CHANGES.txt
  U   zc.testbrowser/trunk/README.txt
  U   zc.testbrowser/trunk/buildout.cfg
  U   zc.testbrowser/trunk/src/zc/testbrowser/README.txt
  U   zc.testbrowser/trunk/src/zc/testbrowser/ftests/controls.html
  A   zc.testbrowser/trunk/src/zc/testbrowser/ftests/doctype.html
  U   zc.testbrowser/trunk/src/zc/testbrowser/real.js
  U   zc.testbrowser/trunk/src/zc/testbrowser/real.py

-=-
Modified: zc.testbrowser/trunk/CHANGES.txt
===================================================================
--- zc.testbrowser/trunk/CHANGES.txt	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/CHANGES.txt	2008-10-02 13:14:48 UTC (rev 91660)
@@ -19,6 +19,8 @@
 - Bugfix: Correctly implement ``tb_set_checked()`` Javascript function for all
   cases of item controls.
 
+- Bugfix: Added <DOCTYPE and <html> node to browser.contents of real.Browser.
+
 - Feature: Improved test handler for HTTP to handle simple forms and multipart
   forms.
 
@@ -28,7 +30,10 @@
 - Feature: Correctly implemented the ``add_file()`` method of the control
   object for the real testbrowser implementation.
 
+- Feature: Support for Firefox 3 and Mozlab 0.1.9. Testbrowser does not work
+  with Mozlab 0.1.8 anymore due to API changes.
 
+
 1.0a4 (2008-03-06)
 ------------------
 

Modified: zc.testbrowser/trunk/README.txt
===================================================================
--- zc.testbrowser/trunk/README.txt	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/README.txt	2008-10-02 13:14:48 UTC (rev 91660)
@@ -11,10 +11,3 @@
 
 This project originates in the Zope 3 community, but is not Zope-specific (the
 zc namespace package stands for "Zope Corporation").
-
-
-Note:
-=====
-
-zc.testbrowser.real requires 0.1.8 of MozLab. 0.1.9 does not work
-because of changes in the API.

Modified: zc.testbrowser/trunk/buildout.cfg
===================================================================
--- zc.testbrowser/trunk/buildout.cfg	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/buildout.cfg	2008-10-02 13:14:48 UTC (rev 91660)
@@ -17,13 +17,8 @@
 [versions]
 ClientForm = 0.2.7
 mechanize = 0.1.7b
-setuptools = 0.6c7
 simplejson = 1.7.1
-zc.buildout = 1.0.0b30
-zc.recipe.egg = 1.0.0b6
-zc.recipe.testrunner = 1.0.0b8
 zope.event = 3.4.0
 zope.i18nmessageid = 3.4.0
 zope.interface = 3.4.0
 zope.schema = 3.3.0
-zope.testing = 3.5.1

Modified: zc.testbrowser/trunk/src/zc/testbrowser/README.txt
===================================================================
--- zc.testbrowser/trunk/src/zc/testbrowser/README.txt	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/src/zc/testbrowser/README.txt	2008-10-02 13:14:48 UTC (rev 91660)
@@ -45,6 +45,15 @@
     True
 
 
+The doctype and <html> node are also part of the contents:
+
+    >>> browser.open('doctype.html')
+    >>> print browser.contents
+    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+    <html>
+    <head>...
+
+
 Checking for HTML
 -----------------
 

Modified: zc.testbrowser/trunk/src/zc/testbrowser/ftests/controls.html
===================================================================
--- zc.testbrowser/trunk/src/zc/testbrowser/ftests/controls.html	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/src/zc/testbrowser/ftests/controls.html	2008-10-02 13:14:48 UTC (rev 91660)
@@ -193,6 +193,12 @@
         </select>
       </div>
 
+      <div>
+        <label for="image-value-superstring">Control names should be able to be
+                                             superstrings of others</label>
+        <input type="text" name="image-value-superstring"
+               id="image-value-superstring" />
+      </div>
 
     </form>
 

Copied: zc.testbrowser/trunk/src/zc/testbrowser/ftests/doctype.html (from rev 91659, zc.testbrowser/branches/sweh-mozlab0.1.9/src/zc/testbrowser/ftests/doctype.html)
===================================================================
--- zc.testbrowser/trunk/src/zc/testbrowser/ftests/doctype.html	                        (rev 0)
+++ zc.testbrowser/trunk/src/zc/testbrowser/ftests/doctype.html	2008-10-02 13:14:48 UTC (rev 91660)
@@ -0,0 +1,9 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+  <head>
+    <title>Doctype Test</title>
+  </head>
+  <body>
+    <h1>Doctype Test</h1>
+  </body>
+</html>

Modified: zc.testbrowser/trunk/src/zc/testbrowser/real.js
===================================================================
--- zc.testbrowser/trunk/src/zc/testbrowser/real.js	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/src/zc/testbrowser/real.js	2008-10-02 13:14:48 UTC (rev 91660)
@@ -295,7 +295,7 @@
     return tb_get_control_by_predicate(
         function (control) {
             var controlName = control.getAttribute('name');
-            return controlName != null && controlName.indexOf(name) != -1;
+            return controlName != null && controlName == name;
         }, index, true, tb_tokens[contextToken], xpath)
 }
 
@@ -571,3 +571,20 @@
     }
     return tokens;
 }
+
+function tb_get_contents() {
+    // get doctype
+    var node = content.document.firstChild;
+    var contents = '';
+    while (node) {
+      if (node.nodeType == node.DOCUMENT_TYPE_NODE) {
+        contents += '<!DOCTYPE ' + node.name.toLowerCase() + ' PUBLIC "' +
+          node.publicId + '" "' + node.systemId + '">\n';
+      } else if (node.nodeType == node.ELEMENT_NODE) {
+        var name = node.nodeName.toLowerCase();
+        contents += '<' + name + '>\n' + node.innerHTML + '</' + name + '>';
+      }
+      node = node.nextSibling;
+    }
+    return contents;
+}

Modified: zc.testbrowser/trunk/src/zc/testbrowser/real.py
===================================================================
--- zc.testbrowser/trunk/src/zc/testbrowser/real.py	2008-10-02 12:59:34 UTC (rev 91659)
+++ zc.testbrowser/trunk/src/zc/testbrowser/real.py	2008-10-02 13:14:48 UTC (rev 91660)
@@ -11,6 +11,7 @@
 import zope.interface
 
 PROMPT = re.compile('repl\d?> ')
+CONTINUATION_PROMPT = re.compile('\\.\\.\\.\\.\d?> ')
 
 class BrowserStateError(RuntimeError):
     pass
@@ -74,7 +75,7 @@
         res = self.executor(js)
         # JS has 'null' and 'undefined', python only has 'None'.
         # This hack is sufficient for now.
-        if res == '[undefined]':
+        if res == '[(void 0)]':
             return None
         return simplejson.loads(res)[0]
 
@@ -119,24 +120,31 @@
             raise RuntimeError('Error connecting to Firefox at %s:%s.'
                 ' Is MozRepl running?' % (host, port))
 
-        self.telnet.write(open(js_path, 'rt').read())
-        self.expect()
+        self.load_file(js_path)
 
+    def load_file(self, file_path):
+        for line in open(file_path, 'r'):
+            self.telnet.write(line)
+            self.expect([PROMPT, CONTINUATION_PROMPT])
+
     def execute(self, js):
         if not js.strip():
             return
-        self.telnet.write("'MARKER'")
+        if not js.endswith('\n'):
+            js = js + '\n'
+        self.telnet.write("'MARKER'\n")
         self.telnet.read_until('MARKER', self.timeout)
         self.expect()
         self.telnet.write(js)
         i, match, text = self.expect()
         #if '!!!' in text: import pdb;pdb.set_trace() # XXX debug only, remove
-        if '!!!' in text: raise Exception('FAILED: ' + js)
+        if '!!!' in text: raise Exception('FAILED: ' + text + ' in ' + js)
         result = text.rsplit('\n', 1)
         if len(result) == 1:
             return None
-        else:
-            return result[0]
+        if result[0].startswith('"') and result[0].endswith('"'):
+            return result[0][1:-1]
+        return result[0]
 
     def executeLines(self, js):
         lines = js.split('\n')
@@ -149,8 +157,10 @@
     def getAttributes(self, tokens, attr_name):
         return self.js.tb_extract_token_attrs(tokens, attr_name)
 
-    def expect(self):
-        i, match, text = self.telnet.expect([PROMPT], self.timeout)
+    def expect(self, expected=None):
+        if expected is None:
+            expected = [PROMPT]
+        i, match, text = self.telnet.expect(expected, self.timeout)
         if match is None:
             raise RuntimeError('unexpected result from MozRepl')
         return i, match, text
@@ -160,7 +170,18 @@
 
     @property
     def url(self):
-        return self.execute('content.location')
+        url = self.execute('content.location')
+        # url is something like this (without the line breaks):
+        # 'http://localhost:26118/index.html \xe2\x80\x94 {
+        #       href: "http://localhost:26118/index.html",
+        #       host: "localhost:26118",
+        #       hostname: "localhost",
+        #       port: "26118"}'
+        # But we only need the URL part
+        token = ' \xe2\x80\x94 {'
+        if token in url:
+            url = url.split(token)[0]
+        return url
 
     def wait(self):
         start = time.time()
@@ -170,7 +191,11 @@
                 raise RuntimeError('timed out waiting for page load')
 
         assert self.execute('tb_page_loaded;') == 'true'
-        self.execute('tb_page_loaded = false;')
+
+        while self.execute('tb_page_loaded;') == 'true':
+            self.execute('tb_page_loaded = false;')
+            time.sleep(0.001)
+
         assert self.execute('tb_page_loaded;') == 'false'
 
     def open(self, url, data=None):
@@ -205,7 +230,7 @@
         if base == 'text' and 'html' not in sub:
             return self.execute(
                 "content.document.getElementsByTagName('pre')[0].innerHTML")
-        return self.execute('content.document.documentElement.innerHTML')
+        return self.execute('tb_get_contents()')
 
     def reload(self):
         self.execute('content.document.location = content.document.location')



More information about the Checkins mailing list