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