Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/public/browser/devtools_agent_host.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 const char kParamsParam[] = "params"; | 31 const char kParamsParam[] = "params"; |
| 32 | 32 |
| 33 } | 33 } |
| 34 | 34 |
| 35 class DevToolsProtocolTest : public ContentBrowserTest, | 35 class DevToolsProtocolTest : public ContentBrowserTest, |
| 36 public DevToolsAgentHostClient { | 36 public DevToolsAgentHostClient { |
| 37 public: | 37 public: |
| 38 DevToolsProtocolTest() | 38 DevToolsProtocolTest() |
| 39 : last_sent_id_(0), | 39 : last_sent_id_(0), |
| 40 waiting_for_notifications_count_(0), | 40 waiting_for_notifications_count_(0), |
| 41 in_dispatch_(false) { | 41 in_dispatch_(false), |
| 42 waiting_for_command_result_id_(0) { | |
|
Charlie Reis
2015/09/22 23:12:10
What are these test changes? I don't see a test f
dgozman
2015/09/22 23:27:55
This is a side-effect of different timings between
Charlie Reis
2015/09/22 23:56:42
Ok, thanks. It'd probably be worthwhile to includ
| |
| 42 } | 43 } |
| 43 | 44 |
| 44 protected: | 45 protected: |
| 45 void SendCommand(const std::string& method, | 46 void SendCommand(const std::string& method, |
| 46 scoped_ptr<base::DictionaryValue> params) { | 47 scoped_ptr<base::DictionaryValue> params) { |
| 47 SendCommand(method, params.Pass(), true); | 48 SendCommand(method, params.Pass(), true); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void SendCommand(const std::string& method, | 51 void SendCommand(const std::string& method, |
| 51 scoped_ptr<base::DictionaryValue> params, | 52 scoped_ptr<base::DictionaryValue> params, |
| 52 bool wait) { | 53 bool wait) { |
| 53 in_dispatch_ = true; | 54 in_dispatch_ = true; |
| 54 base::DictionaryValue command; | 55 base::DictionaryValue command; |
| 55 command.SetInteger(kIdParam, ++last_sent_id_); | 56 command.SetInteger(kIdParam, ++last_sent_id_); |
| 56 command.SetString(kMethodParam, method); | 57 command.SetString(kMethodParam, method); |
| 57 if (params) | 58 if (params) |
| 58 command.Set(kParamsParam, params.release()); | 59 command.Set(kParamsParam, params.release()); |
| 59 | 60 |
| 60 std::string json_command; | 61 std::string json_command; |
| 61 base::JSONWriter::Write(command, &json_command); | 62 base::JSONWriter::Write(command, &json_command); |
| 62 agent_host_->DispatchProtocolMessage(json_command); | 63 agent_host_->DispatchProtocolMessage(json_command); |
| 63 // Some messages are dispatched synchronously. | 64 // Some messages are dispatched synchronously. |
| 64 // Only run loop if we are not finished yet. | 65 // Only run loop if we are not finished yet. |
| 65 if (in_dispatch_ && wait) | 66 if (in_dispatch_ && wait) { |
| 67 waiting_for_command_result_id_ = last_sent_id_; | |
| 66 base::MessageLoop::current()->Run(); | 68 base::MessageLoop::current()->Run(); |
| 69 } | |
| 67 in_dispatch_ = false; | 70 in_dispatch_ = false; |
| 68 } | 71 } |
| 69 | 72 |
| 70 bool HasValue(const std::string& path) { | 73 bool HasValue(const std::string& path) { |
| 71 base::Value* value = 0; | 74 base::Value* value = 0; |
| 72 return result_->Get(path, &value); | 75 return result_->Get(path, &value); |
| 73 } | 76 } |
| 74 | 77 |
| 75 bool HasListItem(const std::string& path_to_list, | 78 bool HasListItem(const std::string& path_to_list, |
| 76 const std::string& name, | 79 const std::string& name, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 const std::string& message) override { | 123 const std::string& message) override { |
| 121 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( | 124 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( |
| 122 base::JSONReader::Read(message).release())); | 125 base::JSONReader::Read(message).release())); |
| 123 int id; | 126 int id; |
| 124 if (root->GetInteger("id", &id)) { | 127 if (root->GetInteger("id", &id)) { |
| 125 result_ids_.push_back(id); | 128 result_ids_.push_back(id); |
| 126 base::DictionaryValue* result; | 129 base::DictionaryValue* result; |
| 127 EXPECT_TRUE(root->GetDictionary("result", &result)); | 130 EXPECT_TRUE(root->GetDictionary("result", &result)); |
| 128 result_.reset(result->DeepCopy()); | 131 result_.reset(result->DeepCopy()); |
| 129 in_dispatch_ = false; | 132 in_dispatch_ = false; |
| 130 if (base::MessageLoop::current()->is_running()) | 133 if (id && id == waiting_for_command_result_id_) { |
| 134 waiting_for_command_result_id_ = 0; | |
| 131 base::MessageLoop::current()->QuitNow(); | 135 base::MessageLoop::current()->QuitNow(); |
| 136 } | |
| 132 } else { | 137 } else { |
| 133 std::string notification; | 138 std::string notification; |
| 134 EXPECT_TRUE(root->GetString("method", ¬ification)); | 139 EXPECT_TRUE(root->GetString("method", ¬ification)); |
| 135 notifications_.push_back(notification); | 140 notifications_.push_back(notification); |
| 136 if (waiting_for_notifications_count_) { | 141 if (waiting_for_notifications_count_) { |
| 137 waiting_for_notifications_count_--; | 142 waiting_for_notifications_count_--; |
| 138 if (!waiting_for_notifications_count_) | 143 if (!waiting_for_notifications_count_) |
| 139 base::MessageLoop::current()->QuitNow(); | 144 base::MessageLoop::current()->QuitNow(); |
| 140 } | 145 } |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 | 148 |
| 144 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { | 149 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { |
| 145 EXPECT_TRUE(false); | 150 EXPECT_TRUE(false); |
| 146 } | 151 } |
| 147 | 152 |
| 148 int waiting_for_notifications_count_; | 153 int waiting_for_notifications_count_; |
| 149 bool in_dispatch_; | 154 bool in_dispatch_; |
| 155 int waiting_for_command_result_id_; | |
| 150 }; | 156 }; |
| 151 | 157 |
| 152 class SyntheticKeyEventTest : public DevToolsProtocolTest { | 158 class SyntheticKeyEventTest : public DevToolsProtocolTest { |
| 153 protected: | 159 protected: |
| 154 void SendKeyEvent(const std::string& type, | 160 void SendKeyEvent(const std::string& type, |
| 155 int modifier, | 161 int modifier, |
| 156 int windowsKeyCode, | 162 int windowsKeyCode, |
| 157 int nativeKeyCode) { | 163 int nativeKeyCode) { |
| 158 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 164 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
| 159 params->SetString("type", type); | 165 params->SetString("type", type); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 | 396 |
| 391 bool found_notification = false; | 397 bool found_notification = false; |
| 392 for (size_t i = notification_count; i < notifications_.size(); ++i) { | 398 for (size_t i = notification_count; i < notifications_.size(); ++i) { |
| 393 if (notifications_[i] == "Runtime.executionContextsCleared") | 399 if (notifications_[i] == "Runtime.executionContextsCleared") |
| 394 found_notification = true; | 400 found_notification = true; |
| 395 } | 401 } |
| 396 EXPECT_TRUE(found_notification); | 402 EXPECT_TRUE(found_notification); |
| 397 } | 403 } |
| 398 | 404 |
| 399 } // namespace content | 405 } // namespace content |
| OLD | NEW |