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

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

Issue 2064133002: [DevTools] Explicitly reset context group when clearing ScriptController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clear Created 4 years, 6 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/Source/bindings/core/v8/ScriptController.cpp » ('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 #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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "third_party/WebKit/public/platform/WebString.h" 67 #include "third_party/WebKit/public/platform/WebString.h"
68 #include "third_party/WebKit/public/platform/WebURLResponse.h" 68 #include "third_party/WebKit/public/platform/WebURLResponse.h"
69 #include "third_party/WebKit/public/web/WebDataSource.h" 69 #include "third_party/WebKit/public/web/WebDataSource.h"
70 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" 70 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
71 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" 71 #include "third_party/WebKit/public/web/WebFrameContentDumper.h"
72 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" 72 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
73 #include "third_party/WebKit/public/web/WebHistoryItem.h" 73 #include "third_party/WebKit/public/web/WebHistoryItem.h"
74 #include "third_party/WebKit/public/web/WebLocalFrame.h" 74 #include "third_party/WebKit/public/web/WebLocalFrame.h"
75 #include "third_party/WebKit/public/web/WebPerformance.h" 75 #include "third_party/WebKit/public/web/WebPerformance.h"
76 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 76 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
77 #include "third_party/WebKit/public/web/WebScriptSource.h"
77 #include "third_party/WebKit/public/web/WebSettings.h" 78 #include "third_party/WebKit/public/web/WebSettings.h"
78 #include "third_party/WebKit/public/web/WebView.h" 79 #include "third_party/WebKit/public/web/WebView.h"
79 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 80 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
80 #include "ui/events/event.h" 81 #include "ui/events/event.h"
81 #include "ui/events/keycodes/keyboard_codes.h" 82 #include "ui/events/keycodes/keyboard_codes.h"
82 #include "ui/gfx/codec/jpeg_codec.h" 83 #include "ui/gfx/codec/jpeg_codec.h"
83 #include "ui/gfx/range/range.h" 84 #include "ui/gfx/range/range.h"
84 85
85 #if defined(USE_AURA) && defined(USE_X11) 86 #if defined(USE_AURA) && defined(USE_X11)
86 #include <X11/Xlib.h> 87 #include <X11/Xlib.h>
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 377 }
377 378
378 private: 379 private:
379 std::unique_ptr<MockKeyboard> mock_keyboard_; 380 std::unique_ptr<MockKeyboard> mock_keyboard_;
380 }; 381 };
381 382
382 class DevToolsAgentTest : public RenderViewImplTest { 383 class DevToolsAgentTest : public RenderViewImplTest {
383 public: 384 public:
384 void Attach() { 385 void Attach() {
385 notifications_ = std::vector<std::string>(); 386 notifications_ = std::vector<std::string>();
387 expecting_pause_ = false;
386 std::string host_id = "host_id"; 388 std::string host_id = "host_id";
387 agent()->OnAttach(host_id, 17); 389 agent()->OnAttach(host_id, 17);
388 agent()->send_protocol_message_callback_for_test_ = base::Bind( 390 agent()->send_protocol_message_callback_for_test_ = base::Bind(
389 &DevToolsAgentTest::OnDevToolsMessage, base::Unretained(this)); 391 &DevToolsAgentTest::OnDevToolsMessage, base::Unretained(this));
390 } 392 }
391 393
392 void Detach() { 394 void Detach() {
393 agent()->send_protocol_message_callback_for_test_.Reset(); 395 agent()->send_protocol_message_callback_for_test_.Reset();
394 agent()->OnDetach(); 396 agent()->OnDetach();
395 } 397 }
396 398
397 bool IsPaused() { 399 bool IsPaused() {
398 return agent()->paused_; 400 return agent()->paused_;
399 } 401 }
400 402
401 void DispatchDevToolsMessage(const std::string& method, 403 void DispatchDevToolsMessage(const std::string& method,
402 const std::string& message) { 404 const std::string& message) {
403 agent()->OnDispatchOnInspectorBackend(17, 1, method, message); 405 agent()->OnDispatchOnInspectorBackend(17, 1, method, message);
404 } 406 }
405 407
406 void CloseWhilePaused() { 408 void CloseWhilePaused() {
407 EXPECT_TRUE(IsPaused()); 409 EXPECT_TRUE(IsPaused());
408 view()->NotifyOnClose(); 410 view()->NotifyOnClose();
409 } 411 }
410 412
411 void OnDevToolsMessage( 413 void OnDevToolsMessage(
412 int, int, const std::string& message, const std::string&) { 414 int, int, const std::string& message, const std::string&) {
413 last_received_message_ = message; 415 last_message_ = base::WrapUnique(static_cast<base::DictionaryValue*>(
414 std::unique_ptr<base::DictionaryValue> root( 416 base::JSONReader::Read(message).release()));
415 static_cast<base::DictionaryValue*>(
416 base::JSONReader::Read(message).release()));
417 int id; 417 int id;
418 if (!root->GetInteger("id", &id)) { 418 if (!last_message_->GetInteger("id", &id)) {
419 std::string notification; 419 std::string notification;
420 EXPECT_TRUE(root->GetString("method", &notification)); 420 EXPECT_TRUE(last_message_->GetString("method", &notification));
421 notifications_.push_back(notification); 421 notifications_.push_back(notification);
422
423 if (notification == "Debugger.paused" && expecting_pause_) {
424 base::ListValue* call_frames;
425 EXPECT_TRUE(last_message_->GetList("params.callFrames", &call_frames));
426 if (call_frames) {
427 EXPECT_EQ(call_frames_count_,
428 static_cast<int>(call_frames->GetSize()));
429 }
430 expecting_pause_ = false;
431 base::ThreadTaskRunnerHandle::Get()->PostTask(
432 FROM_HERE,
433 base::Bind(&DevToolsAgentTest::DispatchDevToolsMessage,
434 base::Unretained(this),
435 "Debugger.resume",
436 "{\"id\":100,\"method\":\"Debugger.resume\"}"));
437 }
422 } 438 }
423 } 439 }
424 440
425 int CountNotifications(const std::string& notification) { 441 int CountNotifications(const std::string& notification) {
426 int result = 0; 442 int result = 0;
427 for (const std::string& s : notifications_) { 443 for (const std::string& s : notifications_) {
428 if (s == notification) 444 if (s == notification)
429 ++result; 445 ++result;
430 } 446 }
431 return result; 447 return result;
432 } 448 }
433 449
434 std::string LastReceivedMessage() const { return last_received_message_; } 450 base::DictionaryValue* LastReceivedMessage() {
451 return last_message_.get();
452 }
453
454 void ExpectPauseAndResume(int call_frames_count) {
455 expecting_pause_ = true;
456 call_frames_count_ = call_frames_count;
457 }
435 458
436 private: 459 private:
437 DevToolsAgent* agent() { 460 DevToolsAgent* agent() {
438 return frame()->devtools_agent(); 461 return frame()->devtools_agent();
439 } 462 }
440 463
441 std::vector<std::string> notifications_; 464 std::vector<std::string> notifications_;
442 std::string last_received_message_; 465 std::unique_ptr<base::DictionaryValue> last_message_;
466 int call_frames_count_;
467 bool expecting_pause_;
443 }; 468 };
444 469
445 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { 470 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest {
446 public: 471 public:
447 virtual void DoSetUp() { 472 virtual void DoSetUp() {
448 RenderViewImplTest::SetUp(); 473 RenderViewImplTest::SetUp();
449 } 474 }
450 475
451 blink::WebSettings* settings() { 476 blink::WebSettings* settings() {
452 return view()->webview()->settings(); 477 return view()->webview()->settings();
(...skipping 2025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2478 DispatchDevToolsMessage("Console.enable", 2503 DispatchDevToolsMessage("Console.enable",
2479 "{\"id\":1,\"method\":\"Console.enable\"}"); 2504 "{\"id\":1,\"method\":\"Console.enable\"}");
2480 DispatchDevToolsMessage("Runtime.evaluate", 2505 DispatchDevToolsMessage("Runtime.evaluate",
2481 "{\"id\":2," 2506 "{\"id\":2,"
2482 "\"method\":\"Runtime.evaluate\"," 2507 "\"method\":\"Runtime.evaluate\","
2483 "\"params\":{" 2508 "\"params\":{"
2484 "\"expression\":\"window\"" 2509 "\"expression\":\"window\""
2485 "}" 2510 "}"
2486 "}"); 2511 "}");
2487 2512
2488 std::unique_ptr<base::DictionaryValue> root( 2513 base::DictionaryValue* root = LastReceivedMessage();
2489 static_cast<base::DictionaryValue*>(
2490 base::JSONReader::Read(LastReceivedMessage()).release()));
2491 const base::Value* object_id; 2514 const base::Value* object_id;
2492 ASSERT_TRUE(root->Get("result.result.objectId", &object_id)); 2515 ASSERT_TRUE(root->Get("result.result.objectId", &object_id));
2493 std::string object_id_str; 2516 std::string object_id_str;
2494 EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str)); 2517 EXPECT_TRUE(base::JSONWriter::Write(*object_id, &object_id_str));
2495 2518
2496 DispatchDevToolsMessage("Runtime.callFunctionOn", 2519 DispatchDevToolsMessage("Runtime.callFunctionOn",
2497 "{\"id\":3," 2520 "{\"id\":3,"
2498 "\"method\":\"Runtime.callFunctionOn\"," 2521 "\"method\":\"Runtime.callFunctionOn\","
2499 "\"params\":{" 2522 "\"params\":{"
2500 "\"objectId\":" + 2523 "\"objectId\":" +
2501 object_id_str + 2524 object_id_str +
2502 "," 2525 ","
2503 "\"functionDeclaration\":\"function foo(){ " 2526 "\"functionDeclaration\":\"function foo(){ "
2504 "Promise.resolve().then(() => " 2527 "Promise.resolve().then(() => "
2505 "console.log(239))}\"" 2528 "console.log(239))}\""
2506 "}" 2529 "}"
2507 "}"); 2530 "}");
2508 EXPECT_EQ(1, CountNotifications("Console.messageAdded")); 2531 EXPECT_EQ(1, CountNotifications("Console.messageAdded"));
2509 } 2532 }
2510 2533
2534 TEST_F(DevToolsAgentTest, CallFramesInIsolatedWorld) {
2535 LoadHTML("<body>page</body>");
2536 blink::WebScriptSource source1(
2537 WebString::fromUTF8("function func1() { debugger; }"));
2538 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source1, 1, 1);
2539
2540 Attach();
2541 DispatchDevToolsMessage("Debugger.enable",
2542 "{\"id\":1,\"method\":\"Debugger.enable\"}");
2543
2544 ExpectPauseAndResume(3);
2545 blink::WebScriptSource source2(
2546 WebString::fromUTF8("function func2() { func1(); }; func2();"));
2547 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1);
2548
2549 EXPECT_FALSE(IsPaused());
2550 Detach();
2551 }
2552
2511 } // namespace content 2553 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698