blob: 0714518de54095669f3d033b3807ad26772e6b45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/webdriver/commands/chrome_commands.h"
#include <string>
#include <vector>
#include "base/file_path.h"
#include "chrome/test/automation/value_conversion_util.h"
#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/webdriver_error.h"
#include "chrome/test/webdriver/webdriver_session.h"
namespace webdriver {
ExtensionsCommand::ExtensionsCommand(
const std::vector<std::string>& path_segments,
const base::DictionaryValue* const parameters)
: WebDriverCommand(path_segments, parameters) {}
ExtensionsCommand::~ExtensionsCommand() {}
bool ExtensionsCommand::DoesGet() {
return true;
}
bool ExtensionsCommand::DoesPost() {
return true;
}
void ExtensionsCommand::ExecuteGet(Response* const response) {
std::vector<std::string> extension_ids;
Error* error = session_->GetInstalledExtensions(&extension_ids);
if (error) {
response->SetError(error);
return;
}
base::ListValue* extensions = new base::ListValue();
for (size_t i = 0; i < extension_ids.size(); ++i)
extensions->Append(CreateValueFrom(extension_ids[i]));
response->SetValue(extensions);
}
void ExtensionsCommand::ExecutePost(Response* const response) {
FilePath::StringType path_string;
if (!GetStringParameter("path", &path_string)) {
response->SetError(new Error(kUnknownError, "'path' missing or invalid"));
return;
}
std::string extension_id;
Error* error = session_->InstallExtension(
FilePath(path_string), &extension_id);
if (error) {
response->SetError(error);
return;
}
response->SetValue(CreateValueFrom(extension_id));
}
} // namespace webdriver
|