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

Side by Side Diff: client/site_tests/power_LoadTest/extension/background.html

Issue 669230: Update Power Test to be 60/20/10 test. (Closed)
Patch Set: Fix issues pointed out by snanda and petkov Created 10 years, 9 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
« no previous file with comments | « no previous file | client/site_tests/power_LoadTest/extension/ct.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!--- 1 <!---
2 Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be 3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file. 4 found in the LICENSE file.
5 ---> 5 --->
6 6
7 <html> 7 <html>
8 <script src='/urls.js'> 8 <script src='/urls.js'>
9 </script> 9 </script>
10 10
11 <script src='/params.js'> 11 <script src='/params.js'>
12 </script> 12 </script>
13 13
14 <script> 14 <script>
15 15
16 // Test normally takes 60 mins. Set time_ratio to 10 to
17 // speed up the test 10x. This reduces the amount of time
18 // spent on each task.
19 var cycle_tabs = {}; 16 var cycle_tabs = {};
20 var failed_loads = [0]; 17 var cycles = {};
21 var successful_loads = [0];
22 var time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour 18 var time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour
23 var preexisting_windows = []; 19 var preexisting_windows = [];
24 20
25 chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { 21 chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
26 if (sender.tab.id in cycle_tabs) { 22 if (sender.tab.id in cycle_tabs) {
27 successful_loads[0]++; 23 cycle = cycle_tabs[sender.tab.id];
28 if (request.action == "should_scroll") { 24 cycle.successful_loads++;
25 if (request.action == "should_scroll" && cycle.focus) {
29 sendResponse({"should_scroll": should_scroll, 26 sendResponse({"should_scroll": should_scroll,
30 "should_scroll_up": should_scroll_up, 27 "should_scroll_up": should_scroll_up,
31 "scroll_loop": scroll_loop, 28 "scroll_loop": scroll_loop,
32 "scroll_interval": scroll_interval_ms, 29 "scroll_interval": scroll_interval_ms,
33 "scroll_by": scroll_by_pixels}); 30 "scroll_by": scroll_by_pixels});
34 } 31 }
35 delete cycle_tabs[sender.tab.id]; 32 delete cycle_tabs[sender.tab.id];
36 } 33 }
37 }); 34 });
38 35
39 function close_preexisting_windows() { 36 function close_preexisting_windows() {
40 for (var i = 0; i < preexisting_windows.length; i++) { 37 for (var i = 0; i < preexisting_windows.length; i++) {
41 chrome.windows.remove(preexisting_windows[i].id); 38 chrome.windows.remove(preexisting_windows[i].id);
42 } 39 }
43 preexisting_windows.length = 0; 40 preexisting_windows.length = 0;
44 } 41 }
45 42
43 function cycle_navigate(cycle) {
44 cycle_tabs[cycle.id] = cycle;
45 var url = cycle.urls[cycle.idx];
46 chrome.tabs.update(cycle.id, {'url': url, 'selected': true});
47 cycle.idx = (cycle.idx + 1) % cycle.urls.length;
48 if (cycle.timeout < cycle.delay && cycle.timeout > 0) {
49 cycle.timer = setTimeout(cycle_check_timeout, cycle.timeout, cycle);
50 } else {
51 cycle.timer = setTimeout(cycle_navigate, cycle.delay, cycle);
52 }
53 }
54
55 function cycle_check_timeout(cycle) {
56 if (cycle.id in cycle_tabs) {
57 cycle.failed_loads++;
58 cycle_navigate(cycle);
59 } else {
60 cycle.timer = setTimeout(cycle_navigate, cycle.delay - cycle.timeout,
61 cycle);
62 }
63 }
64
46 function launch_task(task) { 65 function launch_task(task) {
47 if (task.type == 'window' && task.tabs) { 66 if (task.type == 'window' && task.tabs) {
48 var url = task.tabs[0]; 67 var url = task.tabs[0];
49 chrome.windows.create({'url': url}, function (win) { 68 chrome.windows.create({'url': url}, function (win) {
50 close_preexisting_windows(); 69 close_preexisting_windows();
51 for (var i = 1; i < task.tabs.length; i++) { 70 for (var i = 1; i < task.tabs.length; i++) {
52 chrome.tabs.create({'windowId': win.id, url: task.tabs[i]}); 71 chrome.tabs.create({'windowId': win.id, url: task.tabs[i]});
53 } 72 }
54 setTimeout(chrome.windows.remove, task.duration / time_ratio, win.id); 73 setTimeout(chrome.windows.remove, task.duration / time_ratio, win.id);
55 }) 74 });
56 } else if (task.type == 'cycle' && task.urls) { 75 } else if (task.type == 'cycle' && task.urls) {
57 var url = task.urls[0]; 76 chrome.windows.create({'url': 'about:blank'}, function (win) {
58 var idx = 0;
59 chrome.windows.create({'url': url}, function (win) {
60 close_preexisting_windows(); 77 close_preexisting_windows();
61 chrome.tabs.getSelected(win.id, function(tab) { 78 chrome.tabs.getSelected(win.id, function(tab) {
62 cycle_tabs[tab.id] = task.scroll_interval; 79 var cycle = {
63 var cycleTask = setInterval(function(urls, tab_id) { 80 'timeout': task.timeout,
64 if (tab_id in cycle_tabs && urls.length > 1) { 81 'name': task.name,
65 failed_loads[0] += 1; 82 'delay': task.delay,
66 } 83 'urls': task.urls,
67 console.log('suc/fail: ' + successful_loads[0] + '/' + 84 'id': tab.id,
68 failed_loads[0]); 85 'idx': 0,
69 cycle_tabs[tab_id] = task.scroll_interval; 86 'timer': null,
70 idx = (idx + 1) % urls.length; 87 'focus': !!task.focus,
71 chrome.tabs.update(tab_id, {'url': urls[idx], 'selected': true}) 88 'successful_loads': 0,
72 }, task.delay, task.urls, tab.id); 89 'failed_loads': 0
73 setTimeout(function(win_id) { 90 };
74 clearInterval(cycleTask); 91 cycles[task.name] = cycle;
92 cycle_navigate(cycle);
93 setTimeout(function(cycle, win_id) {
94 clearTimeout(cycle.timer);
75 chrome.windows.remove(win_id); 95 chrome.windows.remove(win_id);
76 }, task.duration / time_ratio, win.id); 96 }, task.duration / time_ratio, cycle, win.id);
77 }); 97 });
78 }); 98 });
79 } 99 }
80 } 100 }
81 101
82 function close_browser() { 102 function close_browser() {
83 chrome.windows.getAll(null, function(windows) { 103 chrome.windows.getAll(null, function(windows) {
84 for (var i = 0; i < windows.length; i++) { 104 for (var i = 0; i < windows.length; i++) {
85 chrome.windows.remove(windows[i].id); 105 chrome.windows.remove(windows[i].id);
86 } 106 }
87 }); 107 });
88 } 108 }
89 109
90 function send_status() { 110 function send_status() {
111 var post = ["status=good"];
112
113 for (var name in cycles) {
114 var cycle = cycles[name];
115 post.push(name + "_successful_loads=" + cycle.successful_loads);
116 post.push(name + "_failed_loads=" + cycle.failed_loads);
117 }
118
91 var log_url = 'http://localhost:8001/status'; 119 var log_url = 'http://localhost:8001/status';
92 var req = new XMLHttpRequest(); 120 var req = new XMLHttpRequest();
93 req.open('POST', log_url, true); 121 req.open('POST', log_url, true);
94 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 122 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
95 req.send("status=good&succeeded=" + successful_loads[0] + "&failed=" 123 req.send(post.join("&"));
96 + failed_loads[0]); 124 console.log(post.join("&"));
97 } 125 }
98 126
99 127
100 chrome.windows.getAll(null, function(windows) { 128 chrome.windows.getAll(null, function(windows) {
101 preexisting_windows = windows; 129 preexisting_windows = windows;
102 var end = 0; 130 var end = 0;
103 for (var i = 0; i < tasks.length; i++) { 131 for (var i = 0; i < tasks.length; i++) {
104 end = Math.max(end, (tasks[i].start + tasks[i].duration) / time_ratio); 132 end = Math.max(end, (tasks[i].start + tasks[i].duration) / time_ratio);
105 setTimeout(launch_task, tasks[i].start / time_ratio, tasks[i]); 133 setTimeout(launch_task, tasks[i].start / time_ratio, tasks[i]);
106 } 134 }
107 setTimeout(send_status, end); 135 setTimeout(send_status, end);
108 136
109 // Add a 5sec delay between sending the status back and closing browser 137 // Add a 5sec delay between sending the status back and closing browser
110 // so that status message can reach autotest safely 138 // so that status message can reach autotest safely
111 setTimeout(close_browser, end + 5 * 1000); 139 setTimeout(close_browser, end + 5 * 1000);
112 }); 140 });
113 141
114 142
115 </script> 143 </script>
116 144
117 <body> 145 <body>
118 </body> 146 </body>
119 </html> 147 </html>
OLDNEW
« no previous file with comments | « no previous file | client/site_tests/power_LoadTest/extension/ct.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698