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