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