Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 1932343002: [DevTools] Don't run microtasks after call to InjectedScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/inspector-protocol/debugger/debugger-doesnt-step-into-injected-script.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 agent()->OnDispatchOnInspectorBackend(17, 1, method, message); 401 agent()->OnDispatchOnInspectorBackend(17, 1, method, message);
401 } 402 }
402 403
403 void CloseWhilePaused() { 404 void CloseWhilePaused() {
404 EXPECT_TRUE(IsPaused()); 405 EXPECT_TRUE(IsPaused());
405 view()->NotifyOnClose(); 406 view()->NotifyOnClose();
406 } 407 }
407 408
408 void OnDevToolsMessage( 409 void OnDevToolsMessage(
409 int, int, const std::string& message, const std::string&) { 410 int, int, const std::string& message, const std::string&) {
411 last_received_message_ = message;
410 std::unique_ptr<base::DictionaryValue> root( 412 std::unique_ptr<base::DictionaryValue> root(
411 static_cast<base::DictionaryValue*>( 413 static_cast<base::DictionaryValue*>(
412 base::JSONReader::Read(message).release())); 414 base::JSONReader::Read(message).release()));
413 int id; 415 int id;
414 if (!root->GetInteger("id", &id)) { 416 if (!root->GetInteger("id", &id)) {
415 std::string notification; 417 std::string notification;
416 EXPECT_TRUE(root->GetString("method", &notification)); 418 EXPECT_TRUE(root->GetString("method", &notification));
417 notifications_.push_back(notification); 419 notifications_.push_back(notification);
418 } 420 }
419 } 421 }
420 422
421 int CountNotifications(const std::string& notification) { 423 int CountNotifications(const std::string& notification) {
422 int result = 0; 424 int result = 0;
423 for (const std::string& s : notifications_) { 425 for (const std::string& s : notifications_) {
424 if (s == notification) 426 if (s == notification)
425 ++result; 427 ++result;
426 } 428 }
427 return result; 429 return result;
428 } 430 }
429 431
432 std::string LastReceivedMessage() const { return last_received_message_; }
433
430 private: 434 private:
431 DevToolsAgent* agent() { 435 DevToolsAgent* agent() {
432 return frame()->devtools_agent(); 436 return frame()->devtools_agent();
433 } 437 }
434 438
435 std::vector<std::string> notifications_; 439 std::vector<std::string> notifications_;
440 std::string last_received_message_;
436 }; 441 };
437 442
438 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { 443 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest {
439 public: 444 public:
440 virtual void DoSetUp() { 445 virtual void DoSetUp() {
441 RenderViewImplTest::SetUp(); 446 RenderViewImplTest::SetUp();
442 } 447 }
443 448
444 blink::WebSettings* settings() { 449 blink::WebSettings* settings() {
445 return view()->webview()->settings(); 450 return view()->webview()->settings();
(...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 2402
2398 TEST_F(DevToolsAgentTest, RuntimeEnableForcesContextsAfterNavigation) { 2403 TEST_F(DevToolsAgentTest, RuntimeEnableForcesContextsAfterNavigation) {
2399 Attach(); 2404 Attach();
2400 DispatchDevToolsMessage("Runtime.enable", 2405 DispatchDevToolsMessage("Runtime.enable",
2401 "{\"id\":1,\"method\":\"Runtime.enable\"}"); 2406 "{\"id\":1,\"method\":\"Runtime.enable\"}");
2402 EXPECT_EQ(0, CountNotifications("Runtime.executionContextCreated")); 2407 EXPECT_EQ(0, CountNotifications("Runtime.executionContextCreated"));
2403 LoadHTML("<body>page<iframe></iframe></body>"); 2408 LoadHTML("<body>page<iframe></iframe></body>");
2404 EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated")); 2409 EXPECT_EQ(2, CountNotifications("Runtime.executionContextCreated"));
2405 } 2410 }
2406 2411
2412 TEST_F(DevToolsAgentTest, RuntimeEvaluateRunMicrotasks) {
2413 LoadHTML("<body>page</body>");
2414 Attach();
2415 DispatchDevToolsMessage("Console.enable",
2416 "{\"id\":1,\"method\":\"Console.enable\"}");
2417 DispatchDevToolsMessage("Runtime.evaluate",
2418 "{\"id\":2,"
2419 "\"method\":\"Runtime.evaluate\","
2420 "\"params\":{"
2421 "\"expression\":\"Promise.resolve().then("
2422 "() => console.log(42));\""
2423 "}"
2424 "}");
2425 EXPECT_EQ(1, CountNotifications("Console.messageAdded"));
2426 }
2427
2428 TEST_F(DevToolsAgentTest, RuntimeCallFunctionOnRunMicrotasks) {
2429 LoadHTML("<body>page</body>");
2430 Attach();
2431 DispatchDevToolsMessage("Console.enable",
2432 "{\"id\":1,\"method\":\"Console.enable\"}");
2433 DispatchDevToolsMessage("Runtime.evaluate",
2434 "{\"id\":2,"
2435 "\"method\":\"Runtime.evaluate\","
2436 "\"params\":{"
2437 "\"expression\":\"window\""
2438 "}"
2439 "}");
2440
2441 std::unique_ptr<base::DictionaryValue> root(
2442 static_cast<base::DictionaryValue*>(
2443 base::JSONReader::Read(LastReceivedMessage()).release()));
2444 const base::Value* result;
2445 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.
2446 ->Get("result", &result));
2447 const base::Value* object;
2448 EXPECT_TRUE(static_cast<const base::DictionaryValue*>(result)->Get("result",
2449 &object));
2450 const base::Value* object_id;
2451 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.
2452 "objectId", &object_id));
2453
2454 std::string object_id_str;
2455 EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str));
2456
2457 DispatchDevToolsMessage("Runtime.callFunctionOn",
2458 "{\"id\":3,"
2459 "\"method\":\"Runtime.callFunctionOn\","
2460 "\"params\":{"
2461 "\"objectId\":" +
2462 object_id_str +
2463 ","
2464 "\"functionDeclaration\":\"function foo(){ "
2465 "Promise.resolve().then(() => "
2466 "console.log(239))}\""
2467 "}"
2468 "}");
2469 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.
2470 }
2471
2407 } // namespace content 2472 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/inspector-protocol/debugger/debugger-doesnt-step-into-injected-script.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698