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

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

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