| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function $(criterion) { | 5 function $(criterion) { |
| 6 return document.querySelector(criterion); | 6 return document.querySelector(criterion); |
| 7 } | 7 } |
| 8 | 8 |
| 9 var pageCyclerUI = new (function () { | 9 var cyclerUI = new (function () { |
| 10 var noTestMessage = "N/A -- do Prepare Test"; | |
| 11 | |
| 12 this.urlList = []; | 10 this.urlList = []; |
| 13 this.cacheDir = ""; | 11 this.cacheDir = ""; |
| 14 | 12 |
| 15 this.captureTab = $("#capture-tab"); | 13 this.captureTab = $("#capture-tab"); |
| 16 this.captureTabLabel = $("#capture-tab-label"); | 14 this.captureTabLabel = $("#capture-tab-label"); |
| 17 this.captureButton = $("#capture-test"); | 15 this.captureButton = $("#capture-test"); |
| 18 this.captureErrorDiv = $("#capture-errors-display"); | 16 this.captureErrorDiv = $("#capture-errors-display"); |
| 19 this.captureErrorList = $("#capture-errors"); | 17 this.captureErrorList = $("#capture-errors"); |
| 20 | 18 |
| 21 this.replayTab = $("#replay-tab"); | 19 this.playbackTab = $("#playback-tab"); |
| 22 this.replayTabLabel = $("#replay-tab-label"); | 20 this.playbackTabLabel = $("#playback-tab-label"); |
| 23 this.replayURLs = $("#replay-urls"); | 21 this.playbackURLs = $("#playback-urls"); |
| 24 this.replayCache = $("#replay-cache-dir"); | 22 this.playbackCache = $("#playback-cache-dir"); |
| 25 this.replayButton = $("#replay-test"); | 23 this.playbackButton = $("#playback-test"); |
| 26 this.replayErrorDiv = $("#replay-errors-display"); | 24 this.playbackErrorDiv = $("#playback-errors-display"); |
| 27 this.replayErrorList = $("#replay-errors"); | 25 this.playbackErrorList = $("#playback-errors"); |
| 28 | 26 |
| 29 this.replayURLs.innerText = this.replayCache.innerText = noTestMessage; | 27 this.playbackURLs.innerText = this.playbackCache.innerText = noTestMessage; |
| 30 | 28 |
| 31 this.enableTab = function(tabLabel, tab) { | 29 this.enableTab = function(tabLabel, tab) { |
| 32 var tabList = document.querySelectorAll(".tab"); | 30 var tabList = document.querySelectorAll(".tab"); |
| 33 var tabLabelList = document.querySelectorAll(".tab-label"); | 31 var tabLabelList = document.querySelectorAll(".tab-label"); |
| 34 | 32 |
| 35 for (var i = 0; i < tabList.length; i++) | 33 for (var i = 0; i < tabList.length; i++) |
| 36 if (tabList[i] == tab) | 34 if (tabList[i] == tab) |
| 37 tabList[i].style.visibility = "visible"; | 35 tabList[i].style.visibility = "visible"; |
| 38 else | 36 else |
| 39 tabList[i].style.visibility = "hidden"; | 37 tabList[i].style.visibility = "hidden"; |
| 40 | 38 |
| 41 for (var i = 0; i < tabLabelList.length; i++) | 39 for (var i = 0; i < tabLabelList.length; i++) |
| 42 if (tabLabelList[i] == tabLabel) { | 40 if (tabLabelList[i] == tabLabel) { |
| 43 tabLabelList[i].classList.add("enabled-tab-label"); | 41 tabLabelList[i].classList.add("enabled-tab-label"); |
| 44 tabLabelList[i].classList.remove("disabled-tab-label"); | 42 tabLabelList[i].classList.remove("disabled-tab-label"); |
| 45 } else { | 43 } else { |
| 46 tabLabelList[i].classList.remove("enabled-tab-label"); | 44 tabLabelList[i].classList.remove("enabled-tab-label"); |
| 47 tabLabelList[i].classList.add("disabled-tab-label"); | 45 tabLabelList[i].classList.add("disabled-tab-label"); |
| 48 } | 46 } |
| 49 } | 47 } |
| 50 | 48 |
| 51 this.chooseCapture = function() { | 49 this.chooseCapture = function() { |
| 52 this.enableTab(this.captureTabLabel, this.captureTab); | 50 this.enableTab(this.captureTabLabel, this.captureTab); |
| 53 } | 51 } |
| 54 | 52 |
| 55 this.chooseReplay = function() { | 53 this.chooseReplay = function() { |
| 56 this.enableTab(this.replayTabLabel, this.replayTab); | 54 this.enableTab(this.playbackTabLabel, this.playbackTab); |
| 57 } | 55 } |
| 58 | 56 |
| 59 this.captureTest = function() { | 57 this.captureTest = function() { |
| 60 var errorList = $("#capture-errors"); | 58 var errorList = $("#capture-errors"); |
| 61 var errors = []; | 59 var errors = []; |
| 62 | 60 |
| 63 this.cacheDir = $("#capture-cache-dir").value; | 61 this.cacheDir = $("#capture-cache-dir").value; |
| 64 this.urlList = $("#capture-urls").value.split("\n"); | 62 this.urlList = $("#capture-urls").value.split("\n"); |
| 65 | 63 |
| 66 if (errors.length > 0) { | 64 if (errors.length > 0) { |
| 67 this.captureErrorList.innerText = errors.join("\n"); | 65 this.captureErrorList.innerText = errors.join("\n"); |
| 68 this.captureErrorDiv.className = "error-list-show"; | 66 this.captureErrorDiv.className = "error-list-show"; |
| 69 } | 67 } |
| 70 else { | 68 else { |
| 71 this.captureErrorDiv.className = "error-list-hide"; | 69 this.captureErrorDiv.className = "error-list-hide"; |
| 72 this.captureButton.disabled = true; | 70 this.captureButton.disabled = true; |
| 73 chrome.experimental.record.captureURLs(this.urlList, this.cacheDir, | 71 chrome.experimental.record.captureURLs(this.urlList, this.cacheDir, |
| 74 this.onCaptureDone.bind(this)); | 72 this.onCaptureDone.bind(this)); |
| 75 } | 73 } |
| 76 } | 74 } |
| 77 | 75 |
| 78 this.onCaptureDone = function(errors) { | 76 this.onCaptureDone = function(errors) { |
| 79 | 77 |
| 80 this.captureButton.disabled = false; | 78 this.captureButton.disabled = false; |
| 81 if (errors.length > 0) { | 79 if (errors.length > 0) { |
| 82 this.captureErrorList.innerText = errors.join("\n"); | 80 this.captureErrorList.innerText = errors.join("\n"); |
| 83 this.captureErrorDiv.className = "error-list-show"; | 81 this.captureErrorDiv.className = "error-list-show"; |
| 84 this.replayButton.disabled = true; | 82 this.playbackButton.disabled = true; |
| 85 this.replayCache.innerText = this.replayURLs.innerText = noTestMessage; | 83 this.playbackCache.innerText = this.playbackURLs.innerText = |
| 84 noTestMessage; |
| 86 } | 85 } |
| 87 else { | 86 else { |
| 88 this.captureErrorDiv.className = "error-list-hide"; | 87 this.captureErrorDiv.className = "error-list-hide"; |
| 89 this.replayButton.disabled = false; | 88 this.playbackButton.disabled = false; |
| 90 this.replayURLs.innerText = this.urlList.join("\n"); | 89 this.playbackURLs.innerText = this.urlList.join("\n"); |
| 91 this.replayCache.innerText = this.cacheDir; | 90 this.playbackCache.innerText = this.cacheDir; |
| 92 } | 91 } |
| 93 } | 92 } |
| 94 | 93 |
| 95 this.replayTest = function() { | 94 this.playbackTest = function() { |
| 96 var extensionPath = $("#extension-dir").value; | 95 var extensionPath = $("#extension-dir").value; |
| 97 var repeatCount = parseInt($('#repeat-count').value); | 96 var repeatCount = parseInt($('#repeat-count').value); |
| 98 var errors = []; | 97 var errors = []; |
| 99 | 98 |
| 100 // Check local errors | 99 // Check local errors |
| 101 if (isNaN(repeatCount)) | 100 if (isNaN(repeatCount)) |
| 102 errors.push("Enter a number for repeat count"); | 101 errors.push("Enter a number for repeat count"); |
| 103 else if (repeatCount < 1 || repeatCount > 100) | 102 else if (repeatCount < 1 || repeatCount > 100) |
| 104 errors.push("Repeat count must be between 1 and 100"); | 103 errors.push("Repeat count must be between 1 and 100"); |
| 105 | 104 |
| 106 if (errors.length > 0) { | 105 if (errors.length > 0) { |
| 107 this.replayErrorList.innerText = errors.join("\n"); | 106 this.playbackErrorList.innerText = errors.join("\n"); |
| 108 this.replayErrorDiv.className = "error-list-show"; | 107 this.playbackErrorDiv.className = "error-list-show"; |
| 109 } else { | 108 } else { |
| 110 this.replayErrorDiv.className = "error-list-hide"; | 109 this.playbackErrorDiv.className = "error-list-hide"; |
| 111 this.replayButton.disabled = true; | 110 this.playbackButton.disabled = true; |
| 112 chrome.experimental.record.replayURLs( | 111 chrome.experimental.record.playbackURLs( |
| 113 this.urlList, | 112 this.urlList, |
| 114 this.cacheDir, | 113 this.cacheDir, |
| 115 repeatCount, | 114 repeatCount, |
| 116 {"extensionPath": extensionPath}, | 115 {"extensionPath": extensionPath}, |
| 117 this.onReplayDone.bind(this)); | 116 this.onReplayDone.bind(this)); |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 | 119 |
| 121 this.onReplayDone = function(result) { | 120 this.onReplayDone = function(result) { |
| 122 var replayResult = $("#replay-result"); | 121 var playbackResult = $("#playback-result"); |
| 123 | 122 |
| 124 this.replayButton.disabled = false; | 123 this.playbackButton.disabled = false; |
| 125 | 124 |
| 126 if (result.errors.length > 0) { | 125 if (result.errors.length > 0) { |
| 127 this.replayErrorList.innerText = result.errors.join("<br>"); | 126 this.playbackErrorList.innerText = result.errors.join("<br>"); |
| 128 this.replayErrorDiv.className = "error-list-show"; | 127 this.playbackErrorDiv.className = "error-list-show"; |
| 129 } | 128 } |
| 130 else { | 129 else { |
| 131 this.replayErrorDiv.className = "error-list-hide"; | 130 this.playbackErrorDiv.className = "error-list-hide"; |
| 132 replayResult.innerText = "Test took " + result.runTime + "mS :\n" + | 131 playbackResult.innerText = "Test took " + result.runTime + "mS :\n" + |
| 133 result.stats; | 132 result.stats; |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 this.captureButton.addEventListener("click", this.captureTest.bind(this)); | 136 this.captureButton.addEventListener("click", this.captureTest.bind(this)); |
| 138 this.replayButton.addEventListener("click", this.replayTest.bind(this)); | 137 this.playbackButton.addEventListener("click", this.playbackTest.bind(this)); |
| 139 this.captureTabLabel.addEventListener("click", this.chooseCapture.bind(this)); | 138 this.captureTabLabel.addEventListener("click", this.chooseCapture.bind(this)); |
| 140 this.replayTabLabel.addEventListener("click", this.chooseReplay.bind(this)); | 139 this.playbackTabLabel.addEventListener("click", this.chooseReplay.bind(this)); |
| 141 this.enableTab(this.captureTabLabel, this.captureTab); | 140 this.enableTab(this.captureTabLabel, this.captureTab); |
| 142 })(); | 141 })(); |
| 143 | 142 |
| OLD | NEW |