OLD | NEW |
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 #ifndef CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ | 5 #ifndef CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ |
6 #define CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ | 6 #define CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "content/public/browser/navigation_details.h" | |
14 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
16 | 15 |
17 class GURL; | 16 class GURL; |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 class FrameTreeNode; | 19 class FrameTreeNode; |
21 class RenderFrameHostImpl; | 20 class RenderFrameHostImpl; |
22 class WebContents; | 21 class WebContents; |
| 22 struct LoadCommittedDetails; |
23 | 23 |
24 // For content_browsertests, which run on the UI thread, run a second | 24 // For content_browsertests, which run on the UI thread, run a second |
25 // MessageLoop and quit when the navigation in a specific frame completes | 25 // MessageLoop and quit when the navigation in a specific frame completes |
26 // loading. | 26 // loading. |
27 class TestFrameNavigationObserver : public WebContentsObserver { | 27 class TestFrameNavigationObserver : public WebContentsObserver { |
28 public: | 28 public: |
29 // Create and register a new TestFrameNavigationObserver which will track | 29 // Create and register a new TestFrameNavigationObserver which will track |
30 // navigations performed in the specified |node| of the frame tree. | 30 // navigations performed in the specified |node| of the frame tree. |
31 TestFrameNavigationObserver(FrameTreeNode* node, int number_of_navigations); | 31 TestFrameNavigationObserver(FrameTreeNode* node, int number_of_navigations); |
32 // As above but waits for one navigation. | 32 // As above but waits for one navigation. |
33 explicit TestFrameNavigationObserver(FrameTreeNode* node); | 33 explicit TestFrameNavigationObserver(FrameTreeNode* node); |
34 | 34 |
35 ~TestFrameNavigationObserver() override; | 35 ~TestFrameNavigationObserver() override; |
36 | 36 |
37 // Runs a nested message loop and blocks until the expected number of | 37 // Runs a nested message loop and blocks until the expected number of |
38 // navigations are complete. | 38 // navigations are complete. |
39 void Wait(); | 39 void Wait(); |
40 | 40 |
41 // Returns the LoadCommittedDetails for the last navigation to commit. | |
42 const LoadCommittedDetails& load_committed_details() const { | |
43 return load_committed_details_; | |
44 } | |
45 | |
46 private: | 41 private: |
47 // WebContentsObserver | 42 // WebContentsObserver |
48 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, | 43 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, |
49 const GURL& validated_url, | 44 const GURL& validated_url, |
50 bool is_error_page, | 45 bool is_error_page, |
51 bool is_iframe_srcdoc) override; | 46 bool is_iframe_srcdoc) override; |
52 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, | 47 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, |
53 const LoadCommittedDetails& details, | 48 const LoadCommittedDetails& details, |
54 const FrameNavigateParams& params) override; | 49 const FrameNavigateParams& params) override; |
55 | 50 |
56 // The id of the FrameTreeNode in which navigations are peformed. | 51 // The id of the FrameTreeNode in which navigations are peformed. |
57 int frame_tree_node_id_; | 52 int frame_tree_node_id_; |
58 | 53 |
59 // If true the navigation has started. | 54 // If true the navigation has started. |
60 bool navigation_started_; | 55 bool navigation_started_; |
61 | 56 |
62 // The number of navigations that have been completed. | 57 // The number of navigations that have been completed. |
63 int navigations_completed_; | 58 int navigations_completed_; |
64 | 59 |
65 // The number of navigations to wait for. | 60 // The number of navigations to wait for. |
66 int number_of_navigations_; | 61 int number_of_navigations_; |
67 | 62 |
68 LoadCommittedDetails load_committed_details_; | |
69 | |
70 // The MessageLoopRunner used to spin the message loop. | 63 // The MessageLoopRunner used to spin the message loop. |
71 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 64 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
72 | 65 |
73 DISALLOW_COPY_AND_ASSIGN(TestFrameNavigationObserver); | 66 DISALLOW_COPY_AND_ASSIGN(TestFrameNavigationObserver); |
74 }; | 67 }; |
75 | 68 |
76 } // namespace content | 69 } // namespace content |
77 | 70 |
78 #endif // CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ | 71 #endif // CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ |
OLD | NEW |