| 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 #include <tuple> | 7 #include <tuple> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2428 DispatchDevToolsMessage("Runtime.enable", | 2428 DispatchDevToolsMessage("Runtime.enable", |
| 2429 "{\"id\":1,\"method\":\"Runtime.enable\"}"); | 2429 "{\"id\":1,\"method\":\"Runtime.enable\"}"); |
| 2430 EXPECT_EQ(0, CountNotifications("Runtime.executionContextCreated")); | 2430 EXPECT_EQ(0, CountNotifications("Runtime.executionContextCreated")); |
| 2431 LoadHTML("<body>page<iframe></iframe></body>"); | 2431 LoadHTML("<body>page<iframe></iframe></body>"); |
| 2432 EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated")); | 2432 EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated")); |
| 2433 } | 2433 } |
| 2434 | 2434 |
| 2435 TEST_F(DevToolsAgentTest, RuntimeEvaluateRunMicrotasks) { | 2435 TEST_F(DevToolsAgentTest, RuntimeEvaluateRunMicrotasks) { |
| 2436 LoadHTML("<body>page</body>"); | 2436 LoadHTML("<body>page</body>"); |
| 2437 Attach(); | 2437 Attach(); |
| 2438 DispatchDevToolsMessage("Console.enable", | 2438 DispatchDevToolsMessage("Runtime.enable", |
| 2439 "{\"id\":1,\"method\":\"Console.enable\"}"); | 2439 "{\"id\":1,\"method\":\"Runtime.enable\"}"); |
| 2440 DispatchDevToolsMessage("Runtime.evaluate", | 2440 DispatchDevToolsMessage("Runtime.evaluate", |
| 2441 "{\"id\":2," | 2441 "{\"id\":2," |
| 2442 "\"method\":\"Runtime.evaluate\"," | 2442 "\"method\":\"Runtime.evaluate\"," |
| 2443 "\"params\":{" | 2443 "\"params\":{" |
| 2444 "\"expression\":\"Promise.resolve().then(" | 2444 "\"expression\":\"Promise.resolve().then(" |
| 2445 "() => console.log(42));\"" | 2445 "() => console.log(42));\"" |
| 2446 "}" | 2446 "}" |
| 2447 "}"); | 2447 "}"); |
| 2448 EXPECT_EQ(1, CountNotifications("Console.messageAdded")); | 2448 EXPECT_EQ(1, CountNotifications("Runtime.consoleAPICalled")); |
| 2449 } | 2449 } |
| 2450 | 2450 |
| 2451 TEST_F(DevToolsAgentTest, RuntimeCallFunctionOnRunMicrotasks) { | 2451 TEST_F(DevToolsAgentTest, RuntimeCallFunctionOnRunMicrotasks) { |
| 2452 LoadHTML("<body>page</body>"); | 2452 LoadHTML("<body>page</body>"); |
| 2453 Attach(); | 2453 Attach(); |
| 2454 DispatchDevToolsMessage("Console.enable", | 2454 DispatchDevToolsMessage("Runtime.enable", |
| 2455 "{\"id\":1,\"method\":\"Console.enable\"}"); | 2455 "{\"id\":1,\"method\":\"Runtime.enable\"}"); |
| 2456 DispatchDevToolsMessage("Runtime.evaluate", | 2456 DispatchDevToolsMessage("Runtime.evaluate", |
| 2457 "{\"id\":2," | 2457 "{\"id\":2," |
| 2458 "\"method\":\"Runtime.evaluate\"," | 2458 "\"method\":\"Runtime.evaluate\"," |
| 2459 "\"params\":{" | 2459 "\"params\":{" |
| 2460 "\"expression\":\"window\"" | 2460 "\"expression\":\"window\"" |
| 2461 "}" | 2461 "}" |
| 2462 "}"); | 2462 "}"); |
| 2463 | 2463 |
| 2464 base::DictionaryValue* root = LastReceivedMessage(); | 2464 base::DictionaryValue* root = LastReceivedMessage(); |
| 2465 const base::Value* object_id; | 2465 const base::Value* object_id; |
| 2466 ASSERT_TRUE(root->Get("result.result.objectId", &object_id)); | 2466 ASSERT_TRUE(root->Get("result.result.objectId", &object_id)); |
| 2467 std::string object_id_str; | 2467 std::string object_id_str; |
| 2468 EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str)); | 2468 EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str)); |
| 2469 | 2469 |
| 2470 DispatchDevToolsMessage("Runtime.callFunctionOn", | 2470 DispatchDevToolsMessage("Runtime.callFunctionOn", |
| 2471 "{\"id\":3," | 2471 "{\"id\":3," |
| 2472 "\"method\":\"Runtime.callFunctionOn\"," | 2472 "\"method\":\"Runtime.callFunctionOn\"," |
| 2473 "\"params\":{" | 2473 "\"params\":{" |
| 2474 "\"objectId\":" + | 2474 "\"objectId\":" + |
| 2475 object_id_str + | 2475 object_id_str + |
| 2476 "," | 2476 "," |
| 2477 "\"functionDeclaration\":\"function foo(){ " | 2477 "\"functionDeclaration\":\"function foo(){ " |
| 2478 "Promise.resolve().then(() => " | 2478 "Promise.resolve().then(() => " |
| 2479 "console.log(239))}\"" | 2479 "console.log(239))}\"" |
| 2480 "}" | 2480 "}" |
| 2481 "}"); | 2481 "}"); |
| 2482 EXPECT_EQ(1, CountNotifications("Console.messageAdded")); | 2482 EXPECT_EQ(1, CountNotifications("Runtime.consoleAPICalled")); |
| 2483 } | 2483 } |
| 2484 | 2484 |
| 2485 TEST_F(DevToolsAgentTest, CallFramesInIsolatedWorld) { | 2485 TEST_F(DevToolsAgentTest, CallFramesInIsolatedWorld) { |
| 2486 LoadHTML("<body>page</body>"); | 2486 LoadHTML("<body>page</body>"); |
| 2487 blink::WebScriptSource source1( | 2487 blink::WebScriptSource source1( |
| 2488 WebString::fromUTF8("function func1() { debugger; }")); | 2488 WebString::fromUTF8("function func1() { debugger; }")); |
| 2489 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source1, 1, 1); | 2489 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source1, 1, 1); |
| 2490 | 2490 |
| 2491 Attach(); | 2491 Attach(); |
| 2492 DispatchDevToolsMessage("Debugger.enable", | 2492 DispatchDevToolsMessage("Debugger.enable", |
| 2493 "{\"id\":1,\"method\":\"Debugger.enable\"}"); | 2493 "{\"id\":1,\"method\":\"Debugger.enable\"}"); |
| 2494 | 2494 |
| 2495 ExpectPauseAndResume(3); | 2495 ExpectPauseAndResume(3); |
| 2496 blink::WebScriptSource source2( | 2496 blink::WebScriptSource source2( |
| 2497 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2497 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
| 2498 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); | 2498 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); |
| 2499 | 2499 |
| 2500 EXPECT_FALSE(IsPaused()); | 2500 EXPECT_FALSE(IsPaused()); |
| 2501 Detach(); | 2501 Detach(); |
| 2502 } | 2502 } |
| 2503 | 2503 |
| 2504 } // namespace content | 2504 } // namespace content |
| OLD | NEW |