OLD | NEW |
1 <!--- | 1 <!--- |
2 Copyright (c) 2011 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 |
| 9 <script> |
| 10 // Convert seconds to milliseconds |
| 11 function seconds(s) { |
| 12 return s * 1000; |
| 13 } |
| 14 |
| 15 // Convert minutes to milliseconds |
| 16 function minutes(m) { |
| 17 return seconds(m * 60); |
| 18 } |
| 19 </script> |
| 20 |
8 <script src='/urls.js'> | 21 <script src='/urls.js'> |
9 </script> | 22 </script> |
10 | 23 |
11 <script src='/params.js'> | 24 <script src='/params.js'> |
12 </script> | 25 </script> |
13 | 26 |
14 <script> | 27 <script> |
15 | 28 |
16 var cycle_tabs = {}; | 29 var cycle_tabs = {}; |
17 var cycles = {}; | 30 var cycles = {}; |
(...skipping 23 matching lines...) Expand all Loading... |
41 sendResponse({"should_scroll": should_scroll, | 54 sendResponse({"should_scroll": should_scroll, |
42 "should_scroll_up": should_scroll_up, | 55 "should_scroll_up": should_scroll_up, |
43 "scroll_loop": scroll_loop, | 56 "scroll_loop": scroll_loop, |
44 "scroll_interval": scroll_interval_ms, | 57 "scroll_interval": scroll_interval_ms, |
45 "scroll_by": scroll_by_pixels}); | 58 "scroll_by": scroll_by_pixels}); |
46 } | 59 } |
47 delete cycle_tabs[sender.tab.id]; | 60 delete cycle_tabs[sender.tab.id]; |
48 } | 61 } |
49 } | 62 } |
50 | 63 |
| 64 function parseTaskList(tasks_string) { |
| 65 if (tasks_string == '') |
| 66 return []; |
| 67 var task_strings = tasks_string.split('+'); |
| 68 var task_list = []; |
| 69 var time = 0; |
| 70 |
| 71 // Parse each task. |
| 72 for (var i in task_strings) { |
| 73 // Extract task parameters. |
| 74 var params = task_strings[i].split(';'); |
| 75 var cmd = params[0]; |
| 76 var urls = params[1].split(','); |
| 77 var duration = seconds(parseInt(params[2])); |
| 78 if (params.length > 3) |
| 79 var delay = seconds(parseInt(params[3])); |
| 80 |
| 81 if (cmd == 'window') { |
| 82 task_list.push( { type: 'window', |
| 83 start: time, |
| 84 duration: duration, |
| 85 focus: true, |
| 86 tabs: urls } ); |
| 87 } |
| 88 else if (cmd == 'cycle') { |
| 89 task_list.push( { type: 'cycle', |
| 90 start: time, |
| 91 duration: duration, |
| 92 delay: delay, |
| 93 timeout: seconds(10), |
| 94 focus: true, |
| 95 urls: urls } ); |
| 96 } |
| 97 // Increment the time to determine the start time of the next task. |
| 98 time += duration; |
| 99 } |
| 100 return task_list; |
| 101 } |
| 102 |
| 103 var task_list = []; |
51 | 104 |
52 chrome.extension.onRequest.addListener( | 105 chrome.extension.onRequest.addListener( |
53 function paramsSetupListener(request, sender) { | 106 function paramsSetupListener(request, sender) { |
54 if (undefined != request._test_time_ms && | 107 if (undefined != request._test_time_ms && |
55 undefined != request._should_scroll && | 108 undefined != request._should_scroll && |
56 undefined != request._should_scroll_up && | 109 undefined != request._should_scroll_up && |
57 undefined != request._scroll_loop && | 110 undefined != request._scroll_loop && |
58 undefined != request._scroll_interval_ms && | 111 undefined != request._scroll_interval_ms && |
59 undefined != request._scroll_by_pixels) { | 112 undefined != request._scroll_by_pixels && |
| 113 undefined != request._tasks) { |
60 // Update test parameters from content script. | 114 // Update test parameters from content script. |
61 test_time_ms = request._test_time_ms; | 115 test_time_ms = request._test_time_ms; |
62 should_scroll = request._should_scroll; | 116 should_scroll = request._should_scroll; |
63 should_scroll_up = request._should_scroll_up; | 117 should_scroll_up = request._should_scroll_up; |
64 scroll_loop = request._scroll_loop; | 118 scroll_loop = request._scroll_loop; |
65 scroll_interval_ms = request._scroll_interval_ms; | 119 scroll_interval_ms = request._scroll_interval_ms; |
66 scroll_by_pixels = request._scroll_by_pixels; | 120 scroll_by_pixels = request._scroll_by_pixels; |
| 121 task_list = parseTaskList(request._tasks); |
| 122 if (task_list.length != 0) |
| 123 tasks = task_list; |
67 time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour | 124 time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour |
68 chrome.extension.onRequest.removeListener(paramsSetupListener); | 125 chrome.extension.onRequest.removeListener(paramsSetupListener); |
69 chrome.extension.onRequest.addListener(testListener); | 126 chrome.extension.onRequest.addListener(testListener); |
70 setTimeout(setupTest, 1000); | 127 setTimeout(setupTest, 1000); |
71 } else { | 128 } else { |
72 console.log("Error. Test parameters not received."); | 129 console.log("Error. Test parameters not received."); |
73 } | 130 } |
74 } | 131 } |
75 ); | 132 ); |
76 | 133 |
77 | 134 |
78 | 135 |
79 function close_preexisting_windows() { | 136 function close_preexisting_windows() { |
80 for (var i = 0; i < preexisting_windows.length; i++) { | 137 for (var i = 0; i < preexisting_windows.length; i++) { |
81 chrome.windows.remove(preexisting_windows[i].id); | 138 chrome.windows.remove(preexisting_windows[i].id); |
82 } | 139 } |
83 preexisting_windows.length = 0; | 140 preexisting_windows.length = 0; |
84 } | 141 } |
85 | 142 |
86 function cycle_navigate(cycle) { | 143 function cycle_navigate(cycle) { |
87 cycle_tabs[cycle.id] = cycle; | 144 cycle_tabs[cycle.id] = cycle; |
88 var url = cycle.urls[cycle.idx]; | 145 var url = cycle.urls[cycle.idx]; |
89 chrome.tabs.update(cycle.id, {'url': url, 'selected': true}); | 146 chrome.tabs.update(cycle.id, {'url': url, 'selected': true}); |
90 cycle.idx = (cycle.idx + 1) % cycle.urls.length; | 147 cycle.idx = (cycle.idx + 1) % cycle.urls.length; |
91 if (cycle.timeout < cycle.delay && cycle.timeout > 0) { | 148 if (cycle.timeout < cycle.delay / time_ratio && cycle.timeout > 0) { |
92 cycle.timer = setTimeout(cycle_check_timeout, cycle.timeout, cycle); | 149 cycle.timer = setTimeout(cycle_check_timeout, cycle.timeout, cycle); |
93 } else { | 150 } else { |
94 cycle.timer = setTimeout(cycle_navigate, cycle.delay, cycle); | 151 cycle.timer = setTimeout(cycle_navigate, cycle.delay / time_ratio, cycle); |
95 } | 152 } |
96 } | 153 } |
97 | 154 |
98 function cycle_check_timeout(cycle) { | 155 function cycle_check_timeout(cycle) { |
99 if (cycle.id in cycle_tabs) { | 156 if (cycle.id in cycle_tabs) { |
100 cycle.failed_loads++; | 157 cycle.failed_loads++; |
101 cycle_navigate(cycle); | 158 cycle_navigate(cycle); |
102 } else { | 159 } else { |
103 cycle.timer = setTimeout(cycle_navigate, cycle.delay - cycle.timeout, | 160 cycle.timer = setTimeout(cycle_navigate, |
| 161 cycle.delay / time_ratio - cycle.timeout, |
104 cycle); | 162 cycle); |
105 } | 163 } |
106 } | 164 } |
107 | 165 |
108 function launch_task(task) { | 166 function launch_task(task) { |
109 if (task.type == 'window' && task.tabs) { | 167 if (task.type == 'window' && task.tabs) { |
110 chrome.windows.create({'url': 'about:blank'}, function (win) { | 168 chrome.windows.create({'url': 'about:blank'}, function (win) { |
111 close_preexisting_windows(); | 169 close_preexisting_windows(); |
112 chrome.tabs.getSelected(win.id, function(tab) { | 170 chrome.tabs.getSelected(win.id, function(tab) { |
113 chrome.tabs.update(tab.id, {'url': task.tabs[0], 'selected': true}); | 171 chrome.tabs.update(tab.id, {'url': task.tabs[0], 'selected': true}); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 chrome.extension.onRequest.addListener(testListener); | 244 chrome.extension.onRequest.addListener(testListener); |
187 setupTest(); | 245 setupTest(); |
188 }); | 246 }); |
189 | 247 |
190 | 248 |
191 </script> | 249 </script> |
192 | 250 |
193 <body> | 251 <body> |
194 </body> | 252 </body> |
195 </html> | 253 </html> |
OLD | NEW |