| 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 <memory> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/macros.h" | 8 #include "base/macros.h" |
| 14 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/test_utils.h" | |
| 18 | |
| 19 class GURL; | |
| 20 | 12 |
| 21 namespace content { | 13 namespace content { |
| 22 class RenderFrameHost; | |
| 23 | 14 |
| 24 // Helper for waiting until the navigation in a specific frame tree node (and | 15 // Helper for waiting until the navigation in a specific frame tree node (and |
| 25 // all of its subframes) has completed loading. | 16 // all of its subframes) has completed loading. |
| 26 class TestFrameNavigationObserver : public WebContentsObserver { | 17 class TestFrameNavigationObserver : public WebContentsObserver { |
| 27 public: | 18 public: |
| 28 // Create and register a new TestFrameNavigationObserver which will track | 19 // Create and register a new TestFrameNavigationObserver which will track |
| 29 // navigations performed in the frame tree node associated with |adapter|. | 20 // navigations performed in the frame tree node associated with |adapter|. |
| 30 // Note that RenderFrameHost associated with |frame| might be destroyed during | 21 // Note that RenderFrameHost associated with |frame| might be destroyed during |
| 31 // the navigation (e.g. if the content commits in a new renderer process). | 22 // the navigation (e.g. if the content commits in a new renderer process). |
| 32 explicit TestFrameNavigationObserver(const ToRenderFrameHost& adapter); | 23 explicit TestFrameNavigationObserver(const ToRenderFrameHost& adapter); |
| 33 | 24 |
| 34 ~TestFrameNavigationObserver() override; | 25 ~TestFrameNavigationObserver() override; |
| 35 | 26 |
| 36 // Runs a nested message loop and blocks until the full load has | 27 // Runs a nested message loop and blocks until the full load has |
| 37 // completed. | 28 // completed. |
| 38 void Wait(); | 29 void Wait(); |
| 39 | 30 |
| 40 // Runs a nested message loop and blocks until the navigation in the | 31 // Runs a nested message loop and blocks until the navigation in the |
| 41 // associated FrameTreeNode has committed. | 32 // associated FrameTreeNode has committed. |
| 42 void WaitForCommit(); | 33 void WaitForCommit(); |
| 43 | 34 |
| 44 private: | 35 private: |
| 45 // WebContentsObserver | 36 // WebContentsObserver |
| 46 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, | 37 void DidStartNavigation(NavigationHandle* navigation_handle) override; |
| 47 const GURL& validated_url, | 38 void DidFinishNavigation(NavigationHandle* navigation_handle) override; |
| 48 bool is_error_page) override; | |
| 49 void DidCommitProvisionalLoadForFrame( | |
| 50 RenderFrameHost* render_frame_host, | |
| 51 const GURL& url, | |
| 52 ui::PageTransition transition_type) override; | |
| 53 void DidStopLoading() override; | 39 void DidStopLoading() override; |
| 54 | 40 |
| 55 // The id of the FrameTreeNode in which navigations are peformed. | 41 // The id of the FrameTreeNode in which navigations are peformed. |
| 56 int frame_tree_node_id_; | 42 int frame_tree_node_id_; |
| 57 | 43 |
| 58 // If true the navigation has started. | 44 // If true the navigation has started. |
| 59 bool navigation_started_; | 45 bool navigation_started_; |
| 60 | 46 |
| 61 // If true, the navigation has committed. | 47 // If true, the navigation has committed. |
| 62 bool has_committed_; | 48 bool has_committed_; |
| 63 | 49 |
| 64 // If true, this object is waiting for commit only, not for the full load | 50 // If true, this object is waiting for commit only, not for the full load |
| 65 // of the document. | 51 // of the document. |
| 66 bool wait_for_commit_; | 52 bool wait_for_commit_; |
| 67 | 53 |
| 68 // The RunLoop used to spin the message loop. | 54 // The RunLoop used to spin the message loop. |
| 69 base::RunLoop run_loop_; | 55 base::RunLoop run_loop_; |
| 70 | 56 |
| 71 DISALLOW_COPY_AND_ASSIGN(TestFrameNavigationObserver); | 57 DISALLOW_COPY_AND_ASSIGN(TestFrameNavigationObserver); |
| 72 }; | 58 }; |
| 73 | 59 |
| 74 } // namespace content | 60 } // namespace content |
| 75 | 61 |
| 76 #endif // CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ | 62 #endif // CONTENT_TEST_TEST_FRAME_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |