| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/json/json_writer.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "base/win/windows_version.h" | 21 #include "base/win/windows_version.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 agent()->OnDispatchOnInspectorBackend(17, message); | 399 agent()->OnDispatchOnInspectorBackend(17, message); |
| 399 } | 400 } |
| 400 | 401 |
| 401 void CloseWhilePaused() { | 402 void CloseWhilePaused() { |
| 402 EXPECT_TRUE(IsPaused()); | 403 EXPECT_TRUE(IsPaused()); |
| 403 view()->NotifyOnClose(); | 404 view()->NotifyOnClose(); |
| 404 } | 405 } |
| 405 | 406 |
| 406 void OnDevToolsMessage( | 407 void OnDevToolsMessage( |
| 407 int, int, const std::string& message, const std::string&) { | 408 int, int, const std::string& message, const std::string&) { |
| 408 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( | 409 last_received_message_ = message; |
| 409 base::JSONReader::Read(message).release())); | 410 std::unique_ptr<base::DictionaryValue> root( |
| 411 static_cast<base::DictionaryValue*>( |
| 412 base::JSONReader::Read(message).release())); |
| 410 int id; | 413 int id; |
| 411 if (!root->GetInteger("id", &id)) { | 414 if (!root->GetInteger("id", &id)) { |
| 412 std::string notification; | 415 std::string notification; |
| 413 EXPECT_TRUE(root->GetString("method", ¬ification)); | 416 EXPECT_TRUE(root->GetString("method", ¬ification)); |
| 414 notifications_.push_back(notification); | 417 notifications_.push_back(notification); |
| 415 } | 418 } |
| 416 } | 419 } |
| 417 | 420 |
| 418 int CountNotifications(const std::string& notification) { | 421 int CountNotifications(const std::string& notification) { |
| 419 int result = 0; | 422 int result = 0; |
| 420 for (const std::string& s : notifications_) { | 423 for (const std::string& s : notifications_) { |
| 421 if (s == notification) | 424 if (s == notification) |
| 422 ++result; | 425 ++result; |
| 423 } | 426 } |
| 424 return result; | 427 return result; |
| 425 } | 428 } |
| 426 | 429 |
| 430 std::string LastReceivedMessage() const { return last_received_message_; } |
| 431 |
| 427 private: | 432 private: |
| 428 DevToolsAgent* agent() { | 433 DevToolsAgent* agent() { |
| 429 return frame()->devtools_agent(); | 434 return frame()->devtools_agent(); |
| 430 } | 435 } |
| 431 | 436 |
| 432 std::vector<std::string> notifications_; | 437 std::vector<std::string> notifications_; |
| 438 std::string last_received_message_; |
| 433 }; | 439 }; |
| 434 | 440 |
| 435 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { | 441 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { |
| 436 public: | 442 public: |
| 437 virtual void DoSetUp() { | 443 virtual void DoSetUp() { |
| 438 RenderViewImplTest::SetUp(); | 444 RenderViewImplTest::SetUp(); |
| 439 } | 445 } |
| 440 | 446 |
| 441 blink::WebSettings* settings() { | 447 blink::WebSettings* settings() { |
| 442 return view()->webview()->settings(); | 448 return view()->webview()->settings(); |
| (...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2391 } | 2397 } |
| 2392 | 2398 |
| 2393 TEST_F(DevToolsAgentTest, RuntimeEnableForcesContextsAfterNavigation) { | 2399 TEST_F(DevToolsAgentTest, RuntimeEnableForcesContextsAfterNavigation) { |
| 2394 Attach(); | 2400 Attach(); |
| 2395 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Runtime.enable\"}"); | 2401 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Runtime.enable\"}"); |
| 2396 EXPECT_EQ(0, CountNotifications("Runtime.executionContextCreated")); | 2402 EXPECT_EQ(0, CountNotifications("Runtime.executionContextCreated")); |
| 2397 LoadHTML("<body>page<iframe></iframe></body>"); | 2403 LoadHTML("<body>page<iframe></iframe></body>"); |
| 2398 EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated")); | 2404 EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated")); |
| 2399 } | 2405 } |
| 2400 | 2406 |
| 2407 TEST_F(DevToolsAgentTest, RuntimeEvaluateRunMicrotasks) { |
| 2408 LoadHTML("<body>page</body>"); |
| 2409 Attach(); |
| 2410 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Console.enable\"}"); |
| 2411 DispatchDevToolsMessage("{\"id\":2," |
| 2412 "\"method\":\"Runtime.evaluate\"," |
| 2413 "\"params\":{" |
| 2414 "\"expression\":\"Promise.resolve().then(" |
| 2415 "() => console.log(42));\"" |
| 2416 "}" |
| 2417 "}"); |
| 2418 EXPECT_EQ(1, CountNotifications("Console.messageAdded")); |
| 2419 } |
| 2420 |
| 2421 TEST_F(DevToolsAgentTest, RuntimeCallFunctionOnRunMicrotasks) { |
| 2422 LoadHTML("<body>page</body>"); |
| 2423 Attach(); |
| 2424 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Console.enable\"}"); |
| 2425 DispatchDevToolsMessage("{\"id\":2," |
| 2426 "\"method\":\"Runtime.evaluate\"," |
| 2427 "\"params\":{" |
| 2428 "\"expression\":\"window\"" |
| 2429 "}" |
| 2430 "}"); |
| 2431 |
| 2432 std::unique_ptr<base::DictionaryValue> root( |
| 2433 static_cast<base::DictionaryValue*>( |
| 2434 base::JSONReader::Read(LastReceivedMessage()).release())); |
| 2435 const base::Value* object_id; |
| 2436 ASSERT_TRUE(root->Get("result.result.objectId", &object_id)); |
| 2437 std::string object_id_str; |
| 2438 EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str)); |
| 2439 |
| 2440 DispatchDevToolsMessage("{\"id\":3," |
| 2441 "\"method\":\"Runtime.callFunctionOn\"," |
| 2442 "\"params\":{" |
| 2443 "\"objectId\":" + |
| 2444 object_id_str + |
| 2445 "," |
| 2446 "\"functionDeclaration\":\"function foo(){ " |
| 2447 "Promise.resolve().then(() => " |
| 2448 "console.log(239))}\"" |
| 2449 "}" |
| 2450 "}"); |
| 2451 EXPECT_EQ(1, CountNotifications("Console.messageAdded")); |
| 2452 } |
| 2453 |
| 2401 } // namespace content | 2454 } // namespace content |
| OLD | NEW |