| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <list> | |
| 6 #include <string> | |
| 7 | |
| 8 #include "base/json/json_reader.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/test/chromedriver/dom_tracker.h" | |
| 11 #include "chrome/test/chromedriver/status.h" | |
| 12 #include "chrome/test/chromedriver/stub_devtools_client.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class FakeDevToolsClient : public StubDevToolsClient { | |
| 18 public: | |
| 19 FakeDevToolsClient() {} | |
| 20 virtual ~FakeDevToolsClient() {} | |
| 21 | |
| 22 std::string PopSentCommand() { | |
| 23 std::string command; | |
| 24 if (!sent_command_queue_.empty()) { | |
| 25 command = sent_command_queue_.front(); | |
| 26 sent_command_queue_.pop_front(); | |
| 27 } | |
| 28 return command; | |
| 29 } | |
| 30 | |
| 31 // Overridden from DevToolsClient: | |
| 32 virtual Status SendCommand(const std::string& method, | |
| 33 const base::DictionaryValue& params) OVERRIDE { | |
| 34 sent_command_queue_.push_back(method); | |
| 35 return Status(kOk); | |
| 36 } | |
| 37 virtual Status SendCommandAndGetResult( | |
| 38 const std::string& method, | |
| 39 const base::DictionaryValue& params, | |
| 40 scoped_ptr<base::DictionaryValue>* result) OVERRIDE { | |
| 41 return SendCommand(method, params); | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 std::list<std::string> sent_command_queue_; | |
| 46 }; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 TEST(DomTracker, GetFrameIdForNode) { | |
| 51 FakeDevToolsClient client; | |
| 52 DomTracker tracker(&client); | |
| 53 std::string frame_id; | |
| 54 ASSERT_TRUE(tracker.GetFrameIdForNode(101, &frame_id).IsError()); | |
| 55 ASSERT_TRUE(frame_id.empty()); | |
| 56 | |
| 57 const char nodes[] = | |
| 58 "[{\"nodeId\":100,\"children\":" | |
| 59 " [{\"nodeId\":101}," | |
| 60 " {\"nodeId\":102,\"frameId\":\"f\"}]" | |
| 61 "}]"; | |
| 62 base::DictionaryValue params; | |
| 63 params.Set("nodes", base::JSONReader::Read(nodes)); | |
| 64 tracker.OnEvent("DOM.setChildNodes", params); | |
| 65 ASSERT_TRUE(tracker.GetFrameIdForNode(101, &frame_id).IsError()); | |
| 66 ASSERT_TRUE(frame_id.empty()); | |
| 67 ASSERT_TRUE(tracker.GetFrameIdForNode(102, &frame_id).IsOk()); | |
| 68 ASSERT_STREQ("f", frame_id.c_str()); | |
| 69 | |
| 70 tracker.OnEvent("DOM.documentUpdated", params); | |
| 71 ASSERT_TRUE(tracker.GetFrameIdForNode(102, &frame_id).IsError()); | |
| 72 ASSERT_STREQ("DOM.getDocument", client.PopSentCommand().c_str()); | |
| 73 } | |
| OLD | NEW |