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

Side by Side Diff: chrome/test/chromedriver/commands.cc

Issue 11639019: [chromedriver] Implement SwitchToFrame command. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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
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/test/chromedriver/commands.h" 5 #include "chrome/test/chromedriver/commands.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const base::DictionaryValue& params, 96 const base::DictionaryValue& params,
97 scoped_ptr<base::Value>* value) { 97 scoped_ptr<base::Value>* value) {
98 std::string script; 98 std::string script;
99 if (!params.GetString("script", &script)) 99 if (!params.GetString("script", &script))
100 return Status(kUnknownError, "'script' must be a string"); 100 return Status(kUnknownError, "'script' must be a string");
101 const base::ListValue* args; 101 const base::ListValue* args;
102 if (!params.GetList("args", &args)) 102 if (!params.GetList("args", &args))
103 return Status(kUnknownError, "'args' must be a list"); 103 return Status(kUnknownError, "'args' must be a list");
104 104
105 return session->chrome->CallFunction( 105 return session->chrome->CallFunction(
106 "function(){" + script + "}", *args, value); 106 session->frame, "function(){" + script + "}", *args, value);
107 } 107 }
108
109 Status ExecuteSwitchToFrame(
110 Session* session,
111 const base::DictionaryValue& params,
112 scoped_ptr<base::Value>* value) {
113 const base::Value* id;
114 if (!params.Get("id", &id))
115 return Status(kUnknownError, "missing 'id'");
116
117 if (id->IsType(base::Value::TYPE_NULL)) {
118 session->frame = "";
119 return Status(kOk);
120 }
121
122 std::string script;
123 if (id->IsType(base::Value::TYPE_STRING)) {
124 script =
125 "function(arg) {"
126 " var xpath = '(/html/body//iframe|/html/frameset/frame)';"
127 " var sub = function(s) { return s.replace(/\\$/g, arg); };"
128 " xpath += sub('[@name=\"$\" or @id=\"$\"]');"
129 " return document.evaluate(xpath, document, null, "
craigdh 2012/12/20 20:03:38 Constructing these xpaths in C++ would reduce the
kkania 2013/01/08 18:30:11 I've gone and ahead and switched to C++ since it m
130 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
131 "}";
132 } else if (id->IsType(base::Value::TYPE_INTEGER)) {
133 script =
134 "function(index) {"
135 " var xpathIndex = '[' + (index + 1) + ']';"
136 " var xpath = '(/html/body//iframe|/html/frameset/frame)' + "
137 " xpathIndex;"
138 " return document.evaluate(xpath, document, null, "
139 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
140 "}";
141 } else if (id->IsType(base::Value::TYPE_DICTIONARY)) {
142 // TODO(kkania): Implement.
143 return Status(kUnknownError, "frame switching by element not implemented");
144 } else {
145 return Status(kUnknownError, "invalid 'id'");
146 }
147 base::ListValue args;
148 args.Append(id->DeepCopy());
149 std::string frame;
150 Status status = session->chrome->GetFrameByFunction(
151 session->frame, script, args, &frame);
152 if (status.IsError())
153 return status;
154 session->frame = frame;
155 return Status(kOk);
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698