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