OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/frame_host/navigation_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
6 #include "content/browser/web_contents/web_contents_impl.h" | 6 #include "content/browser/web_contents/web_contents_impl.h" |
7 #include "content/public/browser/web_contents.h" | 7 #include "content/public/browser/web_contents.h" |
8 #include "content/public/browser/web_contents_observer.h" | 8 #include "content/public/browser/web_contents_observer.h" |
9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 class NavigationHandleObserver : public WebContentsObserver { | 23 class NavigationHandleObserver : public WebContentsObserver { |
24 public: | 24 public: |
25 NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url) | 25 NavigationHandleObserver(WebContents* web_contents, const GURL& expected_url) |
26 : WebContentsObserver(web_contents), | 26 : WebContentsObserver(web_contents), |
27 handle_(nullptr), | 27 handle_(nullptr), |
28 has_committed_(false), | 28 has_committed_(false), |
29 is_error_(false), | 29 is_error_(false), |
30 is_main_frame_(false), | 30 is_main_frame_(false), |
31 is_parent_main_frame_(false), | 31 is_parent_main_frame_(false), |
32 is_renderer_initiated_(false), | |
32 is_synchronous_(false), | 33 is_synchronous_(false), |
33 is_srcdoc_(false), | 34 is_srcdoc_(false), |
34 was_redirected_(false), | 35 was_redirected_(false), |
35 frame_tree_node_id_(-1), | 36 frame_tree_node_id_(-1), |
36 page_transition_(ui::PAGE_TRANSITION_LINK), | 37 page_transition_(ui::PAGE_TRANSITION_LINK), |
37 expected_url_(expected_url) {} | 38 expected_url_(expected_url) {} |
38 | 39 |
39 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 40 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
40 if (handle_ || navigation_handle->GetURL() != expected_url_) | 41 if (handle_ || navigation_handle->GetURL() != expected_url_) |
41 return; | 42 return; |
42 | 43 |
43 handle_ = navigation_handle; | 44 handle_ = navigation_handle; |
44 has_committed_ = false; | 45 has_committed_ = false; |
45 is_error_ = false; | 46 is_error_ = false; |
46 page_transition_ = ui::PAGE_TRANSITION_LINK; | 47 page_transition_ = ui::PAGE_TRANSITION_LINK; |
47 last_committed_url_ = GURL(); | 48 last_committed_url_ = GURL(); |
48 | 49 |
49 is_main_frame_ = navigation_handle->IsInMainFrame(); | 50 is_main_frame_ = navigation_handle->IsInMainFrame(); |
50 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); | 51 is_parent_main_frame_ = navigation_handle->IsParentMainFrame(); |
52 is_renderer_initiated_ = navigation_handle->IsRendererInitiated(); | |
51 is_synchronous_ = navigation_handle->IsSynchronousNavigation(); | 53 is_synchronous_ = navigation_handle->IsSynchronousNavigation(); |
52 is_srcdoc_ = navigation_handle->IsSrcdoc(); | 54 is_srcdoc_ = navigation_handle->IsSrcdoc(); |
53 was_redirected_ = navigation_handle->WasServerRedirect(); | 55 was_redirected_ = navigation_handle->WasServerRedirect(); |
54 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); | 56 frame_tree_node_id_ = navigation_handle->GetFrameTreeNodeId(); |
55 } | 57 } |
56 | 58 |
57 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | 59 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
58 if (navigation_handle != handle_) | 60 if (navigation_handle != handle_) |
59 return; | 61 return; |
60 | 62 |
(...skipping 18 matching lines...) Expand all Loading... | |
79 is_error_ = true; | 81 is_error_ = true; |
80 } | 82 } |
81 | 83 |
82 handle_ = nullptr; | 84 handle_ = nullptr; |
83 } | 85 } |
84 | 86 |
85 bool has_committed() { return has_committed_; } | 87 bool has_committed() { return has_committed_; } |
86 bool is_error() { return is_error_; } | 88 bool is_error() { return is_error_; } |
87 bool is_main_frame() { return is_main_frame_; } | 89 bool is_main_frame() { return is_main_frame_; } |
88 bool is_parent_main_frame() { return is_parent_main_frame_; } | 90 bool is_parent_main_frame() { return is_parent_main_frame_; } |
91 bool is_renderer_initiated() { return is_renderer_initiated_; } | |
Charlie Reis
2016/05/11 21:50:03
Please actually check this in some of the tests.
dominickn
2016/05/12 04:22:58
Done.
| |
89 bool is_synchronous() { return is_synchronous_; } | 92 bool is_synchronous() { return is_synchronous_; } |
90 bool is_srcdoc() { return is_srcdoc_; } | 93 bool is_srcdoc() { return is_srcdoc_; } |
91 bool was_redirected() { return was_redirected_; } | 94 bool was_redirected() { return was_redirected_; } |
92 int frame_tree_node_id() { return frame_tree_node_id_; } | 95 int frame_tree_node_id() { return frame_tree_node_id_; } |
93 | 96 |
94 const GURL& last_committed_url() { return last_committed_url_; } | 97 const GURL& last_committed_url() { return last_committed_url_; } |
95 | 98 |
96 ui::PageTransition page_transition() { return page_transition_; } | 99 ui::PageTransition page_transition() { return page_transition_; } |
97 | 100 |
98 private: | 101 private: |
99 // A reference to the NavigationHandle so this class will track only | 102 // A reference to the NavigationHandle so this class will track only |
100 // one navigation at a time. It is set at DidStartNavigation and cleared | 103 // one navigation at a time. It is set at DidStartNavigation and cleared |
101 // at DidFinishNavigation before the NavigationHandle is destroyed. | 104 // at DidFinishNavigation before the NavigationHandle is destroyed. |
102 NavigationHandle* handle_; | 105 NavigationHandle* handle_; |
103 bool has_committed_; | 106 bool has_committed_; |
104 bool is_error_; | 107 bool is_error_; |
105 bool is_main_frame_; | 108 bool is_main_frame_; |
106 bool is_parent_main_frame_; | 109 bool is_parent_main_frame_; |
110 bool is_renderer_initiated_; | |
107 bool is_synchronous_; | 111 bool is_synchronous_; |
108 bool is_srcdoc_; | 112 bool is_srcdoc_; |
109 bool was_redirected_; | 113 bool was_redirected_; |
110 int frame_tree_node_id_; | 114 int frame_tree_node_id_; |
111 ui::PageTransition page_transition_; | 115 ui::PageTransition page_transition_; |
112 GURL expected_url_; | 116 GURL expected_url_; |
113 GURL last_committed_url_; | 117 GURL last_committed_url_; |
114 }; | 118 }; |
115 | 119 |
116 // A test NavigationThrottle that will return pre-determined checks and run | 120 // A test NavigationThrottle that will return pre-determined checks and run |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 navigation_observer.Wait(); | 555 navigation_observer.Wait(); |
552 | 556 |
553 EXPECT_TRUE(observer.has_committed()); | 557 EXPECT_TRUE(observer.has_committed()); |
554 EXPECT_TRUE(observer.was_redirected()); | 558 EXPECT_TRUE(observer.was_redirected()); |
555 EXPECT_FALSE(observer.is_error()); | 559 EXPECT_FALSE(observer.is_error()); |
556 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), | 560 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), |
557 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); | 561 GURL(embedded_test_server()->GetURL("bar.com", "/title2.html"))); |
558 } | 562 } |
559 | 563 |
560 } // namespace content | 564 } // namespace content |
OLD | NEW |