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

Unified Diff: chrome/test/chromedriver/web_view_impl.cc

Issue 12764021: [chromedriver] Support clicking an element in sub frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/web_view_impl.cc
diff --git a/chrome/test/chromedriver/web_view_impl.cc b/chrome/test/chromedriver/web_view_impl.cc
index caa5f35eadc75e892ffbe41bc903e7f52d299ec9..34eb38d4d65e5b85d7abcad3b2b28cc7b1303fd6 100644
--- a/chrome/test/chromedriver/web_view_impl.cc
+++ b/chrome/test/chromedriver/web_view_impl.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/values.h"
+#include "chrome/test/chromedriver/basic_types.h"
#include "chrome/test/chromedriver/devtools_client_impl.h"
#include "chrome/test/chromedriver/dom_tracker.h"
#include "chrome/test/chromedriver/frame_tracker.h"
@@ -82,6 +83,56 @@ const char* GetAsString(KeyEventType type) {
}
}
+Status ParseSubFrame(const base::DictionaryValue* dict, Frame* frame) {
+ std::string id;
+ if (!dict->GetString("id", &id))
+ return Status(kUnknownError, "no id in frame object from DevTools");
+ std::string name;
+ dict->GetString("name", &name);
+ frame->id = id;
+ frame->name = name;
+ return Status(kOk);
+}
+
+Status SearchForFrame(const std::string& frame_id,
+ const base::DictionaryValue* frame_resource_tree,
+ std::list<Frame>* out_frames,
+ bool* out_found) {
+ const base::DictionaryValue* current_frame_dict;
+ if (!frame_resource_tree->GetDictionary("frame", &current_frame_dict))
+ return Status(kUnknownError, "no frame in frame resource tree");
+ Frame current_frame;
+ Status status = ParseSubFrame(current_frame_dict, &current_frame);
+ if (status.IsError())
+ return status;
+ if (current_frame.id == frame_id) {
+ out_frames->push_back(current_frame);
+ *out_found = true;
+ return Status(kOk);
+ }
+
+ const base::ListValue* child_frames;
+ if (frame_resource_tree->GetList("childFrames", &child_frames)) {
+ for (size_t i = 0; i < child_frames->GetSize(); ++i) {
+ const base::DictionaryValue* sub_tree;
+ if (!child_frames->GetDictionary(i, &sub_tree))
+ return Status(kUnknownError, "frame should be a dictionary");
+ bool found = false;
+ status = SearchForFrame(frame_id, sub_tree, out_frames, &found);
+ if (status.IsError())
+ return status;
+ if (found) {
+ out_frames->back().index = i;
+ out_frames->back().parent_id = current_frame.id;
+ out_frames->push_back(current_frame);
+ *out_found = true;
+ break;
+ }
+ }
+ }
+ return Status(kOk);
+}
+
} // namespace
WebViewImpl::WebViewImpl(const std::string& id,
@@ -275,6 +326,26 @@ Status WebViewImpl::CaptureScreenshot(std::string* screenshot) {
return Status(kOk);
}
+Status WebViewImpl::GetFramePath(const std::string& frame_id,
+ std::list<Frame>* frames) {
+ base::DictionaryValue params;
+ scoped_ptr<base::DictionaryValue> result;
+ Status status = client_->SendCommandAndGetResult(
+ "Page.getResourceTree", params, &result);
+ if (status.IsError())
+ return status;
+ const base::DictionaryValue* root_frame_tree;
+ if (!result->GetDictionary("frameTree", &root_frame_tree))
+ return Status(kUnknownError, "no frame tree returned by DevTools");
+ bool found = false;
+ status = SearchForFrame(frame_id, root_frame_tree, frames, &found);
+ if (status.IsError())
+ return status;
+ if (!found)
+ return Status(kUnknownError, "frame not found in the frame tree");
+ return Status(kOk);
+}
+
namespace internal {
Status EvaluateScript(DevToolsClient* client,

Powered by Google App Engine
This is Rietveld 408576698