Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: chrome/test/data/dromaeo/tests/sunspider-string-validate-input.html

Issue 269054: Importing dromaeo performance tests to src/chrome/test/data.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script src="../htmlrunner.js"></script>
4 <script>
5 var letters = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n", "o","p","q","r","s","t","u","v","w","x","y","z");
6 var numbers = new Array(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);
7 var colors = new Array("FF","CC","99","66","33","00");
8
9 var endResult;
10
11 function testEmail()
12 {
13 endResult = "";
14 var r;
15
16 // make up email address
17 for (var k=0;k<2000;k++)
18 {
19 var name = makeName(6);
20 var email = (k%2)?name+"@mac.com":name+"(at)mac.com";
21
22 // validate the email address
23 var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a- zA-Z]{2,3}$/;
24
25 if(pattern.test(email))
26 {
27 r = email + " appears to be a valid email address.";
28 addResult(r);
29 }
30 else
31 {
32 r = email + " does NOT appear to be a valid email address.";
33 addResult(r);
34 }
35 }
36 }
37
38 function testZip()
39 {
40 endResult = "";
41 var r;
42
43 // make up ZIP codes
44 for (var s=0;s<2000;s++)
45 {
46 var zipGood = true;
47 var zip = makeNumber(4);
48 (s%2)?zip=zip+"xyz":zip=zip.concat("7");
49
50 // validate the zip code
51 for (var i = 0; i < zip.length; i++) {
52 var ch = zip.charAt(i);
53 if (ch < "0" || ch > "9") {
54 zipGood = false;
55 r = zip + " contains letters.";
56 addResult(r);
57 }
58 }
59 if (zipGood && zip.length>5)
60 {
61 zipGood = false;
62 r = zip + " is longer than five characters.";
63 addResult(r);
64 }
65 if (zipGood)
66 {
67 r = zip + " appears to be a valid ZIP code.";
68 addResult(r);
69 }
70 }
71 }
72
73 function makeName(n)
74 {
75 var tmp = "";
76 for (var i=0;i<n;i++)
77 {
78 var l = Math.floor(26*Math.random());
79 tmp += letters[l];
80 }
81 return tmp;
82 }
83
84 function makeNumber(n)
85 {
86 var tmp = "";
87 for (var i=0;i<n;i++)
88 {
89 var l = Math.floor(9*Math.random());
90 tmp = tmp.concat(l);
91 }
92 return tmp;
93 }
94
95 function addResult(r)
96 {
97 endResult += "\n" + r;
98 }
99
100 window.onload = function(){ startTest("sunspider-string-validate-input", '');
101
102 test("Validate Email Input", testEmail);
103 test("Validate Zipcode Input", testEmail);
104
105 endTest(); };
106 </script>
107 </head>
108 <body></body>
109 </html>
OLDNEW
« no previous file with comments | « chrome/test/data/dromaeo/tests/sunspider-string-unpack-code.html ('k') | chrome/test/data/dromaeo/tests/v8-crypto.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698