| 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()); |
| 131 CHECK(!navigation_handle->HasCommittedErrorPage()); | 130 CHECK(!navigation_handle->IsErrorPage()); |
| 132 | 131 |
| 133 ongoing_navigations_.insert(navigation_handle); | 132 ongoing_navigations_.insert(navigation_handle); |
| 134 } | 133 } |
| 135 | 134 |
| 136 void WebContentsObserverSanityChecker::DidRedirectNavigation( | 135 void WebContentsObserverSanityChecker::DidRedirectNavigation( |
| 137 NavigationHandle* navigation_handle) { | 136 NavigationHandle* navigation_handle) { |
| 138 CHECK(NavigationIsOngoing(navigation_handle)); | 137 CHECK(NavigationIsOngoing(navigation_handle)); |
| 139 CHECK(!NavigationIsOngoingAndCommitted(navigation_handle)); | |
| 140 | 138 |
| 141 CHECK(navigation_handle->GetNetErrorCode() == net::OK); | 139 CHECK(navigation_handle->GetNetErrorCode() == net::OK); |
| 142 CHECK(!navigation_handle->HasCommittedDocument()); | 140 CHECK(!navigation_handle->HasCommitted()); |
| 143 CHECK(!navigation_handle->HasCommittedErrorPage()); | 141 CHECK(!navigation_handle->IsErrorPage()); |
| 144 } | 142 } |
| 145 | 143 |
| 146 void WebContentsObserverSanityChecker::ReadyToCommitNavigation( | 144 void WebContentsObserverSanityChecker::ReadyToCommitNavigation( |
| 147 NavigationHandle* navigation_handle) { | 145 NavigationHandle* navigation_handle) { |
| 148 CHECK(NavigationIsOngoing(navigation_handle)); | 146 CHECK(NavigationIsOngoing(navigation_handle)); |
| 149 CHECK(!NavigationIsOngoingAndCommitted(navigation_handle)); | |
| 150 | 147 |
| 151 CHECK(!navigation_handle->HasCommittedDocument()); | 148 CHECK(!navigation_handle->HasCommitted()); |
| 152 CHECK(!navigation_handle->HasCommittedErrorPage()); | 149 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 } | 150 } |
| 169 | 151 |
| 170 void WebContentsObserverSanityChecker::DidFinishNavigation( | 152 void WebContentsObserverSanityChecker::DidFinishNavigation( |
| 171 NavigationHandle* navigation_handle) { | 153 NavigationHandle* navigation_handle) { |
| 172 CHECK(NavigationIsOngoing(navigation_handle)); | 154 CHECK(NavigationIsOngoing(navigation_handle)); |
| 173 | 155 |
| 174 CHECK_IMPLIES(NavigationIsOngoingAndCommitted(navigation_handle), | 156 CHECK_IMPLIES( |
| 175 navigation_handle->HasCommittedDocument() != | 157 navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage(), |
| 176 navigation_handle->HasCommittedErrorPage()); | 158 navigation_handle->GetNetErrorCode() == net::OK); |
| 177 CHECK_IMPLIES(navigation_handle->HasCommittedDocument(), | 159 CHECK_IMPLIES( |
| 178 navigation_handle->GetNetErrorCode() == net::OK); | 160 navigation_handle->HasCommitted() && navigation_handle->IsErrorPage(), |
| 179 CHECK_IMPLIES(navigation_handle->HasCommittedErrorPage(), | 161 navigation_handle->GetNetErrorCode() != net::OK); |
| 180 navigation_handle->GetNetErrorCode() != net::OK); | |
| 181 | 162 |
| 182 if (NavigationIsOngoingAndCommitted(navigation_handle)) | 163 CHECK_IMPLIES(navigation_handle->HasCommitted(), |
| 183 ongoing_committed_navigations_.erase(navigation_handle); | 164 navigation_handle->GetRenderFrameHost() != nullptr); |
| 184 | 165 |
| 185 ongoing_navigations_.erase(navigation_handle); | 166 ongoing_navigations_.erase(navigation_handle); |
| 186 } | 167 } |
| 187 | 168 |
| 188 void WebContentsObserverSanityChecker::DidStartProvisionalLoadForFrame( | 169 void WebContentsObserverSanityChecker::DidStartProvisionalLoadForFrame( |
| 189 RenderFrameHost* render_frame_host, | 170 RenderFrameHost* render_frame_host, |
| 190 const GURL& validated_url, | 171 const GURL& validated_url, |
| 191 bool is_error_page, | 172 bool is_error_page, |
| 192 bool is_iframe_srcdoc) { | 173 bool is_iframe_srcdoc) { |
| 193 AssertRenderFrameExists(render_frame_host); | 174 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 | 261 // TODO(avi): Disabled because of http://crbug.com/445054 |
| 281 AssertRenderFrameExists(render_frame_host); | 262 AssertRenderFrameExists(render_frame_host); |
| 282 #endif | 263 #endif |
| 283 return false; | 264 return false; |
| 284 } | 265 } |
| 285 | 266 |
| 286 void WebContentsObserverSanityChecker::WebContentsDestroyed() { | 267 void WebContentsObserverSanityChecker::WebContentsDestroyed() { |
| 287 CHECK(!web_contents_destroyed_); | 268 CHECK(!web_contents_destroyed_); |
| 288 web_contents_destroyed_ = true; | 269 web_contents_destroyed_ = true; |
| 289 CHECK(ongoing_navigations_.empty()); | 270 CHECK(ongoing_navigations_.empty()); |
| 290 CHECK(ongoing_committed_navigations_.empty()); | |
| 291 } | 271 } |
| 292 | 272 |
| 293 WebContentsObserverSanityChecker::WebContentsObserverSanityChecker( | 273 WebContentsObserverSanityChecker::WebContentsObserverSanityChecker( |
| 294 WebContents* web_contents) | 274 WebContents* web_contents) |
| 295 : WebContentsObserver(web_contents), web_contents_destroyed_(false) { | 275 : WebContentsObserver(web_contents), web_contents_destroyed_(false) { |
| 296 // Prime the pump with the initial objects. | 276 // Prime the pump with the initial objects. |
| 297 // TODO(nasko): Investigate why this is needed. | 277 // TODO(nasko): Investigate why this is needed. |
| 298 RenderViewCreated(web_contents->GetRenderViewHost()); | 278 RenderViewCreated(web_contents->GetRenderViewHost()); |
| 299 } | 279 } |
| 300 | 280 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 render_frame_host->GetRoutingID(), | 313 render_frame_host->GetRoutingID(), |
| 334 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); | 314 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); |
| 335 } | 315 } |
| 336 | 316 |
| 337 bool WebContentsObserverSanityChecker::NavigationIsOngoing( | 317 bool WebContentsObserverSanityChecker::NavigationIsOngoing( |
| 338 NavigationHandle* navigation_handle) { | 318 NavigationHandle* navigation_handle) { |
| 339 auto it = ongoing_navigations_.find(navigation_handle); | 319 auto it = ongoing_navigations_.find(navigation_handle); |
| 340 return it != ongoing_navigations_.end(); | 320 return it != ongoing_navigations_.end(); |
| 341 } | 321 } |
| 342 | 322 |
| 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 | 323 } // namespace content |
| OLD | NEW |