| 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 #include "chrome/browser/extensions/api/record/record_api.h" | 5 #include "chrome/browser/extensions/api/record/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" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Create and fill a temp file to communicate the URL list to the test | 109 // Create and fill a temp file to communicate the URL list to the test |
| 110 // browser. | 110 // browser. |
| 111 FilePath url_path; | 111 FilePath url_path; |
| 112 file_util::CreateTemporaryFile(&url_path); | 112 file_util::CreateTemporaryFile(&url_path); |
| 113 file_util::WriteFile(url_path, url_contents_.c_str(), url_contents_.size()); | 113 file_util::WriteFile(url_path, url_contents_.c_str(), url_contents_.size()); |
| 114 line.AppendSwitchPath(switches::kVisitURLs, url_path); | 114 line.AppendSwitchPath(switches::kVisitURLs, url_path); |
| 115 | 115 |
| 116 // Set up Capture- or Replay-specific commandline switches. | 116 // Set up Capture- or Replay-specific commandline switches. |
| 117 AddSwitches(&line); | 117 AddSwitches(&line); |
| 118 | 118 |
| 119 FilePath error_file_path = url_path.DirName() | 119 FilePath error_file_path = url_path.DirName(). |
| 120 .Append(url_path.BaseName().value() + | 120 Append(url_path.BaseName().value() + |
| 121 FilePath::StringType(kURLErrorsSuffix)); | 121 FilePath::StringType(kURLErrorsSuffix)); |
| 122 | 122 |
| 123 LOG(ERROR) << "Test browser commandline: " << line.GetCommandLineString() << | 123 LOG(ERROR) << "Test browser commandline: " << line.GetCommandLineString() << |
| 124 " will be repeated " << repeat_count_ << " times...."; | 124 " will be repeated " << repeat_count_ << " times...."; |
| 125 | 125 |
| 126 // Run the test browser (or a mockup, depending on |process_strategy_|. | 126 // Run the test browser (or a mockup, depending on |process_strategy_|. |
| 127 while (repeat_count_-- && errors_.empty() && | 127 while (repeat_count_-- && errors_.empty() && |
| 128 !file_util::PathExists(error_file_path)) | 128 !file_util::PathExists(error_file_path)) |
| 129 process_strategy_->RunProcess(line, &errors_); | 129 process_strategy_->RunProcess(line, &errors_); |
| 130 | 130 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 160 CaptureURLsFunction::CaptureURLsFunction(ProcessStrategy* strategy) | 160 CaptureURLsFunction::CaptureURLsFunction(ProcessStrategy* strategy) |
| 161 : RunPageCyclerFunction(strategy) {} | 161 : RunPageCyclerFunction(strategy) {} |
| 162 | 162 |
| 163 // Fetch data for possible optional switch for an extension to load. | 163 // Fetch data for possible optional switch for an extension to load. |
| 164 bool CaptureURLsFunction::ParseJSParameters() { | 164 bool CaptureURLsFunction::ParseJSParameters() { |
| 165 scoped_ptr<record::CaptureURLs::Params> params( | 165 scoped_ptr<record::CaptureURLs::Params> params( |
| 166 record::CaptureURLs::Params::Create(*args_)); | 166 record::CaptureURLs::Params::Create(*args_)); |
| 167 EXTENSION_FUNCTION_VALIDATE(params.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 168 | 168 |
| 169 url_contents_ = JoinString(params->urls, '\n'); | 169 url_contents_ = JoinString(params->urls, '\n'); |
| 170 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path); | 170 // TODO(cstaley): Can't just use captureName -- gotta stick it in a temp dir. |
| 171 // TODO(cstaley): Ensure that capture name is suitable as directory name. |
| 172 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); |
| 171 | 173 |
| 172 return true; | 174 return true; |
| 173 } | 175 } |
| 174 | 176 |
| 175 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns | 177 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns |
| 176 // just the (possibly empty) error list. | 178 // just the (possibly empty) error list. |
| 177 void CaptureURLsFunction::AddSwitches(CommandLine* line) { | 179 void CaptureURLsFunction::AddSwitches(CommandLine* line) { |
| 178 if (!line->HasSwitch(switches::kRecordMode)) | 180 if (!line->HasSwitch(switches::kRecordMode)) |
| 179 line->AppendSwitch(switches::kRecordMode); | 181 line->AppendSwitch(switches::kRecordMode); |
| 180 } | 182 } |
| 181 | 183 |
| 182 void CaptureURLsFunction::Finish() { | 184 void CaptureURLsFunction::Finish() { |
| 183 results_ = record::CaptureURLs::Results::Create(errors_); | 185 results_ = record::CaptureURLs::Results::Create(errors_); |
| 184 SendResponse(true); | 186 SendResponse(true); |
| 185 } | 187 } |
| 186 | 188 |
| 187 | |
| 188 // ReplayURLsFunction ------------------------------------------------ | 189 // ReplayURLsFunction ------------------------------------------------ |
| 189 | 190 |
| 190 ReplayURLsFunction::ReplayURLsFunction() | 191 ReplayURLsFunction::ReplayURLsFunction() |
| 191 : RunPageCyclerFunction(new ProductionProcessStrategy()), | 192 : RunPageCyclerFunction(new ProductionProcessStrategy()), |
| 192 run_time_ms_(0) { | 193 run_time_ms_(0.0) { |
| 193 } | 194 } |
| 194 | 195 |
| 195 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) | 196 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) |
| 196 : RunPageCyclerFunction(strategy), run_time_ms_(0) { | 197 : RunPageCyclerFunction(strategy), run_time_ms_(0.0) { |
| 197 } | 198 } |
| 198 | 199 |
| 199 ReplayURLsFunction::~ReplayURLsFunction() {} | 200 ReplayURLsFunction::~ReplayURLsFunction() {} |
| 200 | 201 |
| 201 // Fetch data for possible optional switches for a repeat count and an | 202 // Fetch data for possible optional switches for a repeat count and an |
| 202 // extension to load. | 203 // extension to load. |
| 203 bool ReplayURLsFunction::ParseJSParameters() { | 204 bool ReplayURLsFunction::ParseJSParameters() { |
| 204 scoped_ptr<record::ReplayURLs::Params> params( | 205 scoped_ptr<record::ReplayURLs::Params> params( |
| 205 record::ReplayURLs::Params::Create(*args_)); | 206 record::ReplayURLs::Params::Create(*args_)); |
| 206 EXTENSION_FUNCTION_VALIDATE(params.get()); | 207 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 207 | 208 |
| 208 url_contents_ = JoinString(params->urls, '\n'); | 209 |
| 209 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path); | 210 // TODO(cstaley): Must build full temp dir from capture_name |
| 211 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); |
| 212 |
| 213 // TODO(cstaley): Get this from user data dir ultimately |
| 214 url_contents_ = "http://www.google.com\nhttp://www.amazon.com"; |
| 215 |
| 210 repeat_count_ = params->repeat_count; | 216 repeat_count_ = params->repeat_count; |
| 211 | 217 |
| 212 if (params->details.get()) { | 218 if (params->details.get()) { |
| 213 if (params->details->extension_path.get()) | 219 if (params->details->extension_path.get()) |
| 214 extension_path_ = | 220 extension_path_ = |
| 215 FilePath::FromUTF8Unsafe(*params->details->extension_path); | 221 FilePath::FromUTF8Unsafe(*params->details->extension_path); |
| 216 } | 222 } |
| 217 | 223 |
| 218 return true; | 224 return true; |
| 219 } | 225 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 230 line->AppendSwitch(switches::kPlaybackMode); | 236 line->AppendSwitch(switches::kPlaybackMode); |
| 231 line->AppendSwitchPath(switches::kRecordStats, stats_file_path_); | 237 line->AppendSwitchPath(switches::kRecordStats, stats_file_path_); |
| 232 | 238 |
| 233 timer_ = base::Time::NowFromSystemTime(); | 239 timer_ = base::Time::NowFromSystemTime(); |
| 234 } | 240 } |
| 235 | 241 |
| 236 // Read stats file, and get run time. | 242 // Read stats file, and get run time. |
| 237 void ReplayURLsFunction::ReadReplyFiles() { | 243 void ReplayURLsFunction::ReadReplyFiles() { |
| 238 file_util::ReadFileToString(stats_file_path_, &stats_); | 244 file_util::ReadFileToString(stats_file_path_, &stats_); |
| 239 | 245 |
| 240 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMilliseconds(); | 246 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMillisecondsF(); |
| 241 } | 247 } |
| 242 | 248 |
| 243 void ReplayURLsFunction::Finish() { | 249 void ReplayURLsFunction::Finish() { |
| 244 record::ReplayURLsResult result; | 250 record::ReplayURLsResult result; |
| 245 | 251 |
| 246 result.run_time = run_time_ms_; | 252 result.run_time = run_time_ms_; |
| 247 result.stats = stats_; | 253 result.stats = stats_; |
| 248 result.errors = errors_; | 254 result.errors = errors_; |
| 249 | 255 |
| 250 results_ = record::ReplayURLs::Results::Create(result); | 256 results_ = record::ReplayURLs::Results::Create(result); |
| 251 SendResponse(true); | 257 SendResponse(true); |
| 252 } | 258 } |
| 253 | 259 |
| 254 } // namespace extensions | 260 } // namespace extensions |
| OLD | NEW |