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

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

Issue 2844047: Modify power_LoadTest Extension to pull in test parameters. (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: Set 1 hour long test. Created 9 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
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 var cycle_tabs = {}; 16 var cycle_tabs = {};
17 var cycles = {}; 17 var cycles = {};
18 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
19 var preexisting_windows = []; 19 var preexisting_windows = [];
20 20
21 chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { 21 function setupTest() {
22 chrome.windows.getAll(null, function(windows) {
23 preexisting_windows = windows;
24 var end = 0;
25 for (var i = 0; i < tasks.length; i++) {
26 end = Math.max(end, (tasks[i].start + tasks[i].duration) / time_ratio);
27 setTimeout(launch_task, tasks[i].start / time_ratio, tasks[i]);
28 }
29 setTimeout(send_status, end);
30 // Add a 5sec delay between sending the status back and closing browser
31 // so that status message can reach autotest safely
32 setTimeout(close_browser, end + 5 * 1000);
33 });
34 }
35
36 function testListener(request, sender, sendResponse) {
22 if (sender.tab.id in cycle_tabs) { 37 if (sender.tab.id in cycle_tabs) {
23 cycle = cycle_tabs[sender.tab.id]; 38 cycle = cycle_tabs[sender.tab.id];
24 cycle.successful_loads++; 39 cycle.successful_loads++;
25 if (request.action == "should_scroll" && cycle.focus) { 40 if (request.action == "should_scroll" && cycle.focus) {
26 sendResponse({"should_scroll": should_scroll, 41 sendResponse({"should_scroll": should_scroll,
27 "should_scroll_up": should_scroll_up, 42 "should_scroll_up": should_scroll_up,
28 "scroll_loop": scroll_loop, 43 "scroll_loop": scroll_loop,
29 "scroll_interval": scroll_interval_ms, 44 "scroll_interval": scroll_interval_ms,
30 "scroll_by": scroll_by_pixels}); 45 "scroll_by": scroll_by_pixels});
31 } 46 }
32 delete cycle_tabs[sender.tab.id]; 47 delete cycle_tabs[sender.tab.id];
33 } 48 }
34 }); 49 }
50
51
52 chrome.extension.onRequest.addListener(
53 function paramsSetupListener(request, sender) {
54 console.log(sender.tab ?
55 "from a content script:" + sender.tab.url :
56 "from the extension");
Sameer Nanda 2011/02/28 22:11:34 remove logging?
Benson Leung 2011/03/01 02:16:19 Done.
57 if (undefined != request._test_time_ms &&
58 undefined != request._should_scroll &&
59 undefined != request._should_scroll_up &&
60 undefined != request._scroll_loop &&
61 undefined != request._scroll_interval_ms &&
62 undefined != request._scroll_by_pixels) {
63 console.log("test parameters received!");
64 // Update test parameters from content script.
65 test_time_ms = request._test_time_ms;
66 should_scroll = request._should_scroll;
67 should_scroll_up = request._should_scroll_up;
68 scroll_loop = request._scroll_loop;
69 scroll_interval_ms = request._scroll_interval_ms;
70 scroll_by_pixels = request._scroll_by_pixels;
71 time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour
72 chrome.extension.onRequest.removeListener(paramsSetupListener);
73 chrome.extension.onRequest.addListener(testListener);
74 setTimeout(setupTest, 1000);
75 }
Sameer Nanda 2011/02/28 22:11:34 add else clause with error log?
Benson Leung 2011/03/01 02:16:19 Done.
76 }
77 );
78
79
35 80
36 function close_preexisting_windows() { 81 function close_preexisting_windows() {
37 for (var i = 0; i < preexisting_windows.length; i++) { 82 for (var i = 0; i < preexisting_windows.length; i++) {
38 chrome.windows.remove(preexisting_windows[i].id); 83 chrome.windows.remove(preexisting_windows[i].id);
39 } 84 }
40 preexisting_windows.length = 0; 85 preexisting_windows.length = 0;
41 } 86 }
42 87
43 function cycle_navigate(cycle) { 88 function cycle_navigate(cycle) {
44 cycle_tabs[cycle.id] = cycle; 89 cycle_tabs[cycle.id] = cycle;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 console.log(post.join("&")); 171 console.log(post.join("&"));
127 } 172 }
128 173
129 chrome.windows.getAll(null, function(windows) { 174 chrome.windows.getAll(null, function(windows) {
130 // delay starting test by short amount of time to allow chromeos 175 // delay starting test by short amount of time to allow chromeos
131 // login process to settle down 176 // login process to settle down
132 setTimeout(startTest, test_startup_delay); 177 setTimeout(startTest, test_startup_delay);
133 }); 178 });
134 179
135 function startTest() { 180 function startTest() {
136 var end = 0; 181 chrome.windows.create({'url': 'http://localhost:8001/testparams.html'});
137 chrome.windows.getAll(null, function(windows) {
138 preexisting_windows = windows;
139 });
140 for (var i = 0; i < tasks.length; i++) {
141 end = Math.max(end, (tasks[i].start + tasks[i].duration) / time_ratio);
142 setTimeout(launch_task, tasks[i].start / time_ratio, tasks[i]);
143 }
144 setTimeout(send_status, end);
145 182
146 // Add a 5sec delay between sending the status back and closing browser
147 // so that status message can reach autotest safely
148 setTimeout(close_browser, end + 5 * 1000);
149 } 183 }
150 184
185 // Called when the user clicks on the browser action.
186 chrome.browserAction.onClicked.addListener(function(tab) {
187 // Start the test with default settings.
188 chrome.extension.onRequest.addListener(testListener);
189 setupTest();
190 });
191
151 192
152 </script> 193 </script>
153 194
154 <body> 195 <body>
155 </body> 196 </body>
156 </html> 197 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698