| 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 |
| 49 TestNavigationObserver* parent_; | 53 TestNavigationObserver* parent_; |
| 50 | 54 |
| 51 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); | 55 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); |
| 52 }; | 56 }; |
| 53 | 57 |
| 54 TestNavigationObserver::TestNavigationObserver( | 58 TestNavigationObserver::TestNavigationObserver( |
| 55 WebContents* web_contents, | 59 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, |
| 56 int number_of_navigations) | 77 int number_of_navigations) |
| 57 : navigation_started_(false), | 78 : navigation_started_(false), |
| 58 navigations_completed_(0), | 79 navigations_completed_(0), |
| 59 number_of_navigations_(number_of_navigations), | 80 number_of_navigations_(number_of_navigations), |
| 81 first_paint_(FirstPaintNotRequired), |
| 60 message_loop_runner_(new MessageLoopRunner), | 82 message_loop_runner_(new MessageLoopRunner), |
| 61 web_contents_created_callback_( | 83 web_contents_created_callback_( |
| 62 base::Bind( | 84 base::Bind( |
| 63 &TestNavigationObserver::OnWebContentsCreated, | 85 &TestNavigationObserver::OnWebContentsCreated, |
| 64 base::Unretained(this))) { | 86 base::Unretained(this))) { |
| 65 if (web_contents) | 87 if (web_contents) |
| 66 RegisterAsObserver(web_contents); | 88 RegisterAsObserver(web_contents); |
| 67 } | 89 } |
| 68 | 90 |
| 69 TestNavigationObserver::TestNavigationObserver( | 91 TestNavigationObserver::TestNavigationObserver( |
| 70 WebContents* web_contents) | 92 WebContents* web_contents) |
| 71 : navigation_started_(false), | 93 : navigation_started_(false), |
| 72 navigations_completed_(0), | 94 navigations_completed_(0), |
| 73 number_of_navigations_(1), | 95 number_of_navigations_(1), |
| 96 first_paint_(FirstPaintNotRequired), |
| 74 message_loop_runner_(new MessageLoopRunner), | 97 message_loop_runner_(new MessageLoopRunner), |
| 75 web_contents_created_callback_( | 98 web_contents_created_callback_( |
| 76 base::Bind( | 99 base::Bind( |
| 77 &TestNavigationObserver::OnWebContentsCreated, | 100 &TestNavigationObserver::OnWebContentsCreated, |
| 78 base::Unretained(this))) { | 101 base::Unretained(this))) { |
| 79 if (web_contents) | 102 if (web_contents) |
| 80 RegisterAsObserver(web_contents); | 103 RegisterAsObserver(web_contents); |
| 81 } | 104 } |
| 82 | 105 |
| 83 TestNavigationObserver::~TestNavigationObserver() { | 106 TestNavigationObserver::~TestNavigationObserver() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 154 |
| 132 void TestNavigationObserver::OnDidStartLoading(WebContents* web_contents) { | 155 void TestNavigationObserver::OnDidStartLoading(WebContents* web_contents) { |
| 133 navigation_started_ = true; | 156 navigation_started_ = true; |
| 134 } | 157 } |
| 135 | 158 |
| 136 void TestNavigationObserver::OnDidStopLoading(WebContents* web_contents) { | 159 void TestNavigationObserver::OnDidStopLoading(WebContents* web_contents) { |
| 137 if (!navigation_started_) | 160 if (!navigation_started_) |
| 138 return; | 161 return; |
| 139 | 162 |
| 140 ++navigations_completed_; | 163 ++navigations_completed_; |
| 141 if (navigations_completed_ == number_of_navigations_) { | 164 if ((navigations_completed_ == number_of_navigations_) && |
| 165 first_paint_ == FirstPaintNotRequired) { |
| 142 navigation_started_ = false; | 166 navigation_started_ = false; |
| 143 message_loop_runner_->Quit(); | 167 message_loop_runner_->Quit(); |
| 144 } | 168 } |
| 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 } |
| 145 } | 181 } |
| 146 | 182 |
| 147 } // namespace content | 183 } // namespace content |
| OLD | NEW |