Chromium Code Reviews| Index: content/renderer/render_view_browsertest.cc |
| diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc |
| index e66c4c3075bfea7a57b44d3c07ff9f6012e0a47b..08590a4a51e6ca55443ca232d397ef422f91cf72 100644 |
| --- a/content/renderer/render_view_browsertest.cc |
| +++ b/content/renderer/render_view_browsertest.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/callback.h" |
| #include "base/command_line.h" |
| #include "base/json/json_reader.h" |
| +#include "base/json/json_writer.h" |
| #include "base/location.h" |
| #include "base/macros.h" |
| #include "base/single_thread_task_runner.h" |
| @@ -407,6 +408,7 @@ class DevToolsAgentTest : public RenderViewImplTest { |
| void OnDevToolsMessage( |
| int, int, const std::string& message, const std::string&) { |
| + last_received_message_ = message; |
| std::unique_ptr<base::DictionaryValue> root( |
| static_cast<base::DictionaryValue*>( |
| base::JSONReader::Read(message).release())); |
| @@ -427,12 +429,15 @@ class DevToolsAgentTest : public RenderViewImplTest { |
| return result; |
| } |
| + std::string LastReceivedMessage() const { return last_received_message_; } |
| + |
| private: |
| DevToolsAgent* agent() { |
| return frame()->devtools_agent(); |
| } |
| std::vector<std::string> notifications_; |
| + std::string last_received_message_; |
| }; |
| class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { |
| @@ -2404,4 +2409,64 @@ TEST_F(DevToolsAgentTest, RuntimeEnableForcesContextsAfterNavigation) { |
| EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated")); |
| } |
| +TEST_F(DevToolsAgentTest, RuntimeEvaluateRunMicrotasks) { |
| + LoadHTML("<body>page</body>"); |
| + Attach(); |
| + DispatchDevToolsMessage("Console.enable", |
| + "{\"id\":1,\"method\":\"Console.enable\"}"); |
| + DispatchDevToolsMessage("Runtime.evaluate", |
| + "{\"id\":2," |
| + "\"method\":\"Runtime.evaluate\"," |
| + "\"params\":{" |
| + "\"expression\":\"Promise.resolve().then(" |
| + "() => console.log(42));\"" |
| + "}" |
| + "}"); |
| + EXPECT_EQ(1, CountNotifications("Console.messageAdded")); |
| +} |
| + |
| +TEST_F(DevToolsAgentTest, RuntimeCallFunctionOnRunMicrotasks) { |
| + LoadHTML("<body>page</body>"); |
| + Attach(); |
| + DispatchDevToolsMessage("Console.enable", |
| + "{\"id\":1,\"method\":\"Console.enable\"}"); |
| + DispatchDevToolsMessage("Runtime.evaluate", |
| + "{\"id\":2," |
| + "\"method\":\"Runtime.evaluate\"," |
| + "\"params\":{" |
| + "\"expression\":\"window\"" |
| + "}" |
| + "}"); |
| + |
| + std::unique_ptr<base::DictionaryValue> root( |
| + static_cast<base::DictionaryValue*>( |
| + base::JSONReader::Read(LastReceivedMessage()).release())); |
| + const base::Value* result; |
| + EXPECT_TRUE(static_cast<const base::DictionaryValue*>(root.get()) |
|
dgozman
2016/04/30 02:26:07
No need to cast.
kozy
2016/04/30 03:08:30
Done.
|
| + ->Get("result", &result)); |
| + const base::Value* object; |
| + EXPECT_TRUE(static_cast<const base::DictionaryValue*>(result)->Get("result", |
| + &object)); |
| + const base::Value* object_id; |
| + EXPECT_TRUE(static_cast<const base::DictionaryValue*>(object)->Get( |
|
dgozman
2016/04/30 02:26:06
std::string object_id;
root->GetStringASCII("resul
kozy
2016/04/30 03:08:30
Done.
|
| + "objectId", &object_id)); |
| + |
| + std::string object_id_str; |
| + EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str)); |
| + |
| + DispatchDevToolsMessage("Runtime.callFunctionOn", |
| + "{\"id\":3," |
| + "\"method\":\"Runtime.callFunctionOn\"," |
| + "\"params\":{" |
| + "\"objectId\":" + |
| + object_id_str + |
| + "," |
| + "\"functionDeclaration\":\"function foo(){ " |
| + "Promise.resolve().then(() => " |
| + "console.log(239))}\"" |
| + "}" |
| + "}"); |
| + EXPECT_EQ(1, CountNotifications("Console.messageAdded")); |
|
dgozman
2016/04/30 02:26:07
Could we also add test for "Runtime.getProperties"
kozy
2016/04/30 03:08:30
I'll add a test for this in follow up.
|
| +} |
| + |
| } // namespace content |