OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/frame_tracker.h" | 5 #include "chrome/test/chromedriver/frame_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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 const std::string& frame_id, int* context_id) { | 31 const std::string& frame_id, int* context_id) { |
32 if (frame_to_context_map_.count(frame_id) == 0) | 32 if (frame_to_context_map_.count(frame_id) == 0) |
33 return Status(kUnknownError, "frame does not have execution context"); | 33 return Status(kUnknownError, "frame does not have execution context"); |
34 *context_id = frame_to_context_map_[frame_id]; | 34 *context_id = frame_to_context_map_[frame_id]; |
35 return Status(kOk); | 35 return Status(kOk); |
36 } | 36 } |
37 | 37 |
38 Status FrameTracker::OnConnected() { | 38 Status FrameTracker::OnConnected() { |
39 // Enable runtime events to allow tracking execution context creation. | 39 // Enable runtime events to allow tracking execution context creation. |
40 base::DictionaryValue params; | 40 base::DictionaryValue params; |
41 return client_->SendCommand("Runtime.enable", params); | 41 Status status = client_->SendCommand("Runtime.enable", params); |
| 42 if (status.IsError()) |
| 43 return status; |
| 44 return client_->SendCommand("DOM.getDocument", params); |
42 } | 45 } |
43 | 46 |
44 void FrameTracker::OnEvent(const std::string& method, | 47 void FrameTracker::OnEvent(const std::string& method, |
45 const base::DictionaryValue& params) { | 48 const base::DictionaryValue& params) { |
46 if (method == "Runtime.executionContextCreated") { | 49 if (method == "Runtime.executionContextCreated") { |
47 const base::DictionaryValue* context; | 50 const base::DictionaryValue* context; |
48 if (!params.GetDictionary("context", &context)) { | 51 if (!params.GetDictionary("context", &context)) { |
49 LOG(ERROR) << "Runtime.executionContextCreated missing dict 'context'"; | 52 LOG(ERROR) << "Runtime.executionContextCreated missing dict 'context'"; |
50 return; | 53 return; |
51 } | 54 } |
52 int context_id; | 55 int context_id; |
53 std::string frame_id; | 56 std::string frame_id; |
54 if (!context->GetInteger("id", &context_id) || | 57 if (!context->GetInteger("id", &context_id) || |
55 !context->GetString("frameId", &frame_id)) { | 58 !context->GetString("frameId", &frame_id)) { |
56 std::string json; | 59 std::string json; |
57 base::JSONWriter::Write(context, &json); | 60 base::JSONWriter::Write(context, &json); |
58 LOG(ERROR) << "Runtime.executionContextCreated has invalid 'context': " | 61 LOG(ERROR) << "Runtime.executionContextCreated has invalid 'context': " |
59 << json; | 62 << json; |
60 return; | 63 return; |
61 } | 64 } |
62 frame_to_context_map_.insert(std::make_pair(frame_id, context_id)); | 65 frame_to_context_map_.insert(std::make_pair(frame_id, context_id)); |
63 context_to_frame_map_.insert(std::make_pair(context_id, frame_id)); | 66 context_to_frame_map_.insert(std::make_pair(context_id, frame_id)); |
64 } else if (method == "DOM.documentUpdated") { | 67 } else if (method == "DOM.documentUpdated") { |
65 frame_to_context_map_.clear(); | 68 frame_to_context_map_.clear(); |
66 context_to_frame_map_.clear(); | 69 context_to_frame_map_.clear(); |
67 } | 70 } |
68 } | 71 } |
OLD | NEW |