OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/public/test/navigation_handle_observer.h" |
| 6 |
| 7 #include "content/public/browser/navigation_handle.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 NavigationHandleObserver::NavigationHandleObserver( |
| 12 WebContents* web_contents, |
| 13 const GURL& expected_start_url) |
| 14 : WebContentsObserver(web_contents), |
| 15 page_transition_(ui::PAGE_TRANSITION_LINK), |
| 16 expected_start_url_(expected_start_url) {} |
| 17 |
| 18 void NavigationHandleObserver::DidStartNavigation( |
| 19 NavigationHandle* navigation_handle) { |
| 20 if (handle_ || navigation_handle->GetURL() != expected_start_url_) |
| 21 return; |
| 22 |
| 23 handle_ = navigation_handle; |
| 24 has_committed_ = false; |
| 25 is_error_ = false; |
| 26 page_transition_ = ui::PAGE_TRANSITION_LINK; |
| 27 last_committed_url_ = GURL(); |
| 28 |
| 29 is_main_frame_ = navigation_handle->IsInMainFrame(); |
| 30 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); |
| 31 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); |
| 32 is_same_document_ = navigation_handle->IsSameDocument(); |
| 33 was_redirected_ = navigation_handle->WasServerRedirect(); |
| 34 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); |
| 35 } |
| 36 |
| 37 void NavigationHandleObserver::DidFinishNavigation( |
| 38 NavigationHandle* navigation_handle) { |
| 39 if (navigation_handle != handle_) |
| 40 return; |
| 41 |
| 42 DCHECK_EQ(is_main_frame_, navigation_handle->IsInMainFrame()); |
| 43 DCHECK_EQ(is_parent_main_frame_, navigation_handle->IsParentMainFrame()); |
| 44 DCHECK_EQ(is_same_document_, navigation_handle->IsSameDocument()); |
| 45 DCHECK_EQ(is_renderer_initiated_, navigation_handle->IsRendererInitiated()); |
| 46 DCHECK_EQ(frame_tree_node_id_, navigation_handle->GetFrameTreeNodeId()); |
| 47 |
| 48 was_redirected_ = navigation_handle->WasServerRedirect(); |
| 49 net_error_code_ = navigation_handle->GetNetErrorCode(); |
| 50 |
| 51 if (navigation_handle->HasCommitted()) { |
| 52 has_committed_ = true; |
| 53 if (!navigation_handle->IsErrorPage()) { |
| 54 page_transition_ = navigation_handle->GetPageTransition(); |
| 55 last_committed_url_ = navigation_handle->GetURL(); |
| 56 } else { |
| 57 is_error_ = true; |
| 58 } |
| 59 } else { |
| 60 has_committed_ = false; |
| 61 is_error_ = true; |
| 62 } |
| 63 |
| 64 handle_ = nullptr; |
| 65 } |
| 66 |
| 67 } // namespace content |
OLD | NEW |