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

Side by Side Diff: chrome/browser/extensions/extension_record_api.cc

Issue 10386134: Record API fix adding FirstRun, and allowing repeat-count in capture (plus some browsertests along … (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes for latest review (master merged) Created 8 years, 6 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
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 #include "chrome/browser/extensions/extension_record_api.h" 5 #include "chrome/browser/extensions/extension_record_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_split.h" 14 #include "base/string_split.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 17
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/api/experimental_record.h" 19 #include "chrome/common/extensions/api/experimental_record.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 22
23 namespace record = extensions::api::experimental_record; 23 namespace record = extensions::api::experimental_record;
24 24
25 const FilePath::CharType kFirstRunFile[] = FILE_PATH_LITERAL("First Run");
26
25 ProcessStrategy::~ProcessStrategy() {} 27 ProcessStrategy::~ProcessStrategy() {}
26 28
27 void ProductionProcessStrategy::RunProcess(const CommandLine& line) { 29 void ProductionProcessStrategy::RunProcess(const CommandLine& line) {
28 base::LaunchOptions options; 30 base::LaunchOptions options;
29 31
30 options.wait = true; 32 options.wait = true;
31 base::LaunchProcess(line, options, NULL); 33 base::LaunchProcess(line, options, NULL);
32 } 34 }
33 35
34 RunPageCyclerFunction::RunPageCyclerFunction(ProcessStrategy* strategy) 36 RunPageCyclerFunction::RunPageCyclerFunction(ProcessStrategy* strategy)
35 : base_command_line_(*CommandLine::ForCurrentProcess()), 37 : repeat_count_(1), base_command_line_(*CommandLine::ForCurrentProcess()),
36 process_strategy_(strategy) {} 38 process_strategy_(strategy) {}
37 39
38 RunPageCyclerFunction::~RunPageCyclerFunction() {} 40 RunPageCyclerFunction::~RunPageCyclerFunction() {}
39 41
40 bool RunPageCyclerFunction::RunImpl() { 42 bool RunPageCyclerFunction::RunImpl() {
41 if (!ParseJSParameters()) 43 if (!ParseJSParameters())
42 return false; 44 return false;
43 45
44 // If we've had any errors reportable to the JS caller so far (in 46 // If we've had any errors reportable to the JS caller so far (in
45 // parameter parsing) then return a list of such errors, else perform 47 // parameter parsing) then return a list of such errors, else perform
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 remove_switches.push_back(switches::kVisitURLsCount); 91 remove_switches.push_back(switches::kVisitURLsCount);
90 remove_switches.push_back(switches::kPlaybackMode); 92 remove_switches.push_back(switches::kPlaybackMode);
91 remove_switches.push_back(switches::kRecordStats); 93 remove_switches.push_back(switches::kRecordStats);
92 remove_switches.push_back(switches::kLoadExtension); 94 remove_switches.push_back(switches::kLoadExtension);
93 95
94 CommandLine line = RemoveSwitches(base_command_line_, remove_switches); 96 CommandLine line = RemoveSwitches(base_command_line_, remove_switches);
95 97
96 // Add the user-data-dir switch, since this is common to both call types. 98 // Add the user-data-dir switch, since this is common to both call types.
97 line.AppendSwitchPath(switches::kUserDataDir, user_data_dir_); 99 line.AppendSwitchPath(switches::kUserDataDir, user_data_dir_);
98 100
101 // Test browsers must run as if they are not in first-run mode, so if
102 // user_data_dir_ doesn't exist, create it and insert "First Run" file
103 line.AppendSwitch(switches::kNoFirstRun);
104
105 /*
Aaron Boodman 2012/06/05 04:17:04 Kill dead code.
106 if (!file_util::PathExists(user_data_dir_)) {
107 file_util::CreateDirectory(user_data_dir_);
108 FilePath firstRunFilePath
109 = user_data_dir_.Append(FilePath::StringType(kFirstRunFile));
110 file_util::WriteFile(firstRunFilePath, "", 0);
111 }
112 */
113
99 // Do the same for visit-urls, creating a temp file to communicate the 114 // Do the same for visit-urls, creating a temp file to communicate the
100 // URL list to the test browser. 115 // URL list to the test browser.
101 FilePath url_path; 116 FilePath url_path;
102 file_util::CreateTemporaryFile(&url_path); 117 file_util::CreateTemporaryFile(&url_path);
103 file_util::WriteFile(url_path, url_contents_.c_str(), url_contents_.size()); 118 file_util::WriteFile(url_path, url_contents_.c_str(), url_contents_.size());
104 line.AppendSwitchPath(switches::kVisitURLs, url_path); 119 line.AppendSwitchPath(switches::kVisitURLs, url_path);
105 120
106 // Set up Capture- or Replay-specific commandline switches. 121 // Set up Capture- or Replay-specific commandline switches.
107 AddSwitches(&line); 122 AddSwitches(&line);
108 LOG(ERROR) << "Test browser commandline: " << line.GetCommandLineString(); 123 LOG(ERROR) << "Test browser commandline: " << line.GetCommandLineString();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 163
149 // Fetch data for possible optional switches for a repeat count and an 164 // Fetch data for possible optional switches for a repeat count and an
150 // extension to load. 165 // extension to load.
151 bool CaptureURLsFunction::ParseJSParameters() { 166 bool CaptureURLsFunction::ParseJSParameters() {
152 scoped_ptr<record::CaptureURLs::Params> params( 167 scoped_ptr<record::CaptureURLs::Params> params(
153 record::CaptureURLs::Params::Create(*args_)); 168 record::CaptureURLs::Params::Create(*args_));
154 EXTENSION_FUNCTION_VALIDATE(params.get()); 169 EXTENSION_FUNCTION_VALIDATE(params.get());
155 170
156 url_contents_ = JoinString(params->urls, '\n'); 171 url_contents_ = JoinString(params->urls, '\n');
157 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path); 172 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path);
173 repeat_count_ = params->repeat_count;
158 174
159 return true; 175 return true;
160 } 176 }
161 177
162 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns 178 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns
163 // just the (possibly empty) error list. 179 // just the (possibly empty) error list.
164 void CaptureURLsFunction::AddSwitches(CommandLine* line) { 180 void CaptureURLsFunction::AddSwitches(CommandLine* line) {
181 line->AppendSwitchASCII(switches::kVisitURLsCount,
182 base::Int64ToString(repeat_count_));
183
165 if (!line->HasSwitch(switches::kRecordMode)) 184 if (!line->HasSwitch(switches::kRecordMode))
166 line->AppendSwitch(switches::kRecordMode); 185 line->AppendSwitch(switches::kRecordMode);
167 } 186 }
168 187
169 void CaptureURLsFunction::Finish() { 188 void CaptureURLsFunction::Finish() {
170 result_.reset(record::CaptureURLs::Result::Create(errors_)); 189 result_.reset(record::CaptureURLs::Result::Create(errors_));
171 SendResponse(true); 190 SendResponse(true);
172 } 191 }
173 192
174 193
175 // ReplayURLsFunction ------------------------------------------------ 194 // ReplayURLsFunction ------------------------------------------------
176 195
177 ReplayURLsFunction::ReplayURLsFunction() 196 ReplayURLsFunction::ReplayURLsFunction()
178 : RunPageCyclerFunction(new ProductionProcessStrategy()), 197 : RunPageCyclerFunction(new ProductionProcessStrategy()),
179 repeat_count_(1), run_time_ms_(0) { 198 run_time_ms_(0) {
180 } 199 }
181 200
182 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) 201 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy)
183 : RunPageCyclerFunction(strategy), 202 : RunPageCyclerFunction(strategy), run_time_ms_(0) {
184 repeat_count_(1), run_time_ms_(0) {
185 } 203 }
186 204
187 ReplayURLsFunction::~ReplayURLsFunction() {} 205 ReplayURLsFunction::~ReplayURLsFunction() {}
188 206
189 // Fetch data for possible optional switches for a repeat count and an 207 // Fetch data for possible optional switches for a repeat count and an
190 // extension to load. 208 // extension to load.
191 bool ReplayURLsFunction::ParseJSParameters() { 209 bool ReplayURLsFunction::ParseJSParameters() {
192 scoped_ptr<record::ReplayURLs::Params> params( 210 scoped_ptr<record::ReplayURLs::Params> params(
193 record::ReplayURLs::Params::Create(*args_)); 211 record::ReplayURLs::Params::Create(*args_));
194 EXTENSION_FUNCTION_VALIDATE(params.get()); 212 EXTENSION_FUNCTION_VALIDATE(params.get());
195 213
196 url_contents_ = JoinString(params->urls, '\n'); 214 url_contents_ = JoinString(params->urls, '\n');
197 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path); 215 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path);
216 repeat_count_ = params->repeat_count;
198 217
199 if (params->details.get()) { 218 if (params->details.get()) {
200 if (params->details->repeat_count.get())
201 repeat_count_ = *params->details->repeat_count;
202 if (params->details->extension_path.get()) 219 if (params->details->extension_path.get())
203 extension_path_ = 220 extension_path_ =
204 FilePath::FromUTF8Unsafe(*params->details->extension_path); 221 FilePath::FromUTF8Unsafe(*params->details->extension_path);
205 } 222 }
206 223
207 return true; 224 return true;
208 } 225 }
209 226
210 // Add special switches, if indicated, for repeat count and extension to load, 227 // Add special switches, if indicated, for repeat count and extension to load,
211 // plus temp file into which to place stats. (Can't do this in 228 // plus temp file into which to place stats. (Can't do this in
(...skipping 23 matching lines...) Expand all
235 record::ReplayURLsResult result; 252 record::ReplayURLsResult result;
236 253
237 result.run_time = run_time_ms_; 254 result.run_time = run_time_ms_;
238 result.stats = stats_; 255 result.stats = stats_;
239 result.errors = errors_; 256 result.errors = errors_;
240 257
241 result_.reset(record::ReplayURLs::Result::Create(result)); 258 result_.reset(record::ReplayURLs::Result::Create(result));
242 SendResponse(true); 259 SendResponse(true);
243 } 260 }
244 261
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698