OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 * |
| 5 * The scripts in this file will be injected to the http responses when |
| 6 * simulating network via Web Page Replay for Chrome Endure tests. |
| 7 * |
| 8 * If you need to modify this scripts, make sure that you use the same version |
| 9 * of this scripts in both record and replay mode. |
| 10 * |
| 11 * TODO(fdeng): |
| 12 * This file is adapted from deterministic.js in Web Page Replay project. |
| 13 * http://code.google.com/p/web-page-replay/source/browse/trunk/deterministic.js |
| 14 * The value of time_seed is modified to a date far in the future. |
| 15 * This is a workaround for Endure tests for Google apps like Gmail. |
| 16 * The side effect of a future date is unknown and needs future investigation. |
| 17 * A better way to go is to revise the time_seed to |
| 18 * current time each time we record and use the revised scripts for replay. |
| 19 * This can be achieved by modifying Web Page Replay to automatically |
| 20 * revise and save scripts in the archive in record mode and read it |
| 21 * from the archive in replay mode. |
| 22 */ |
| 23 (function () { |
| 24 var orig_date = Date; |
| 25 var random_count = 0; |
| 26 var date_count = 0; |
| 27 var random_seed = 0.462; |
| 28 var time_seed = 3204251968254; // Changed from default value 1204251968254 |
| 29 var random_count_threshold = 25; |
| 30 var date_count_threshold = 25; |
| 31 Math.random = function() { |
| 32 random_count++; |
| 33 if (random_count > random_count_threshold) { |
| 34 random_seed += 0.1; |
| 35 random_count = 1; |
| 36 } |
| 37 return (random_seed % 1); |
| 38 }; |
| 39 Date = function() { |
| 40 if (this instanceof Date) { |
| 41 date_count++; |
| 42 if (date_count > date_count_threshold) { |
| 43 time_seed += 50; |
| 44 date_count = 1; |
| 45 } |
| 46 switch (arguments.length) { |
| 47 case 0: return new orig_date(time_seed); |
| 48 case 1: return new orig_date(arguments[0]); |
| 49 default: return new orig_date(arguments[0], arguments[1], |
| 50 arguments.length >= 3 ? arguments[2] : 1, |
| 51 arguments.length >= 4 ? arguments[3] : 0, |
| 52 arguments.length >= 5 ? arguments[4] : 0, |
| 53 arguments.length >= 6 ? arguments[5] : 0, |
| 54 arguments.length >= 7 ? arguments[6] : 0); |
| 55 } |
| 56 } |
| 57 return new Date().toString(); |
| 58 }; |
| 59 Date.__proto__ = orig_date; |
| 60 Date.prototype.constructor = Date; |
| 61 orig_date.now = function() { |
| 62 return new Date().getTime(); |
| 63 }; |
| 64 })(); |
OLD | NEW |