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

Side by Side Diff: chrome/common/automation_id.cc

Issue 8790003: Allow the automation provider to accept an ID for performing render-view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years 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 | Annotate | Revision Log
« chrome/common/automation_id.h ('K') | « chrome/common/automation_id.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/common/automation_id.h"
6
7 #include "base/stringprintf.h"
8 #include "base/values.h"
9
10 using base::DictionaryValue;
11 using base::Value;
12
13 // static
14 bool AutomationId::FromValue(
15 Value* value, AutomationId* id, std::string* error) {
16 DictionaryValue* dict;
17 if (!value->GetAsDictionary(&dict)) {
18 *error = "automation ID must be a dictionary";
19 return false;
20 }
21 int type;
22 if (!dict->GetInteger("type", &type)) {
23 *error = "automation ID 'type' missing or invalid";
24 return false;
25 }
26 std::string type_id;
27 if (!dict->GetString("id", &type_id)) {
28 *error = "automation ID 'type_id' missing or invalid";
29 return false;
30 }
31 *id = AutomationId(static_cast<Type>(type), type_id);
32 return true;
33 }
34
35 // static
36 bool AutomationId::FromValueInDictionary(
37 DictionaryValue* dict,
38 const std::string& key,
39 AutomationId* id,
40 std::string* error) {
41 Value* id_value;
42 if (!dict->Get(key, &id_value)) {
43 *error = base::StringPrintf("automation ID '%s' missing", key.c_str());
44 return false;
45 }
46 return FromValue(id_value, id, error);
47 }
48
49 AutomationId::AutomationId() : type_(kTypeInvalid) { }
50
51 AutomationId::AutomationId(Type type, const std::string& id)
52 : type_(type), id_(id) { }
53
54 bool AutomationId::operator==(const AutomationId& id) const {
55 return type_ == id.type_ && id_ == id.id_;
56 }
57
58 DictionaryValue* AutomationId::ToValue() const {
59 DictionaryValue* dict = new DictionaryValue();
60 dict->SetInteger("type", type_);
61 dict->SetString("id", id_);
62 return dict;
63 }
64
65 bool AutomationId::is_valid() const {
66 return type_ != kTypeInvalid;
67 }
68
69 AutomationId::Type AutomationId::type() const {
70 return type_;
71 }
72
73 const std::string& AutomationId::id() const {
74 return id_;
75 }
OLDNEW
« chrome/common/automation_id.h ('K') | « chrome/common/automation_id.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698