OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
| 4 <a id="file" href="file:///path/to/file">File</a> |
| 5 <a id="chrome" href="about:chrome">Chrome</a> |
| 6 <a href="about:blank"><b id="blank">Click me</b></a> |
4 <script> | 7 <script> |
5 | 8 |
6 function testQuoteString() { | 9 function testQuoteString() { |
7 // Basic cases. | 10 // Basic cases. |
8 assertEquals('\"test\"', quoteString('"test"')); | 11 assertEquals('\"test\"', quoteString('"test"')); |
9 assertEquals('\\!\\?', quoteString('!?')); | 12 assertEquals('\\!\\?', quoteString('!?')); |
10 assertEquals('\\(\\._\\.\\) \\( \\:l \\) \\(\\.-\\.\\)', | 13 assertEquals('\\(\\._\\.\\) \\( \\:l \\) \\(\\.-\\.\\)', |
11 quoteString('(._.) ( :l ) (.-.)')); | 14 quoteString('(._.) ( :l ) (.-.)')); |
12 | 15 |
13 // Using the output as a regex. | 16 // Using the output as a regex. |
14 var re = new RegExp(quoteString('"hello"'), 'gim'); | 17 var re = new RegExp(quoteString('"hello"'), 'gim'); |
15 var match = re.exec('She said "Hello" loudly'); | 18 var match = re.exec('She said "Hello" loudly'); |
16 assertEquals(9, match.index); | 19 assertEquals(9, match.index); |
17 | 20 |
18 re = new RegExp(quoteString('Hello, .*'), 'gim'); | 21 re = new RegExp(quoteString('Hello, .*'), 'gim'); |
19 match = re.exec('Hello, world'); | 22 match = re.exec('Hello, world'); |
20 assertEquals(null, match); | 23 assertEquals(null, match); |
21 } | 24 } |
22 | 25 |
| 26 function testClickHandler() { |
| 27 var clickArgs = null; |
| 28 var oldSend = chrome.send; |
| 29 chrome.send = function(message, args) { |
| 30 assertEquals('navigateToUrl', message); |
| 31 clickArgs = args; |
| 32 }; |
| 33 $('file').click(); |
| 34 assertEquals('file:///path/to/file', clickArgs[0]); |
| 35 $('chrome').click(); |
| 36 assertEquals('about:chrome', clickArgs[0]); |
| 37 $('blank').click(); |
| 38 assertEquals('about:blank', clickArgs[0]); |
| 39 chrome.send = oldSend; |
| 40 } |
| 41 |
23 </script> | 42 </script> |
24 </body> | 43 </body> |
25 </html> | 44 </html> |
OLD | NEW |