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

Side by Side Diff: chrome/common/extensions/docs/examples/api/record/page_cycler/page_cycler.js

Issue 21854002: Remove experimental.record api completely (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch Created 7 years, 4 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 unified diff | Download patch
OLDNEW
(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 pageCyclerUI = new (function () {
10 var noTestMessage = "N/A -- do Prepare Test";
11
12 this.urlList = [];
13 this.cacheDir = "";
14
15 this.captureTab = $("#capture-tab");
16 this.captureTabLabel = $("#capture-tab-label");
17 this.captureButton = $("#capture-test");
18 this.captureErrorDiv = $("#capture-errors-display");
19 this.captureErrorList = $("#capture-errors");
20
21 this.replayTab = $("#replay-tab");
22 this.replayTabLabel = $("#replay-tab-label");
23 this.replayURLs = $("#replay-urls");
24 this.replayCache = $("#replay-cache-dir");
25 this.replayButton = $("#replay-test");
26 this.replayErrorDiv = $("#replay-errors-display");
27 this.replayErrorList = $("#replay-errors");
28
29 this.replayURLs.innerText = this.replayCache.innerText = noTestMessage;
30
31 this.enableTab = function(tabLabel, tab) {
32 var tabList = document.querySelectorAll(".tab");
33 var tabLabelList = document.querySelectorAll(".tab-label");
34
35 for (var i = 0; i < tabList.length; i++)
36 if (tabList[i] == tab)
37 tabList[i].style.visibility = "visible";
38 else
39 tabList[i].style.visibility = "hidden";
40
41 for (var i = 0; i < tabLabelList.length; i++)
42 if (tabLabelList[i] == tabLabel) {
43 tabLabelList[i].classList.add("enabled-tab-label");
44 tabLabelList[i].classList.remove("disabled-tab-label");
45 } else {
46 tabLabelList[i].classList.remove("enabled-tab-label");
47 tabLabelList[i].classList.add("disabled-tab-label");
48 }
49 }
50
51 this.chooseCapture = function() {
52 this.enableTab(this.captureTabLabel, this.captureTab);
53 }
54
55 this.chooseReplay = function() {
56 this.enableTab(this.replayTabLabel, this.replayTab);
57 }
58
59 this.captureTest = function() {
60 var errorList = $("#capture-errors");
61 var errors = [];
62
63 this.cacheDir = $("#capture-cache-dir").value;
64 this.urlList = $("#capture-urls").value.split("\n");
65
66 if (errors.length > 0) {
67 this.captureErrorList.innerText = errors.join("\n");
68 this.captureErrorDiv.className = "error-list-show";
69 }
70 else {
71 this.captureErrorDiv.className = "error-list-hide";
72 this.captureButton.disabled = true;
73 chrome.experimental.record.captureURLs(this.urlList, this.cacheDir,
74 this.onCaptureDone.bind(this));
75 }
76 }
77
78 this.onCaptureDone = function(errors) {
79
80 this.captureButton.disabled = false;
81 if (errors.length > 0) {
82 this.captureErrorList.innerText = errors.join("\n");
83 this.captureErrorDiv.className = "error-list-show";
84 this.replayButton.disabled = true;
85 this.replayCache.innerText = this.replayURLs.innerText = noTestMessage;
86 }
87 else {
88 this.captureErrorDiv.className = "error-list-hide";
89 this.replayButton.disabled = false;
90 this.replayURLs.innerText = this.urlList.join("\n");
91 this.replayCache.innerText = this.cacheDir;
92 }
93 }
94
95 this.replayTest = function() {
96 var extensionPath = $("#extension-dir").value;
97 var repeatCount = parseInt($('#repeat-count').value);
98 var errors = [];
99
100 // Check local errors
101 if (isNaN(repeatCount))
102 errors.push("Enter a number for repeat count");
103 else if (repeatCount < 1 || repeatCount > 100)
104 errors.push("Repeat count must be between 1 and 100");
105
106 if (errors.length > 0) {
107 this.replayErrorList.innerText = errors.join("\n");
108 this.replayErrorDiv.className = "error-list-show";
109 } else {
110 this.replayErrorDiv.className = "error-list-hide";
111 this.replayButton.disabled = true;
112 chrome.experimental.record.replayURLs(
113 this.urlList,
114 this.cacheDir,
115 repeatCount,
116 {"extensionPath": extensionPath},
117 this.onReplayDone.bind(this));
118 }
119 }
120
121 this.onReplayDone = function(result) {
122 var replayResult = $("#replay-result");
123
124 this.replayButton.disabled = false;
125
126 if (result.errors.length > 0) {
127 this.replayErrorList.innerText = result.errors.join("<br>");
128 this.replayErrorDiv.className = "error-list-show";
129 }
130 else {
131 this.replayErrorDiv.className = "error-list-hide";
132 replayResult.innerText = "Test took " + result.runTime + "mS :\n" +
133 result.stats;
134 }
135 }
136
137 this.captureButton.addEventListener("click", this.captureTest.bind(this));
138 this.replayButton.addEventListener("click", this.replayTest.bind(this));
139 this.captureTabLabel.addEventListener("click", this.chooseCapture.bind(this));
140 this.replayTabLabel.addEventListener("click", this.chooseReplay.bind(this));
141 this.enableTab(this.captureTabLabel, this.captureTab);
142 })();
143
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698