| OLD | NEW |
| 1 <!--- | 1 <!--- |
| 2 Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 Copyright (c) 2011 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 if (undefined != request._test_time_ms && |
| 55 undefined != request._should_scroll && |
| 56 undefined != request._should_scroll_up && |
| 57 undefined != request._scroll_loop && |
| 58 undefined != request._scroll_interval_ms && |
| 59 undefined != request._scroll_by_pixels) { |
| 60 // Update test parameters from content script. |
| 61 test_time_ms = request._test_time_ms; |
| 62 should_scroll = request._should_scroll; |
| 63 should_scroll_up = request._should_scroll_up; |
| 64 scroll_loop = request._scroll_loop; |
| 65 scroll_interval_ms = request._scroll_interval_ms; |
| 66 scroll_by_pixels = request._scroll_by_pixels; |
| 67 time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour |
| 68 chrome.extension.onRequest.removeListener(paramsSetupListener); |
| 69 chrome.extension.onRequest.addListener(testListener); |
| 70 setTimeout(setupTest, 1000); |
| 71 } else { |
| 72 console.log("Error. Test parameters not received."); |
| 73 } |
| 74 } |
| 75 ); |
| 76 |
| 77 |
| 35 | 78 |
| 36 function close_preexisting_windows() { | 79 function close_preexisting_windows() { |
| 37 for (var i = 0; i < preexisting_windows.length; i++) { | 80 for (var i = 0; i < preexisting_windows.length; i++) { |
| 38 chrome.windows.remove(preexisting_windows[i].id); | 81 chrome.windows.remove(preexisting_windows[i].id); |
| 39 } | 82 } |
| 40 preexisting_windows.length = 0; | 83 preexisting_windows.length = 0; |
| 41 } | 84 } |
| 42 | 85 |
| 43 function cycle_navigate(cycle) { | 86 function cycle_navigate(cycle) { |
| 44 cycle_tabs[cycle.id] = cycle; | 87 cycle_tabs[cycle.id] = cycle; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 console.log(post.join("&")); | 169 console.log(post.join("&")); |
| 127 } | 170 } |
| 128 | 171 |
| 129 chrome.windows.getAll(null, function(windows) { | 172 chrome.windows.getAll(null, function(windows) { |
| 130 // delay starting test by short amount of time to allow chromeos | 173 // delay starting test by short amount of time to allow chromeos |
| 131 // login process to settle down | 174 // login process to settle down |
| 132 setTimeout(startTest, test_startup_delay); | 175 setTimeout(startTest, test_startup_delay); |
| 133 }); | 176 }); |
| 134 | 177 |
| 135 function startTest() { | 178 function startTest() { |
| 136 var end = 0; | 179 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 | 180 |
| 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 } | 181 } |
| 150 | 182 |
| 183 // Called when the user clicks on the browser action. |
| 184 chrome.browserAction.onClicked.addListener(function(tab) { |
| 185 // Start the test with default settings. |
| 186 chrome.extension.onRequest.addListener(testListener); |
| 187 setupTest(); |
| 188 }); |
| 189 |
| 151 | 190 |
| 152 </script> | 191 </script> |
| 153 | 192 |
| 154 <body> | 193 <body> |
| 155 </body> | 194 </body> |
| 156 </html> | 195 </html> |
| OLD | NEW |