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

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

Issue 12093057: [ChromeDriver] Send DOM.getDocument after each DOM.documentUpdated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile error on win_rel Created 7 years, 10 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 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/dom_tracker.h" 5 #include "chrome/test/chromedriver/dom_tracker.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/test/chromedriver/status.h" 12 #include "chrome/test/chromedriver/status.h"
13 13
14 DomTracker::DomTracker() {} 14 DomTracker::DomTracker(DevToolsClient* client) : client_(client) {
15 DCHECK(client_);
16 }
15 17
16 DomTracker::~DomTracker() {} 18 DomTracker::~DomTracker() {}
17 19
20 Status DomTracker::Init() {
21 // Fetch the root document node so that Inspector will push DOM node
22 // information to the client.
23 base::DictionaryValue params;
24 return client_->SendCommand("DOM.getDocument", params);
25 }
26
18 Status DomTracker::GetFrameIdForNode( 27 Status DomTracker::GetFrameIdForNode(
19 int node_id, std::string* frame_id) { 28 int node_id, std::string* frame_id) {
20 if (node_to_frame_map_.count(node_id) == 0) 29 if (node_to_frame_map_.count(node_id) == 0)
21 return Status(kUnknownError, "element is not a frame"); 30 return Status(kUnknownError, "element is not a frame");
22 *frame_id = node_to_frame_map_[node_id]; 31 *frame_id = node_to_frame_map_[node_id];
23 return Status(kOk); 32 return Status(kOk);
24 } 33 }
25 34
26 void DomTracker::OnEvent(const std::string& method, 35 void DomTracker::OnEvent(const std::string& method,
27 const base::DictionaryValue& params) { 36 const base::DictionaryValue& params) {
28 if (method == "DOM.setChildNodes") { 37 if (method == "DOM.setChildNodes") {
29 const base::Value* nodes; 38 const base::Value* nodes;
30 if (!params.Get("nodes", &nodes)) { 39 if (!params.Get("nodes", &nodes)) {
31 LOG(ERROR) << "DOM.setChildNodes missing 'nodes'"; 40 LOG(ERROR) << "DOM.setChildNodes missing 'nodes'";
32 return; 41 return;
33 } 42 }
34 if (!ProcessNodeList(nodes)) { 43 if (!ProcessNodeList(nodes)) {
35 std::string json; 44 std::string json;
36 base::JSONWriter::Write(nodes, &json); 45 base::JSONWriter::Write(nodes, &json);
37 LOG(ERROR) << "DOM.setChildNodes has invalid 'nodes': " << json; 46 LOG(ERROR) << "DOM.setChildNodes has invalid 'nodes': " << json;
38 } 47 }
39 } else if (method == "DOM.documentUpdated") { 48 } else if (method == "DOM.documentUpdated") {
40 node_to_frame_map_.clear(); 49 node_to_frame_map_.clear();
50 base::DictionaryValue params;
51 client_->SendCommand("DOM.getDocument", params);
41 } 52 }
42 } 53 }
43 54
44 bool DomTracker::ProcessNodeList(const base::Value* nodes) { 55 bool DomTracker::ProcessNodeList(const base::Value* nodes) {
45 const base::ListValue* nodes_list; 56 const base::ListValue* nodes_list;
46 if (!nodes->GetAsList(&nodes_list)) 57 if (!nodes->GetAsList(&nodes_list))
47 return false; 58 return false;
48 for (size_t i = 0; i < nodes_list->GetSize(); ++i) { 59 for (size_t i = 0; i < nodes_list->GetSize(); ++i) {
49 const base::Value* node; 60 const base::Value* node;
50 if (!nodes_list->Get(i, &node)) 61 if (!nodes_list->Get(i, &node))
(...skipping 13 matching lines...) Expand all
64 return false; 75 return false;
65 std::string frame_id; 76 std::string frame_id;
66 if (dict->GetString("frameId", &frame_id)) 77 if (dict->GetString("frameId", &frame_id))
67 node_to_frame_map_.insert(std::make_pair(node_id, frame_id)); 78 node_to_frame_map_.insert(std::make_pair(node_id, frame_id));
68 79
69 const base::Value* children; 80 const base::Value* children;
70 if (dict->Get("children", &children)) 81 if (dict->Get("children", &children))
71 return ProcessNodeList(children); 82 return ProcessNodeList(children);
72 return true; 83 return true;
73 } 84 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/dom_tracker.h ('k') | chrome/test/chromedriver/dom_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698