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

Side by Side Diff: content/test/web_contents_observer_sanity_checker.cc

Issue 2561963002: base: Remove the string logging from CHECK(). (Closed)
Patch Set: checkstring: rebase Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/test/web_contents_observer_sanity_checker.h" 5 #include "content/test/web_contents_observer_sanity_checker.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/frame_host/render_frame_host_impl.h" 9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/common/frame_messages.h" 10 #include "content/common/frame_messages.h"
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 void WebContentsObserverSanityChecker::RenderFrameCreated( 42 void WebContentsObserverSanityChecker::RenderFrameCreated(
43 RenderFrameHost* render_frame_host) { 43 RenderFrameHost* render_frame_host) {
44 CHECK(!web_contents_destroyed_); 44 CHECK(!web_contents_destroyed_);
45 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host); 45 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host);
46 bool frame_exists = !live_routes_.insert(routing_pair).second; 46 bool frame_exists = !live_routes_.insert(routing_pair).second;
47 deleted_routes_.erase(routing_pair); 47 deleted_routes_.erase(routing_pair);
48 48
49 if (frame_exists) { 49 if (frame_exists) {
50 CHECK(false) << "RenderFrameCreated called more than once for routing pair:" 50 // RenderFrameCreated called more than once for routing pair.
51 << Format(render_frame_host); 51 CHECK(false);
52 } 52 }
53 53
54 CHECK(render_frame_host->GetProcess()->HasConnection()) 54 // RenderFrameCreated was called for a RenderFrameHost whose render process is
55 << "RenderFrameCreated was called for a RenderFrameHost whose render " 55 // not currently live, so there's no way for the RenderFrame to have been
56 "process is not currently live, so there's no way for the RenderFrame " 56 // created.
57 "to have been created."; 57 CHECK(render_frame_host->GetProcess()->HasConnection());
58 CHECK( 58 // RenderFrameCreated called on for a RenderFrameHost that thinks it is not
59 static_cast<RenderFrameHostImpl*>(render_frame_host)->IsRenderFrameLive()) 59 // alive.
60 << "RenderFrameCreated called on for a RenderFrameHost that thinks it is " 60 CHECK(static_cast<RenderFrameHostImpl*>(render_frame_host)
61 "not alive."; 61 ->IsRenderFrameLive());
62 62
63 EnsureStableParentValue(render_frame_host); 63 EnsureStableParentValue(render_frame_host);
64 CHECK(!HasAnyChildren(render_frame_host)); 64 CHECK(!HasAnyChildren(render_frame_host));
65 if (render_frame_host->GetParent()) { 65 if (render_frame_host->GetParent()) {
66 // It should also be a current host. 66 // It should also be a current host.
67 GlobalRoutingID parent_routing_pair = 67 GlobalRoutingID parent_routing_pair =
68 GetRoutingPair(render_frame_host->GetParent()); 68 GetRoutingPair(render_frame_host->GetParent());
69 69
70 CHECK(current_hosts_.count(parent_routing_pair)) 70 // RenderFrameCreated called for a RenderFrameHost whose parent was not a
71 << "RenderFrameCreated called for a RenderFrameHost whose parent was " 71 // current RenderFrameHost. Only the current frame should be spawning
72 << "not a current RenderFrameHost. Only the current frame should be " 72 // children.
73 << "spawning children."; 73 CHECK(current_hosts_.count(parent_routing_pair));
74 } 74 }
75 } 75 }
76 76
77 void WebContentsObserverSanityChecker::RenderFrameDeleted( 77 void WebContentsObserverSanityChecker::RenderFrameDeleted(
78 RenderFrameHost* render_frame_host) { 78 RenderFrameHost* render_frame_host) {
79 CHECK(!web_contents_destroyed_); 79 CHECK(!web_contents_destroyed_);
80 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host); 80 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host);
81 bool was_live = !!live_routes_.erase(routing_pair); 81 bool was_live = !!live_routes_.erase(routing_pair);
82 bool was_dead_already = !deleted_routes_.insert(routing_pair).second; 82 bool was_dead_already = !deleted_routes_.insert(routing_pair).second;
83 83
84 if (was_dead_already) { 84 if (was_dead_already) {
85 CHECK(false) << "RenderFrameDeleted called more than once for routing pair " 85 // RenderFrameDeleted called more than once for routing pair
86 << Format(render_frame_host); 86 // |Format(render_frame_host)|
87 CHECK(false);
87 } else if (!was_live) { 88 } else if (!was_live) {
88 CHECK(false) << "RenderFrameDeleted called for routing pair " 89 // RenderFrameDeleted called for routing pair |Format(render_frame_host)|
89 << Format(render_frame_host) 90 // for which RenderFrameCreated was never called
90 << " for which RenderFrameCreated was never called"; 91 CHECK(false);
91 } 92 }
92 93
93 EnsureStableParentValue(render_frame_host); 94 EnsureStableParentValue(render_frame_host);
94 CHECK(!HasAnyChildren(render_frame_host)); 95 CHECK(!HasAnyChildren(render_frame_host));
95 if (render_frame_host->GetParent()) 96 if (render_frame_host->GetParent())
96 AssertRenderFrameExists(render_frame_host->GetParent()); 97 AssertRenderFrameExists(render_frame_host->GetParent());
97 98
98 // All players should have been paused by this point. 99 // All players should have been paused by this point.
99 for (const auto& id : active_media_players_) 100 for (const auto& id : active_media_players_)
100 CHECK_NE(id.first, render_frame_host); 101 CHECK_NE(id.first, render_frame_host);
101 } 102 }
102 103
103 void WebContentsObserverSanityChecker::RenderFrameForInterstitialPageCreated( 104 void WebContentsObserverSanityChecker::RenderFrameForInterstitialPageCreated(
104 RenderFrameHost* render_frame_host) { 105 RenderFrameHost* render_frame_host) {
105 // TODO(nick): Record this. 106 // TODO(nick): Record this.
106 } 107 }
107 108
108 void WebContentsObserverSanityChecker::RenderFrameHostChanged( 109 void WebContentsObserverSanityChecker::RenderFrameHostChanged(
109 RenderFrameHost* old_host, 110 RenderFrameHost* old_host,
110 RenderFrameHost* new_host) { 111 RenderFrameHost* new_host) {
111 CHECK(new_host); 112 CHECK(new_host);
112 CHECK_NE(new_host, old_host); 113 CHECK_NE(new_host, old_host);
113 114
114 if (old_host) { 115 if (old_host) {
115 EnsureStableParentValue(old_host); 116 EnsureStableParentValue(old_host);
116 CHECK_EQ(old_host->GetParent(), new_host->GetParent()); 117 CHECK_EQ(old_host->GetParent(), new_host->GetParent());
117 GlobalRoutingID routing_pair = GetRoutingPair(old_host); 118 GlobalRoutingID routing_pair = GetRoutingPair(old_host);
118 bool old_did_exist = !!current_hosts_.erase(routing_pair); 119 bool old_did_exist = !!current_hosts_.erase(routing_pair);
119 if (!old_did_exist) { 120 if (!old_did_exist) {
120 CHECK(false) 121 // RenderFrameHostChanged called with old host that did not exist.
121 << "RenderFrameHostChanged called with old host that did not exist:" 122 CHECK(false);
122 << Format(old_host);
123 } 123 }
124 CHECK(!HasAnyChildren(old_host)) 124 // All children should be detached before a parent is detached.
125 << "All children should be detached before a parent is detached."; 125 CHECK(!HasAnyChildren(old_host));
126 } 126 }
127 127
128 EnsureStableParentValue(new_host); 128 EnsureStableParentValue(new_host);
129 if (new_host->GetParent()) { 129 if (new_host->GetParent()) {
130 AssertRenderFrameExists(new_host->GetParent()); 130 AssertRenderFrameExists(new_host->GetParent());
131 CHECK(current_hosts_.count(GetRoutingPair(new_host->GetParent()))) 131 // Parent of frame being committed must be current.
132 << "Parent of frame being committed must be current."; 132 CHECK(current_hosts_.count(GetRoutingPair(new_host->GetParent())));
133 } 133 }
134 134
135 GlobalRoutingID routing_pair = GetRoutingPair(new_host); 135 GlobalRoutingID routing_pair = GetRoutingPair(new_host);
136 bool host_exists = !current_hosts_.insert(routing_pair).second; 136 bool host_exists = !current_hosts_.insert(routing_pair).second;
137 if (host_exists) { 137 if (host_exists) {
138 CHECK(false) 138 // RenderFrameHostChanged called more than once for routing pair.
139 << "RenderFrameHostChanged called more than once for routing pair:" 139 CHECK(false);
140 << Format(new_host);
141 } 140 }
142 CHECK(!HasAnyChildren(new_host)) 141 // A frame should not have children before it is committed.
143 << "A frame should not have children before it is committed."; 142 CHECK(!HasAnyChildren(new_host));
144 } 143 }
145 144
146 void WebContentsObserverSanityChecker::FrameDeleted( 145 void WebContentsObserverSanityChecker::FrameDeleted(
147 RenderFrameHost* render_frame_host) { 146 RenderFrameHost* render_frame_host) {
148 // A frame can be deleted before RenderFrame in the renderer process is 147 // A frame can be deleted before RenderFrame in the renderer process is
149 // created, so there is not much that can be enforced here. 148 // created, so there is not much that can be enforced here.
150 CHECK(!web_contents_destroyed_); 149 CHECK(!web_contents_destroyed_);
151 150
152 EnsureStableParentValue(render_frame_host); 151 EnsureStableParentValue(render_frame_host);
153 152
154 CHECK(!HasAnyChildren(render_frame_host)) 153 // All children should be deleted before a frame is detached.
155 << "All children should be deleted before a frame is detached."; 154 CHECK(!HasAnyChildren(render_frame_host));
156 155
157 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host); 156 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host);
158 CHECK(current_hosts_.erase(routing_pair)) 157 // FrameDeleted called with a non-current RenderFrameHost.
159 << "FrameDeleted called with a non-current RenderFrameHost."; 158 CHECK(current_hosts_.erase(routing_pair));
160 159
161 if (render_frame_host->GetParent()) 160 if (render_frame_host->GetParent())
162 AssertRenderFrameExists(render_frame_host->GetParent()); 161 AssertRenderFrameExists(render_frame_host->GetParent());
163 } 162 }
164 163
165 void WebContentsObserverSanityChecker::DidStartNavigation( 164 void WebContentsObserverSanityChecker::DidStartNavigation(
166 NavigationHandle* navigation_handle) { 165 NavigationHandle* navigation_handle) {
167 CHECK(!NavigationIsOngoing(navigation_handle)); 166 CHECK(!NavigationIsOngoing(navigation_handle));
168 167
169 CHECK(navigation_handle->GetNetErrorCode() == net::OK); 168 CHECK(navigation_handle->GetNetErrorCode() == net::OK);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 347 }
349 348
350 void WebContentsObserverSanityChecker::AssertRenderFrameExists( 349 void WebContentsObserverSanityChecker::AssertRenderFrameExists(
351 RenderFrameHost* render_frame_host) { 350 RenderFrameHost* render_frame_host) {
352 CHECK(!web_contents_destroyed_); 351 CHECK(!web_contents_destroyed_);
353 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host); 352 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host);
354 353
355 bool render_frame_created_happened = live_routes_.count(routing_pair) != 0; 354 bool render_frame_created_happened = live_routes_.count(routing_pair) != 0;
356 bool render_frame_deleted_happened = deleted_routes_.count(routing_pair) != 0; 355 bool render_frame_deleted_happened = deleted_routes_.count(routing_pair) != 0;
357 356
358 CHECK(render_frame_created_happened) 357 // A RenderFrameHost pointer was passed to a WebContentsObserver method, but
359 << "A RenderFrameHost pointer was passed to a WebContentsObserver " 358 // WebContentsObserver::RenderFrameCreated was never called for that
360 << "method, but WebContentsObserver::RenderFrameCreated was never called " 359 // RenderFrameHost.
361 << "for that RenderFrameHost: " << Format(render_frame_host); 360 CHECK(render_frame_created_happened);
362 CHECK(!render_frame_deleted_happened) 361 // A RenderFrameHost pointer was passed to a WebContentsObserver method, but
363 << "A RenderFrameHost pointer was passed to a WebContentsObserver " 362 // WebContentsObserver::RenderFrameDeleted had already been called on that
364 << "method, but WebContentsObserver::RenderFrameDeleted had already been " 363 // frame.
365 << "called on that frame:" << Format(render_frame_host); 364 CHECK(!render_frame_deleted_happened);
366 } 365 }
367 366
368 void WebContentsObserverSanityChecker::AssertMainFrameExists() { 367 void WebContentsObserverSanityChecker::AssertMainFrameExists() {
369 AssertRenderFrameExists(web_contents()->GetMainFrame()); 368 AssertRenderFrameExists(web_contents()->GetMainFrame());
370 } 369 }
371 370
372 std::string WebContentsObserverSanityChecker::Format( 371 std::string WebContentsObserverSanityChecker::Format(
373 RenderFrameHost* render_frame_host) { 372 RenderFrameHost* render_frame_host) {
374 return base::StringPrintf( 373 return base::StringPrintf(
375 "(%d, %d -> %s)", render_frame_host->GetProcess()->GetID(), 374 "(%d, %d -> %s)", render_frame_host->GetProcess()->GetID(),
(...skipping 11 matching lines...) Expand all
387 RenderFrameHost* render_frame_host) { 386 RenderFrameHost* render_frame_host) {
388 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host); 387 GlobalRoutingID routing_pair = GetRoutingPair(render_frame_host);
389 GlobalRoutingID parent_routing_pair = 388 GlobalRoutingID parent_routing_pair =
390 GetRoutingPair(render_frame_host->GetParent()); 389 GetRoutingPair(render_frame_host->GetParent());
391 390
392 auto it = parent_ids_.find(routing_pair); 391 auto it = parent_ids_.find(routing_pair);
393 if (it == parent_ids_.end()) { 392 if (it == parent_ids_.end()) {
394 parent_ids_.insert(std::make_pair(routing_pair, parent_routing_pair)); 393 parent_ids_.insert(std::make_pair(routing_pair, parent_routing_pair));
395 } else { 394 } else {
396 GlobalRoutingID former_parent_routing_pair = it->second; 395 GlobalRoutingID former_parent_routing_pair = it->second;
397 CHECK(former_parent_routing_pair == parent_routing_pair) 396 // RFH's parent value changed over time! That is really not good!
398 << "RFH's parent value changed over time! That is really not good!"; 397 CHECK(former_parent_routing_pair == parent_routing_pair);
399 } 398 }
400 } 399 }
401 400
402 bool WebContentsObserverSanityChecker::HasAnyChildren(RenderFrameHost* parent) { 401 bool WebContentsObserverSanityChecker::HasAnyChildren(RenderFrameHost* parent) {
403 GlobalRoutingID parent_routing_pair = GetRoutingPair(parent); 402 GlobalRoutingID parent_routing_pair = GetRoutingPair(parent);
404 for (auto& entry : parent_ids_) { 403 for (auto& entry : parent_ids_) {
405 if (entry.second == parent_routing_pair) { 404 if (entry.second == parent_routing_pair) {
406 if (live_routes_.count(entry.first)) 405 if (live_routes_.count(entry.first))
407 return true; 406 return true;
408 if (current_hosts_.count(entry.first)) 407 if (current_hosts_.count(entry.first))
409 return true; 408 return true;
410 } 409 }
411 } 410 }
412 return false; 411 return false;
413 } 412 }
414 413
415 } // namespace content 414 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698