Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/browser/frame_host/render_frame_host_impl.h" | 8 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 9 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
| 10 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 void WebContentsObserverSanityChecker::FrameDeleted( | 117 void WebContentsObserverSanityChecker::FrameDeleted( |
| 118 RenderFrameHost* render_frame_host) { | 118 RenderFrameHost* render_frame_host) { |
| 119 // A frame can be deleted before RenderFrame in the renderer process is | 119 // A frame can be deleted before RenderFrame in the renderer process is |
| 120 // created, so there is not much that can be enforced here. | 120 // created, so there is not much that can be enforced here. |
| 121 CHECK(!web_contents_destroyed_); | 121 CHECK(!web_contents_destroyed_); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void WebContentsObserverSanityChecker::DidStartNavigation( | 124 void WebContentsObserverSanityChecker::DidStartNavigation( |
| 125 NavigationHandle* navigation_handle) { | 125 NavigationHandle* navigation_handle) { |
| 126 CHECK(!NavigationIsOngoing(navigation_handle)); | 126 CHECK(!NavigationIsOngoing(navigation_handle)); |
| 127 CHECK(!NavigationIsOngoingAndCommitted(navigation_handle)); | |
| 128 | 127 |
| 129 CHECK(navigation_handle->GetNetErrorCode() == net::OK); | 128 CHECK(navigation_handle->GetNetErrorCode() == net::OK); |
| 130 CHECK(!navigation_handle->HasCommittedDocument()); | 129 CHECK(!navigation_handle->HasCommitted()); |
|
Charlie Reis
2015/09/21 16:40:42
We can check !IsErrorPage() as well, right? (Same
clamy
2015/09/22 00:38:05
Done.
| |
| 131 CHECK(!navigation_handle->HasCommittedErrorPage()); | |
| 132 | 130 |
| 133 ongoing_navigations_.insert(navigation_handle); | 131 ongoing_navigations_.insert(navigation_handle); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void WebContentsObserverSanityChecker::DidRedirectNavigation( | 134 void WebContentsObserverSanityChecker::DidRedirectNavigation( |
| 137 NavigationHandle* navigation_handle) { | 135 NavigationHandle* navigation_handle) { |
| 138 CHECK(NavigationIsOngoing(navigation_handle)); | 136 CHECK(NavigationIsOngoing(navigation_handle)); |
| 139 CHECK(!NavigationIsOngoingAndCommitted(navigation_handle)); | |
| 140 | 137 |
| 141 CHECK(navigation_handle->GetNetErrorCode() == net::OK); | 138 CHECK(navigation_handle->GetNetErrorCode() == net::OK); |
| 142 CHECK(!navigation_handle->HasCommittedDocument()); | 139 CHECK(!navigation_handle->HasCommitted()); |
| 143 CHECK(!navigation_handle->HasCommittedErrorPage()); | |
| 144 } | 140 } |
| 145 | 141 |
| 146 void WebContentsObserverSanityChecker::ReadyToCommitNavigation( | 142 void WebContentsObserverSanityChecker::ReadyToCommitNavigation( |
| 147 NavigationHandle* navigation_handle) { | 143 NavigationHandle* navigation_handle) { |
| 148 CHECK(NavigationIsOngoing(navigation_handle)); | 144 CHECK(NavigationIsOngoing(navigation_handle)); |
| 149 CHECK(!NavigationIsOngoingAndCommitted(navigation_handle)); | |
| 150 | 145 |
| 151 CHECK(!navigation_handle->HasCommittedDocument()); | 146 CHECK(!navigation_handle->HasCommitted()); |
| 152 CHECK(!navigation_handle->HasCommittedErrorPage()); | 147 CHECK(navigation_handle->GetRenderFrameHost()); |
| 153 } | |
| 154 | |
| 155 void WebContentsObserverSanityChecker::DidCommitNavigation( | |
| 156 NavigationHandle* navigation_handle) { | |
| 157 CHECK(NavigationIsOngoing(navigation_handle)); | |
| 158 CHECK(!NavigationIsOngoingAndCommitted(navigation_handle)); | |
| 159 | |
| 160 CHECK_NE(navigation_handle->HasCommittedDocument(), | |
| 161 navigation_handle->HasCommittedErrorPage()); | |
| 162 CHECK_IMPLIES(navigation_handle->HasCommittedDocument(), | |
| 163 navigation_handle->GetNetErrorCode() == net::OK); | |
| 164 CHECK_IMPLIES(navigation_handle->HasCommittedErrorPage(), | |
| 165 navigation_handle->GetNetErrorCode() != net::OK); | |
| 166 | |
| 167 ongoing_committed_navigations_.insert(navigation_handle); | |
| 168 } | 148 } |
| 169 | 149 |
| 170 void WebContentsObserverSanityChecker::DidFinishNavigation( | 150 void WebContentsObserverSanityChecker::DidFinishNavigation( |
| 171 NavigationHandle* navigation_handle) { | 151 NavigationHandle* navigation_handle) { |
| 172 CHECK(NavigationIsOngoing(navigation_handle)); | 152 CHECK(NavigationIsOngoing(navigation_handle)); |
| 173 | 153 |
| 174 CHECK_IMPLIES(NavigationIsOngoingAndCommitted(navigation_handle), | 154 CHECK_IMPLIES( |
| 175 navigation_handle->HasCommittedDocument() != | 155 navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage(), |
| 176 navigation_handle->HasCommittedErrorPage()); | 156 navigation_handle->GetNetErrorCode() == net::OK); |
| 177 CHECK_IMPLIES(navigation_handle->HasCommittedDocument(), | 157 CHECK_IMPLIES( |
| 178 navigation_handle->GetNetErrorCode() == net::OK); | 158 navigation_handle->HasCommitted() && navigation_handle->IsErrorPage(), |
| 179 CHECK_IMPLIES(navigation_handle->HasCommittedErrorPage(), | 159 navigation_handle->GetNetErrorCode() != net::OK); |
| 180 navigation_handle->GetNetErrorCode() != net::OK); | |
| 181 | 160 |
| 182 if (NavigationIsOngoingAndCommitted(navigation_handle)) | 161 CHECK_IMPLIES(navigation_handle->HasCommitted(), |
|
Charlie Reis
2015/09/21 16:40:42
Should this be CHECK_EQ? (In other words, does th
clamy
2015/09/22 00:38:05
No this is an implication because I've put a CHECK
| |
| 183 ongoing_committed_navigations_.erase(navigation_handle); | 162 navigation_handle->GetRenderFrameHost() != nullptr); |
| 184 | 163 |
| 185 ongoing_navigations_.erase(navigation_handle); | 164 ongoing_navigations_.erase(navigation_handle); |
| 186 } | 165 } |
| 187 | 166 |
| 188 void WebContentsObserverSanityChecker::DidStartProvisionalLoadForFrame( | 167 void WebContentsObserverSanityChecker::DidStartProvisionalLoadForFrame( |
| 189 RenderFrameHost* render_frame_host, | 168 RenderFrameHost* render_frame_host, |
| 190 const GURL& validated_url, | 169 const GURL& validated_url, |
| 191 bool is_error_page, | 170 bool is_error_page, |
| 192 bool is_iframe_srcdoc) { | 171 bool is_iframe_srcdoc) { |
| 193 AssertRenderFrameExists(render_frame_host); | 172 AssertRenderFrameExists(render_frame_host); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 // TODO(avi): Disabled because of http://crbug.com/445054 | 259 // TODO(avi): Disabled because of http://crbug.com/445054 |
| 281 AssertRenderFrameExists(render_frame_host); | 260 AssertRenderFrameExists(render_frame_host); |
| 282 #endif | 261 #endif |
| 283 return false; | 262 return false; |
| 284 } | 263 } |
| 285 | 264 |
| 286 void WebContentsObserverSanityChecker::WebContentsDestroyed() { | 265 void WebContentsObserverSanityChecker::WebContentsDestroyed() { |
| 287 CHECK(!web_contents_destroyed_); | 266 CHECK(!web_contents_destroyed_); |
| 288 web_contents_destroyed_ = true; | 267 web_contents_destroyed_ = true; |
| 289 CHECK(ongoing_navigations_.empty()); | 268 CHECK(ongoing_navigations_.empty()); |
| 290 CHECK(ongoing_committed_navigations_.empty()); | |
| 291 } | 269 } |
| 292 | 270 |
| 293 WebContentsObserverSanityChecker::WebContentsObserverSanityChecker( | 271 WebContentsObserverSanityChecker::WebContentsObserverSanityChecker( |
| 294 WebContents* web_contents) | 272 WebContents* web_contents) |
| 295 : WebContentsObserver(web_contents), web_contents_destroyed_(false) { | 273 : WebContentsObserver(web_contents), web_contents_destroyed_(false) { |
| 296 // Prime the pump with the initial objects. | 274 // Prime the pump with the initial objects. |
| 297 // TODO(nasko): Investigate why this is needed. | 275 // TODO(nasko): Investigate why this is needed. |
| 298 RenderViewCreated(web_contents->GetRenderViewHost()); | 276 RenderViewCreated(web_contents->GetRenderViewHost()); |
| 299 } | 277 } |
| 300 | 278 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 render_frame_host->GetRoutingID(), | 311 render_frame_host->GetRoutingID(), |
| 334 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); | 312 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); |
| 335 } | 313 } |
| 336 | 314 |
| 337 bool WebContentsObserverSanityChecker::NavigationIsOngoing( | 315 bool WebContentsObserverSanityChecker::NavigationIsOngoing( |
| 338 NavigationHandle* navigation_handle) { | 316 NavigationHandle* navigation_handle) { |
| 339 auto it = ongoing_navigations_.find(navigation_handle); | 317 auto it = ongoing_navigations_.find(navigation_handle); |
| 340 return it != ongoing_navigations_.end(); | 318 return it != ongoing_navigations_.end(); |
| 341 } | 319 } |
| 342 | 320 |
| 343 bool WebContentsObserverSanityChecker::NavigationIsOngoingAndCommitted( | |
| 344 NavigationHandle* navigation_handle) { | |
| 345 auto it = ongoing_committed_navigations_.find(navigation_handle); | |
| 346 return it != ongoing_committed_navigations_.end(); | |
| 347 } | |
| 348 | |
| 349 } // namespace content | 321 } // namespace content |
| OLD | NEW |