Index: chrome/test/data/chrome_endure/deterministic.js |
diff --git a/chrome/test/data/chrome_endure/deterministic.js b/chrome/test/data/chrome_endure/deterministic.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..639f4732cd14aef1f7daa619ce95ed36c6b148b7 |
--- /dev/null |
+++ b/chrome/test/data/chrome_endure/deterministic.js |
@@ -0,0 +1,88 @@ |
+/* |
dennis_jeffrey
2012/07/24 00:39:35
could we give this file a new name? Something to
fdeng1
2012/07/24 04:30:05
Done.
|
+ * Copyright 2012, Google Inc. |
+ * All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
dennis_jeffrey
2012/07/24 00:39:35
We should probably use the regular 3-line chromium
fdeng1
2012/07/24 04:30:05
Done.
|
+ |
+/* |
+ * The scripts in this file will be injected to the http responses when |
+ * simulating network via Web Page Replay for Chrome Endure tests. |
+ * |
+ * If you need to modify this scripts, make sure that you use the same version |
+ * of this scripts in both record and replay mode. |
dennis_jeffrey
2012/07/24 00:39:35
you might want to mention that this script is adap
fdeng1
2012/07/24 04:30:05
Done.
|
+ * |
+ * TODO(fdeng): Currently the time_seed is set to a date far in the future. |
+ * This might cause problems but it is the workaround for Endure tests for |
+ * Google apps like Gmail. A better way to go is to revise the time_seed to |
+ * current time each time we record and use the revised scripts for replay. |
+ * This can be achieved by modifying Web Page Replay to automaticly |
dennis_jeffrey
2012/07/24 00:39:35
automaticly --> automatically
fdeng1
2012/07/24 04:30:05
Done.
|
+ * revise and save scripts in the archive in record mode and read it |
+ * from the archive in replay mode. |
+ */ |
+(function () { |
+ var orig_date = Date; |
+ var random_count = 0; |
+ var date_count = 0; |
+ var random_seed = 0.462; |
+ var time_seed = 3204251968254; |
dennis_jeffrey
2012/07/24 00:39:35
var time_seed = 3204251968254; # Changed from def
fdeng1
2012/07/24 04:30:05
Done.
|
+ var random_count_threshold = 25; |
+ var date_count_threshold = 25; |
+ Math.random = function() { |
+ random_count++; |
+ if (random_count > random_count_threshold){ |
dennis_jeffrey
2012/07/24 00:39:35
add a space right before {
fdeng1
2012/07/24 04:30:05
Done.
|
+ random_seed += 0.1; |
+ random_count = 1; |
+ } |
+ return (random_seed % 1); |
+ }; |
+ Date = function() { |
+ if (this instanceof Date) { |
+ date_count++; |
+ if (date_count > date_count_threshold){ |
dennis_jeffrey
2012/07/24 00:39:35
add a space right before {
fdeng1
2012/07/24 04:30:05
Done.
|
+ time_seed += 50; |
+ date_count = 1; |
+ } |
+ switch (arguments.length) { |
+ case 0: return new orig_date(time_seed); |
+ case 1: return new orig_date(arguments[0]); |
+ default: return new orig_date(arguments[0], arguments[1], |
+ arguments.length >= 3 ? arguments[2] : 1, |
+ arguments.length >= 4 ? arguments[3] : 0, |
+ arguments.length >= 5 ? arguments[4] : 0, |
+ arguments.length >= 6 ? arguments[5] : 0, |
+ arguments.length >= 7 ? arguments[6] : 0); |
+ } |
+ } |
+ return new Date().toString(); |
+ }; |
+ Date.__proto__ = orig_date; |
+ Date.prototype.constructor = Date; |
+ orig_date.now = function() { |
+ return new Date().getTime(); |
+ }; |
+})(); |