Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: content/test/test_frame_navigation_observer.cc

Issue 1816733002: Change TestFrameNavigationObserver to wait for load stop instead of commit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded observer and Wait call. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/test_frame_navigation_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/test/test_frame_navigation_observer.h" 5 #include "content/test/test_frame_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"
11 #include "content/browser/frame_host/navigation_entry_impl.h" 11 #include "content/browser/frame_host/navigation_entry_impl.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 12 #include "content/browser/frame_host/render_frame_host_impl.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/web_contents/web_contents_impl.h" 14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 TestFrameNavigationObserver::TestFrameNavigationObserver( 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) 21 FrameTreeNode* node)
34 : WebContentsObserver( 22 : WebContentsObserver(
35 node->current_frame_host()->delegate()->GetAsWebContents()), 23 node->current_frame_host()->delegate()->GetAsWebContents()),
36 frame_tree_node_id_(node->frame_tree_node_id()), 24 frame_tree_node_id_(node->frame_tree_node_id()),
37 navigation_started_(false), 25 navigation_started_(false),
38 navigations_completed_(0), 26 has_committed_(false),
39 number_of_navigations_(1), 27 wait_for_commit_(false),
40 message_loop_runner_(new MessageLoopRunner) { 28 message_loop_runner_(new MessageLoopRunner) {
41 } 29 }
42 30
43 TestFrameNavigationObserver::~TestFrameNavigationObserver() { 31 TestFrameNavigationObserver::~TestFrameNavigationObserver() {
44 } 32 }
45 33
46 void TestFrameNavigationObserver::Wait() { 34 void TestFrameNavigationObserver::Wait() {
35 wait_for_commit_ = false;
47 message_loop_runner_->Run(); 36 message_loop_runner_->Run();
48 } 37 }
49 38
39 void TestFrameNavigationObserver::WaitForCommit() {
40 if (has_committed_)
41 return;
42
43 wait_for_commit_ = true;
44 message_loop_runner_->Run();
45 }
46
50 void TestFrameNavigationObserver::DidStartProvisionalLoadForFrame( 47 void TestFrameNavigationObserver::DidStartProvisionalLoadForFrame(
51 RenderFrameHost* render_frame_host, 48 RenderFrameHost* render_frame_host,
52 const GURL& validated_url, 49 const GURL& validated_url,
53 bool is_error_page, 50 bool is_error_page,
54 bool is_iframe_srcdoc) { 51 bool is_iframe_srcdoc) {
55 RenderFrameHostImpl* rfh = 52 RenderFrameHostImpl* rfh =
56 static_cast<RenderFrameHostImpl*>(render_frame_host); 53 static_cast<RenderFrameHostImpl*>(render_frame_host);
57 if (rfh->frame_tree_node()->frame_tree_node_id() == frame_tree_node_id_) 54 if (rfh->frame_tree_node()->frame_tree_node_id() == frame_tree_node_id_) {
58 navigation_started_ = true; 55 navigation_started_ = true;
56 has_committed_ = false;
57 }
59 } 58 }
60 59
61 void TestFrameNavigationObserver::DidCommitProvisionalLoadForFrame( 60 void TestFrameNavigationObserver::DidCommitProvisionalLoadForFrame(
62 RenderFrameHost* render_frame_host, 61 RenderFrameHost* render_frame_host,
63 const GURL& url, 62 const GURL& url,
64 ui::PageTransition transition_type) { 63 ui::PageTransition transition_type) {
65 if (!navigation_started_) 64 if (!navigation_started_)
66 return; 65 return;
67 66
68 ++navigations_completed_; 67 RenderFrameHostImpl* rfh =
69 if (navigations_completed_ == number_of_navigations_) { 68 static_cast<RenderFrameHostImpl*>(render_frame_host);
70 navigation_started_ = false; 69 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_)
70 return;
71
72 has_committed_ = true;
73 if (wait_for_commit_)
71 message_loop_runner_->Quit(); 74 message_loop_runner_->Quit();
72 } 75 }
76
77 void TestFrameNavigationObserver::DidStopLoading() {
78 if (!navigation_started_)
79 return;
80
81 navigation_started_ = false;
82 message_loop_runner_->Quit();
73 } 83 }
74 84
75 } // namespace content 85 } // namespace content
OLDNEW
« no previous file with comments | « content/test/test_frame_navigation_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698