OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/test/test_navigation_observer.h" | 5 #include "content/public/test/test_navigation_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE { | 41 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE { |
42 parent_->OnDidStartLoading(web_contents()); | 42 parent_->OnDidStartLoading(web_contents()); |
43 } | 43 } |
44 | 44 |
45 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE { | 45 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE { |
46 parent_->OnDidStopLoading(web_contents()); | 46 parent_->OnDidStopLoading(web_contents()); |
47 } | 47 } |
48 | 48 |
49 virtual void DidFirstVisuallyNonEmptyPaint() OVERRIDE { | |
50 parent_->OnDidFirstVisuallyNonEmptyPaint(web_contents()); | |
51 } | |
52 | |
53 TestNavigationObserver* parent_; | 49 TestNavigationObserver* parent_; |
54 | 50 |
55 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); | 51 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); |
56 }; | 52 }; |
57 | 53 |
58 TestNavigationObserver::TestNavigationObserver( | 54 TestNavigationObserver::TestNavigationObserver( |
59 WebContents* web_contents, | 55 WebContents* web_contents, |
60 int number_of_navigations, | |
61 FirstPaint first_paint) | |
62 : navigation_started_(false), | |
63 navigations_completed_(0), | |
64 number_of_navigations_(number_of_navigations), | |
65 first_paint_(first_paint), | |
66 message_loop_runner_(new MessageLoopRunner), | |
67 web_contents_created_callback_( | |
68 base::Bind( | |
69 &TestNavigationObserver::OnWebContentsCreated, | |
70 base::Unretained(this))) { | |
71 if (web_contents) | |
72 RegisterAsObserver(web_contents); | |
73 } | |
74 | |
75 TestNavigationObserver::TestNavigationObserver( | |
76 WebContents* web_contents, | |
77 int number_of_navigations) | 56 int number_of_navigations) |
78 : navigation_started_(false), | 57 : navigation_started_(false), |
79 navigations_completed_(0), | 58 navigations_completed_(0), |
80 number_of_navigations_(number_of_navigations), | 59 number_of_navigations_(number_of_navigations), |
81 first_paint_(FirstPaintNotRequired), | |
82 message_loop_runner_(new MessageLoopRunner), | 60 message_loop_runner_(new MessageLoopRunner), |
83 web_contents_created_callback_( | 61 web_contents_created_callback_( |
84 base::Bind( | 62 base::Bind( |
85 &TestNavigationObserver::OnWebContentsCreated, | 63 &TestNavigationObserver::OnWebContentsCreated, |
86 base::Unretained(this))) { | 64 base::Unretained(this))) { |
87 if (web_contents) | 65 if (web_contents) |
88 RegisterAsObserver(web_contents); | 66 RegisterAsObserver(web_contents); |
89 } | 67 } |
90 | 68 |
91 TestNavigationObserver::TestNavigationObserver( | 69 TestNavigationObserver::TestNavigationObserver( |
92 WebContents* web_contents) | 70 WebContents* web_contents) |
93 : navigation_started_(false), | 71 : navigation_started_(false), |
94 navigations_completed_(0), | 72 navigations_completed_(0), |
95 number_of_navigations_(1), | 73 number_of_navigations_(1), |
96 first_paint_(FirstPaintNotRequired), | |
97 message_loop_runner_(new MessageLoopRunner), | 74 message_loop_runner_(new MessageLoopRunner), |
98 web_contents_created_callback_( | 75 web_contents_created_callback_( |
99 base::Bind( | 76 base::Bind( |
100 &TestNavigationObserver::OnWebContentsCreated, | 77 &TestNavigationObserver::OnWebContentsCreated, |
101 base::Unretained(this))) { | 78 base::Unretained(this))) { |
102 if (web_contents) | 79 if (web_contents) |
103 RegisterAsObserver(web_contents); | 80 RegisterAsObserver(web_contents); |
104 } | 81 } |
105 | 82 |
106 TestNavigationObserver::~TestNavigationObserver() { | 83 TestNavigationObserver::~TestNavigationObserver() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 131 |
155 void TestNavigationObserver::OnDidStartLoading(WebContents* web_contents) { | 132 void TestNavigationObserver::OnDidStartLoading(WebContents* web_contents) { |
156 navigation_started_ = true; | 133 navigation_started_ = true; |
157 } | 134 } |
158 | 135 |
159 void TestNavigationObserver::OnDidStopLoading(WebContents* web_contents) { | 136 void TestNavigationObserver::OnDidStopLoading(WebContents* web_contents) { |
160 if (!navigation_started_) | 137 if (!navigation_started_) |
161 return; | 138 return; |
162 | 139 |
163 ++navigations_completed_; | 140 ++navigations_completed_; |
164 if ((navigations_completed_ == number_of_navigations_) && | 141 if (navigations_completed_ == number_of_navigations_) { |
165 first_paint_ == FirstPaintNotRequired) { | |
166 navigation_started_ = false; | 142 navigation_started_ = false; |
167 message_loop_runner_->Quit(); | 143 message_loop_runner_->Quit(); |
168 } | 144 } |
169 } | |
170 | |
171 void TestNavigationObserver::OnDidFirstVisuallyNonEmptyPaint( | |
172 WebContents* web_contents) { | |
173 if (!navigation_started_) | |
174 return; | |
175 | |
176 if ((navigations_completed_ == number_of_navigations_) && | |
177 first_paint_ == FirstPaintRequired) { | |
178 navigation_started_ = false; | |
179 message_loop_runner_->Quit(); | |
180 } | |
181 } | 145 } |
182 | 146 |
183 } // namespace content | 147 } // namespace content |
OLD | NEW |