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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: client/site_tests/power_LoadTest/extension/background.html
diff --git a/client/site_tests/power_LoadTest/extension/background.html b/client/site_tests/power_LoadTest/extension/background.html
index 6155c6413bbbf736a73d9885aea4f23d86326d4b..51ace7018571e0c6f9c999ab7ee3ca51fd17a562 100755
--- a/client/site_tests/power_LoadTest/extension/background.html
+++ b/client/site_tests/power_LoadTest/extension/background.html
@@ -17,8 +17,23 @@ var cycle_tabs = {};
var cycles = {};
var time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour
var preexisting_windows = [];
-
-chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
+
+function setupTest() {
+ chrome.windows.getAll(null, function(windows) {
+ preexisting_windows = windows;
+ var end = 0;
+ for (var i = 0; i < tasks.length; i++) {
+ end = Math.max(end, (tasks[i].start + tasks[i].duration) / time_ratio);
+ setTimeout(launch_task, tasks[i].start / time_ratio, tasks[i]);
+ }
+ setTimeout(send_status, end);
+ // Add a 5sec delay between sending the status back and closing browser
+ // so that status message can reach autotest safely
+ setTimeout(close_browser, end + 5 * 1000);
+ });
+}
+
+function testListener(request, sender, sendResponse) {
if (sender.tab.id in cycle_tabs) {
cycle = cycle_tabs[sender.tab.id];
cycle.successful_loads++;
@@ -31,7 +46,37 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
}
delete cycle_tabs[sender.tab.id];
}
-});
+}
+
+
+chrome.extension.onRequest.addListener(
+ function paramsSetupListener(request, sender) {
+ console.log(sender.tab ?
+ "from a content script:" + sender.tab.url :
+ "from the extension");
Sameer Nanda 2011/02/28 22:11:34 remove logging?
Benson Leung 2011/03/01 02:16:19 Done.
+ if (undefined != request._test_time_ms &&
+ undefined != request._should_scroll &&
+ undefined != request._should_scroll_up &&
+ undefined != request._scroll_loop &&
+ undefined != request._scroll_interval_ms &&
+ undefined != request._scroll_by_pixels) {
+ console.log("test parameters received!");
+ // Update test parameters from content script.
+ test_time_ms = request._test_time_ms;
+ should_scroll = request._should_scroll;
+ should_scroll_up = request._should_scroll_up;
+ scroll_loop = request._scroll_loop;
+ scroll_interval_ms = request._scroll_interval_ms;
+ scroll_by_pixels = request._scroll_by_pixels;
+ time_ratio = 3600 * 1000 / test_time_ms; // default test time is 1 hour
+ chrome.extension.onRequest.removeListener(paramsSetupListener);
+ chrome.extension.onRequest.addListener(testListener);
+ setTimeout(setupTest, 1000);
+ }
Sameer Nanda 2011/02/28 22:11:34 add else clause with error log?
Benson Leung 2011/03/01 02:16:19 Done.
+ }
+);
+
+
function close_preexisting_windows() {
for (var i = 0; i < preexisting_windows.length; i++) {
@@ -133,21 +178,17 @@ chrome.windows.getAll(null, function(windows) {
});
function startTest() {
- var end = 0;
- chrome.windows.getAll(null, function(windows) {
- preexisting_windows = windows;
- });
- for (var i = 0; i < tasks.length; i++) {
- end = Math.max(end, (tasks[i].start + tasks[i].duration) / time_ratio);
- setTimeout(launch_task, tasks[i].start / time_ratio, tasks[i]);
- }
- setTimeout(send_status, end);
+ chrome.windows.create({'url': 'http://localhost:8001/testparams.html'});
- // Add a 5sec delay between sending the status back and closing browser
- // so that status message can reach autotest safely
- setTimeout(close_browser, end + 5 * 1000);
}
+// Called when the user clicks on the browser action.
+chrome.browserAction.onClicked.addListener(function(tab) {
+ // Start the test with default settings.
+ chrome.extension.onRequest.addListener(testListener);
+ setupTest();
+});
+
</script>

Powered by Google App Engine
This is Rietveld 408576698