tests/test-newcgi.t
author Alexander Plavin <me@aplavin.ru>
Thu, 04 Jul 2013 14:18:44 +0400
changeset 19387 f2e4fdb3dd27
parent 15567 8b84d040d9f9
child 22046 7a9cbb315d84
permissions -rw-r--r--
hgweb: code selection without line numbers in file source view All the source lines are put in a <pre> tag, which gives correct display and copy&paste in both Chromium (WebKit) and FireFox: line numbers are not copied, all the tabs and spaces are kept. This doesn't change the visual appearance of the view compared to current hgweb version and doesn't use any JS code. Also, stripes in this view are now generated clientside with CSS. This implementation is chosen because other variants have important issues: Strategy FF Chrome current D,LT,E,T,L D,L pre S,NW S,NW pre/div/nbsp LT,E,T,TS,NW TS,NW pre/div/br LT,E,T,NW NW ol/li/nbsp LT,E,T,TS,AJ TS,AJ ol/li/br LT,E,T,AJ AJ pre/span LV LV Legend Strategies: - current: implemented in hgweb before this patch, i.e. divs for each line, and line numbers links in the div too - pre: the whole code in one pre tag with newlines, all line numbers in another one with 'float: left' - pre/div/{nbsp,br}: same as just 'pre', but separate divs for each line and &nbsp; or <br> instead of empty lines (otherwise they are not copied at all) - ol/li/{nbsp,br}: a single ol with li's and divs for each line, &nbsp; or <br> same as in previous strategy - pre/span: this patch Problems: D = (very minor) display problems, like wrong width of leading tabs LT = loses leading/trailing whitespace E = loses embedded whitespace B = loses blank lines T = loses tabs L = selects line numbers LV = (only) visually selects line numbers LVE = (only) visually selects line numbers at empty lines S = no stripes (and no ability to easily highlight lines-which-are-linked-at in the future) TS = space copied instead of empty line AJ = get anchor links only with JS (they work even without) NW = no linewrap easily possible (in future) As for browser versions compatibility, the CSS tricks used are supported in (according to caniuse.com): a) line numbers generation with 'content:' property and CSS counters: IE 8+, all other popular browsers (in pre-WebKit Opera numbers are being copied) b) stripes ('nth-child' selector): IE 8+, FF 3.5+, Safari 3.2+, Opera 9.5+, all other popular browsers c) line numbers are not visually selected ('user-select:' property): IE 10+, Opera 15.0+, all other popular browsers This patch is based on a demo implementation by Martin Geisler <martin@geisler.net>.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15567
8b84d040d9f9 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 13269
diff changeset
     1
  $ "$TESTDIR/hghave" no-msys || exit 80 # MSYS will translate web paths as if they were file paths
8b84d040d9f9 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 13269
diff changeset
     2
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
     3
This tests if CGI files from after d0db3462d568 but
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
     4
before d74fc8dec2b4 still work.
5577
e0173902c813 CGI compatibility fix for d74fc8dec2b4.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     5
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
     6
  $ hg init test
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
     7
  $ cat >hgweb.cgi <<HGWEB
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
     8
  > #!/usr/bin/env python
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
     9
  > #
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    10
  > # An example CGI script to use hgweb, edit as necessary
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    11
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    12
  > import cgitb
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    13
  > cgitb.enable()
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    14
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    15
  > from mercurial import demandimport; demandimport.enable()
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    16
  > from mercurial.hgweb import hgweb
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    17
  > from mercurial.hgweb import wsgicgi
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    18
  > from mercurial.hgweb.request import wsgiapplication
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    19
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    20
  > def make_web_app():
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12470
diff changeset
    21
  >     return hgweb("test", "Empty test repository")
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    22
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    23
  > wsgicgi.launch(wsgiapplication(make_web_app))
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    24
  > HGWEB
5577
e0173902c813 CGI compatibility fix for d74fc8dec2b4.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    25
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    26
  $ chmod 755 hgweb.cgi
5577
e0173902c813 CGI compatibility fix for d74fc8dec2b4.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    27
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    28
  $ cat >hgweb.config <<HGWEBDIRCONF
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    29
  > [paths]
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    30
  > test = test
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    31
  > HGWEBDIRCONF
5577
e0173902c813 CGI compatibility fix for d74fc8dec2b4.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    32
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    33
  $ cat >hgwebdir.cgi <<HGWEBDIR
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    34
  > #!/usr/bin/env python
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    35
  > #
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    36
  > # An example CGI script to export multiple hgweb repos, edit as necessary
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    37
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    38
  > import cgitb
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    39
  > cgitb.enable()
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    40
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    41
  > from mercurial import demandimport; demandimport.enable()
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    42
  > from mercurial.hgweb import hgwebdir
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    43
  > from mercurial.hgweb import wsgicgi
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    44
  > from mercurial.hgweb.request import wsgiapplication
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    45
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    46
  > def make_web_app():
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12470
diff changeset
    47
  >     return hgwebdir("hgweb.config")
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    48
  > 
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    49
  > wsgicgi.launch(wsgiapplication(make_web_app))
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    50
  > HGWEBDIR
5577
e0173902c813 CGI compatibility fix for d74fc8dec2b4.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    51
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    52
  $ chmod 755 hgwebdir.cgi
5577
e0173902c813 CGI compatibility fix for d74fc8dec2b4.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    53
13269
aa3f726a2bdb tests: remove duplication of the CGI environment variables
StevenGBrown
parents: 12743
diff changeset
    54
  $ . "$TESTDIR/cgienv"
12470
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    55
  $ python hgweb.cgi > page1
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    56
  $ python hgwebdir.cgi > page2
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    57
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    58
  $ PATH_INFO="/test/"
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    59
  $ PATH_TRANSLATED="/var/something/test.cgi"
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    60
  $ REQUEST_URI="/test/test/"
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    61
  $ SCRIPT_URI="http://hg.omnifarious.org/test/test/"
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    62
  $ SCRIPT_URL="/test/test/"
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    63
  $ python hgwebdir.cgi > page3
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    64
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    65
  $ grep -i error page1 page2 page3
70a6734cf761 tests: unify test-newcgi
Matt Mackall <mpm@selenic.com>
parents: 5580
diff changeset
    66
  [1]