OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/test/test_frame_navigation_observer.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "base/stl_util.h" |
| 11 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 12 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 TestFrameNavigationObserver::TestFrameNavigationObserver( |
| 21 FrameTreeNode* node, |
| 22 int number_of_navigations) |
| 23 : WebContentsObserver( |
| 24 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 25 frame_tree_node_id_(node->frame_tree_node_id()), |
| 26 navigation_started_(false), |
| 27 navigations_completed_(0), |
| 28 number_of_navigations_(number_of_navigations), |
| 29 message_loop_runner_(new MessageLoopRunner) { |
| 30 } |
| 31 |
| 32 TestFrameNavigationObserver::TestFrameNavigationObserver( |
| 33 FrameTreeNode* node) |
| 34 : WebContentsObserver( |
| 35 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 36 frame_tree_node_id_(node->frame_tree_node_id()), |
| 37 navigation_started_(false), |
| 38 navigations_completed_(0), |
| 39 number_of_navigations_(1), |
| 40 message_loop_runner_(new MessageLoopRunner) { |
| 41 } |
| 42 |
| 43 TestFrameNavigationObserver::~TestFrameNavigationObserver() { |
| 44 } |
| 45 |
| 46 void TestFrameNavigationObserver::Wait() { |
| 47 message_loop_runner_->Run(); |
| 48 } |
| 49 |
| 50 void TestFrameNavigationObserver::DidStartProvisionalLoadForFrame( |
| 51 int64 frame_id, |
| 52 int64 parent_frame_id, |
| 53 bool is_main_frame, |
| 54 const GURL& validated_url, |
| 55 bool is_error_page, |
| 56 bool is_iframe_srcdoc, |
| 57 RenderViewHost* render_view_host) { |
| 58 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID( |
| 59 render_view_host->GetProcess()->GetID(), frame_id); |
| 60 if (!rfh) |
| 61 return; |
| 62 |
| 63 if (rfh->frame_tree_node()->frame_tree_node_id() == frame_tree_node_id_) |
| 64 navigation_started_ = true; |
| 65 } |
| 66 |
| 67 void TestFrameNavigationObserver::DidNavigateAnyFrame( |
| 68 const LoadCommittedDetails& details, |
| 69 const FrameNavigateParams& params) { |
| 70 if (!navigation_started_) |
| 71 return; |
| 72 |
| 73 ++navigations_completed_; |
| 74 if (navigations_completed_ == number_of_navigations_) { |
| 75 navigation_started_ = false; |
| 76 message_loop_runner_->Quit(); |
| 77 } |
| 78 } |
| 79 |
| 80 } // namespace content |
OLD | NEW |