| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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 #include "chrome/test/webdriver/commands/chrome_commands.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "chrome/test/automation/value_conversion_util.h" |
| 12 #include "chrome/test/webdriver/commands/response.h" |
| 13 #include "chrome/test/webdriver/webdriver_error.h" |
| 14 #include "chrome/test/webdriver/webdriver_session.h" |
| 15 |
| 16 namespace webdriver { |
| 17 |
| 18 ExtensionsCommand::ExtensionsCommand( |
| 19 const std::vector<std::string>& path_segments, |
| 20 const base::DictionaryValue* const parameters) |
| 21 : WebDriverCommand(path_segments, parameters) {} |
| 22 |
| 23 ExtensionsCommand::~ExtensionsCommand() {} |
| 24 |
| 25 bool ExtensionsCommand::DoesGet() { |
| 26 return true; |
| 27 } |
| 28 |
| 29 bool ExtensionsCommand::DoesPost() { |
| 30 return true; |
| 31 } |
| 32 |
| 33 void ExtensionsCommand::ExecuteGet(Response* const response) { |
| 34 std::vector<std::string> extension_ids; |
| 35 Error* error = session_->GetInstalledExtensions(&extension_ids); |
| 36 if (error) { |
| 37 response->SetError(error); |
| 38 return; |
| 39 } |
| 40 base::ListValue* extensions = new base::ListValue(); |
| 41 for (size_t i = 0; i < extension_ids.size(); ++i) |
| 42 extensions->Append(CreateValueFrom(extension_ids[i])); |
| 43 response->SetValue(extensions); |
| 44 } |
| 45 |
| 46 void ExtensionsCommand::ExecutePost(Response* const response) { |
| 47 FilePath::StringType path_string; |
| 48 if (!GetStringParameter("path", &path_string)) { |
| 49 response->SetError(new Error(kUnknownError, "'path' missing or invalid")); |
| 50 return; |
| 51 } |
| 52 |
| 53 std::string extension_id; |
| 54 Error* error = session_->InstallExtension( |
| 55 FilePath(path_string), &extension_id); |
| 56 if (error) { |
| 57 response->SetError(error); |
| 58 return; |
| 59 } |
| 60 response->SetValue(CreateValueFrom(extension_id)); |
| 61 } |
| 62 |
| 63 } // namespace webdriver |
| OLD | NEW |