1 |
1 |
2 // This file contains functions to be used for testing and logging. |
2 // This file contains functions to be used for testing and logging. |
3 |
3 |
4 var loadStartTime = new Date().getTime(); |
4 var __loadStartTime = new Date().getTime(); |
5 var loadCount = 0; |
5 var __loadCount = 0; |
|
6 var __average = 0; |
6 |
7 |
7 // Setup callback for loadStarted signal. |
8 // Setup callback for loadStarted signal. |
8 // Called when a new page has started loading. |
9 // Called when a new page has started loading. |
9 // |
10 // |
10 window.pageController.loadStarted.connect( |
11 window.pageController.loadStarted.connect( |
11 function() { |
12 function() { |
12 loadStartTime = new Date().getTime(); |
13 __loadStartTime = new Date().getTime(); |
13 window.chrome.log("loadStarted:"); |
14 window.chrome.log("loadStarted:"); |
14 } |
15 } |
15 ); |
16 ); |
16 |
17 |
17 // Setup callback for URL changed signal. |
18 // Setup callback for URL changed signal. |
18 // Called when a new page has started loading. |
19 // Called when a new page has started loading. |
19 // |
20 // |
20 window.pageController.currentPageUrlChanged.connect( |
21 //window.pageController.currentPageUrlChanged.connect( |
21 function(url) { |
22 // function(url) { |
22 window.chrome.log("currentPageUrlChanged: " + url); |
23 // window.chrome.log("currentPageUrlChanged: " + url); |
23 } |
24 // } |
24 ); |
25 //); |
25 |
26 |
26 // Setup callback for loadFinished signal. |
27 // Setup callback for loadFinished signal. |
27 // Called when the current page has finished loading. |
28 // Called when the current page has finished loading. |
28 // 'ok' parameter is false if there was an error (not very reliable). |
29 // 'ok' parameter is false if there was an error (not very reliable). |
29 // |
30 // |
30 window.pageController.loadFinished.connect( |
31 window.pageController.loadFinished.connect( |
31 function(ok) { |
32 function(ok) { |
|
33 __loadCount++; |
|
34 var loadTime = new Date().getTime() - __loadStartTime; |
|
35 app.debug("+++ loadtime=" + loadTime); |
|
36 if (__average == 0) { |
|
37 __average = loadTime; |
|
38 } |
|
39 else { |
|
40 __average += (loadTime - __average) / __loadCount; |
|
41 } |
|
42 app.debug("== count=" + __loadCount + " average=" + __average); |
32 window.chrome.log("loadFinished: " + |
43 window.chrome.log("loadFinished: " + |
33 "load count: " + loadCount + " " + |
44 "load count: " + __loadCount + " " + |
34 "load time: " + (new Date().getTime() - loadStartTime) + "ms " + |
45 "load time: " + loadTime + "ms " + |
|
46 "average: " + __average + "ms " + |
35 "ok=" + ok + " " + window.pageController.currentDocUrl); |
47 "ok=" + ok + " " + window.pageController.currentDocUrl); |
36 //window.pageController.currentLoad("http://www.google.com/search?q=help"); |
48 |
37 |
49 if (__loadCount > 1) { |
38 loadCount++; |
50 // Load another document. This will effectively keep loading the same document forever. |
39 |
51 //setTimeout("window.pageController.currentLoad('http://doc.trolltech.com/4.6/functions.html')",2000); |
40 // Load another document. This will effectively keep loading the same document forever. |
52 setTimeout("window.pageController.currentLoad('http://www.google.com/search?q=help')",1000); |
41 //setTimeout("window.pageController.currentLoad('http://doc.trolltech.com/4.6/classes.html')",1000); |
53 //setTimeout("window.pageController.currentLoad('http://apple.com')",2000); |
42 //setTimeout("window.pageController.currentLoad('http://www.google.com/search?q=help')",1000); |
54 } |
43 } |
55 } |
44 ); |
56 ); |
45 |
57 |
46 // Setup callback for loadProgress signal. |
58 // Setup callback for loadProgress signal. |
47 // Called periodically during the load process. |
59 // Called periodically during the load process. |
48 // 'percent' parameter indicates how much of the document has been loaded (0-100). |
60 // 'percent' parameter indicates how much of the document has been loaded (0-100). |
49 // |
61 // |
50 //window.pageController.loadProgress.connect( |
62 //window.pageController.loadProgress.connect( |
51 // function(percent) { |
63 // function(percent) { |
52 // window.chrome.log("loadProgress: percent=" + percent); |
64 // window.chrome.log("loadProgress: percent=" + percent); |