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

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

Issue 1873533002: [DevTools] Force context creation when runtime is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more tests Created 4 years, 8 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
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/location.h" 12 #include "base/location.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "base/values.h"
18 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
19 #include "build/build_config.h" 21 #include "build/build_config.h"
20 #include "cc/trees/layer_tree_host.h" 22 #include "cc/trees/layer_tree_host.h"
21 #include "content/child/request_extra_data.h" 23 #include "content/child/request_extra_data.h"
22 #include "content/child/service_worker/service_worker_network_provider.h" 24 #include "content/child/service_worker/service_worker_network_provider.h"
23 #include "content/common/content_switches_internal.h" 25 #include "content/common/content_switches_internal.h"
24 #include "content/common/frame_messages.h" 26 #include "content/common/frame_messages.h"
25 #include "content/common/frame_replication_state.h" 27 #include "content/common/frame_replication_state.h"
26 #include "content/common/site_isolation_policy.h" 28 #include "content/common/site_isolation_policy.h"
27 #include "content/common/ssl_status_serialization.h" 29 #include "content/common/ssl_status_serialization.h"
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 view()->OnSetZoomLevelForView(false, level); 372 view()->OnSetZoomLevelForView(false, level);
371 } 373 }
372 374
373 private: 375 private:
374 scoped_ptr<MockKeyboard> mock_keyboard_; 376 scoped_ptr<MockKeyboard> mock_keyboard_;
375 }; 377 };
376 378
377 class DevToolsAgentTest : public RenderViewImplTest { 379 class DevToolsAgentTest : public RenderViewImplTest {
378 public: 380 public:
379 void Attach() { 381 void Attach() {
382 notifications_ = std::vector<std::string>();
380 std::string host_id = "host_id"; 383 std::string host_id = "host_id";
381 agent()->OnAttach(host_id, 17); 384 agent()->OnAttach(host_id, 17);
385 agent()->send_protocol_message_callback_for_test_ = base::Bind(
386 &DevToolsAgentTest::OnDevToolsMessage, base::Unretained(this));
382 } 387 }
383 388
384 void Detach() { 389 void Detach() {
390 agent()->send_protocol_message_callback_for_test_.Reset();
385 agent()->OnDetach(); 391 agent()->OnDetach();
386 } 392 }
387 393
388 bool IsPaused() { 394 bool IsPaused() {
389 return agent()->paused_; 395 return agent()->paused_;
390 } 396 }
391 397
392 void DispatchDevToolsMessage(const std::string& message) { 398 void DispatchDevToolsMessage(const std::string& message) {
393 agent()->OnDispatchOnInspectorBackend(17, message); 399 agent()->OnDispatchOnInspectorBackend(17, message);
394 } 400 }
395 401
396 void CloseWhilePaused() { 402 void CloseWhilePaused() {
397 EXPECT_TRUE(IsPaused()); 403 EXPECT_TRUE(IsPaused());
398 view()->NotifyOnClose(); 404 view()->NotifyOnClose();
399 } 405 }
400 406
407 void OnDevToolsMessage(
408 int, int, const std::string& message, const std::string&) {
409 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>(
410 base::JSONReader::Read(message).release()));
411 int id;
412 if (!root->GetInteger("id", &id)) {
413 std::string notification;
414 EXPECT_TRUE(root->GetString("method", &notification));
415 notifications_.push_back(notification);
416 }
417 }
418
419 bool HasNotifications(const std::string& notification, int count) {
420 for (const std::string& s : notifications_) {
421 if (s == notification)
422 --count;
423 }
424 return count <= 0;
425 }
426
401 private: 427 private:
402 DevToolsAgent* agent() { 428 DevToolsAgent* agent() {
403 return frame()->devtools_agent(); 429 return frame()->devtools_agent();
404 } 430 }
431
432 std::vector<std::string> notifications_;
405 }; 433 };
406 434
407 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest { 435 class RenderViewImplBlinkSettingsTest : public RenderViewImplTest {
408 public: 436 public:
409 virtual void DoSetUp() { 437 virtual void DoSetUp() {
410 RenderViewImplTest::SetUp(); 438 RenderViewImplTest::SetUp();
411 } 439 }
412 440
413 blink::WebSettings* settings() { 441 blink::WebSettings* settings() {
414 return view()->webview()->settings(); 442 return view()->webview()->settings();
(...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 base::ThreadTaskRunnerHandle::Get()->PostTask( 2376 base::ThreadTaskRunnerHandle::Get()->PostTask(
2349 FROM_HERE, 2377 FROM_HERE,
2350 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); 2378 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
2351 ExecuteJavaScriptForTests("debugger;"); 2379 ExecuteJavaScriptForTests("debugger;");
2352 2380
2353 // CloseWhilePaused should resume execution and continue here. 2381 // CloseWhilePaused should resume execution and continue here.
2354 EXPECT_FALSE(IsPaused()); 2382 EXPECT_FALSE(IsPaused());
2355 Detach(); 2383 Detach();
2356 } 2384 }
2357 2385
2386 TEST_F(DevToolsAgentTest, RuntimeEnableForcesMainContext) {
2387 LoadHTML("");
2388 Attach();
2389 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
2390 EXPECT_TRUE(HasNotifications("Runtime.executionContextCreated", 1));
2391 }
2392
2393 TEST_F(DevToolsAgentTest, RuntimeEnableForcesContextsAfterNavigation) {
2394 Attach();
2395 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
2396 EXPECT_FALSE(HasNotifications("Runtime.executionContextCreated", 1));
2397 LoadHTML("<body>page<iframe></iframe></body>");
2398 EXPECT_TRUE(HasNotifications("Runtime.executionContextCreated", 2));
2399 }
2400
2358 } // namespace content 2401 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/devtools/devtools_agent.cc ('k') | third_party/WebKit/Source/core/inspector/InspectorInstrumentation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698