| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ |
| 6 #define CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ | 6 #define CONTENT_PUBLIC_TEST_TEST_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/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class WebContents; | 16 class WebContents; |
| 17 struct LoadCommittedDetails; | 17 struct LoadCommittedDetails; |
| 18 | 18 |
| 19 // For browser_tests, which run on the UI thread, run a second | 19 // For browser_tests, which run on the UI thread, run a second |
| 20 // MessageLoop and quit when the navigation completes loading. | 20 // MessageLoop and quit when the navigation completes loading. |
| 21 class TestNavigationObserver { | 21 class TestNavigationObserver { |
| 22 public: | 22 public: |
| 23 enum FirstPaint { | |
| 24 FirstPaintRequired, | |
| 25 FirstPaintNotRequired | |
| 26 }; | |
| 27 | |
| 28 // Create and register a new TestNavigationObserver against the | 23 // Create and register a new TestNavigationObserver against the |
| 29 // |web_contents|. | 24 // |web_contents|. |
| 30 TestNavigationObserver(WebContents* web_contents, | 25 TestNavigationObserver(WebContents* web_contents, |
| 31 int number_of_navigations, | |
| 32 FirstPaint first_paint); | |
| 33 // Like above but doesn't wait for the first paint after the navigations. | |
| 34 TestNavigationObserver(WebContents* web_contents, | |
| 35 int number_of_navigations); | 26 int number_of_navigations); |
| 36 // Like above but waits for one navigation. | 27 // Like above but waits for one navigation. |
| 37 explicit TestNavigationObserver(WebContents* web_contents); | 28 explicit TestNavigationObserver(WebContents* web_contents); |
| 38 | 29 |
| 39 virtual ~TestNavigationObserver(); | 30 virtual ~TestNavigationObserver(); |
| 40 | 31 |
| 41 // Runs a nested message loop and blocks until the expected number of | 32 // Runs a nested message loop and blocks until the expected number of |
| 42 // navigations are complete. | 33 // navigations are complete. |
| 43 void Wait(); | 34 void Wait(); |
| 44 | 35 |
| 45 // Runs a nested message loop and blocks until the expected | |
| 46 | |
| 47 // Start/stop watching newly created WebContents. | 36 // Start/stop watching newly created WebContents. |
| 48 void StartWatchingNewWebContents(); | 37 void StartWatchingNewWebContents(); |
| 49 void StopWatchingNewWebContents(); | 38 void StopWatchingNewWebContents(); |
| 50 | 39 |
| 51 protected: | 40 protected: |
| 52 // Register this TestNavigationObserver as an observer of the |web_contents|. | 41 // Register this TestNavigationObserver as an observer of the |web_contents|. |
| 53 void RegisterAsObserver(WebContents* web_contents); | 42 void RegisterAsObserver(WebContents* web_contents); |
| 54 | 43 |
| 55 private: | 44 private: |
| 56 class TestWebContentsObserver; | 45 class TestWebContentsObserver; |
| 57 | 46 |
| 58 // Callbacks for WebContents-related events. | 47 // Callbacks for WebContents-related events. |
| 59 void OnWebContentsCreated(WebContents* web_contents); | 48 void OnWebContentsCreated(WebContents* web_contents); |
| 60 void OnWebContentsDestroyed(TestWebContentsObserver* observer, | 49 void OnWebContentsDestroyed(TestWebContentsObserver* observer, |
| 61 WebContents* web_contents); | 50 WebContents* web_contents); |
| 62 void OnNavigationEntryCommitted( | 51 void OnNavigationEntryCommitted( |
| 63 TestWebContentsObserver* observer, | 52 TestWebContentsObserver* observer, |
| 64 WebContents* web_contents, | 53 WebContents* web_contents, |
| 65 const LoadCommittedDetails& load_details); | 54 const LoadCommittedDetails& load_details); |
| 66 void OnDidAttachInterstitialPage(WebContents* web_contents); | 55 void OnDidAttachInterstitialPage(WebContents* web_contents); |
| 67 void OnDidStartLoading(WebContents* web_contents); | 56 void OnDidStartLoading(WebContents* web_contents); |
| 68 void OnDidStopLoading(WebContents* web_contents); | 57 void OnDidStopLoading(WebContents* web_contents); |
| 69 void OnDidFirstVisuallyNonEmptyPaint(WebContents* web_contents); | |
| 70 | 58 |
| 71 // If true the navigation has started. | 59 // If true the navigation has started. |
| 72 bool navigation_started_; | 60 bool navigation_started_; |
| 73 | 61 |
| 74 // The number of navigations that have been completed. | 62 // The number of navigations that have been completed. |
| 75 int navigations_completed_; | 63 int navigations_completed_; |
| 76 | 64 |
| 77 // The number of navigations to wait for. | 65 // The number of navigations to wait for. |
| 78 int number_of_navigations_; | 66 int number_of_navigations_; |
| 79 | 67 |
| 80 // Whether we want to wait for first paint after navigations. | |
| 81 FirstPaint first_paint_; | |
| 82 | |
| 83 // The MessageLoopRunner used to spin the message loop. | 68 // The MessageLoopRunner used to spin the message loop. |
| 84 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 69 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 85 | 70 |
| 86 // Callback invoked on WebContents creation. | 71 // Callback invoked on WebContents creation. |
| 87 base::Callback<void(WebContents*)> web_contents_created_callback_; | 72 base::Callback<void(WebContents*)> web_contents_created_callback_; |
| 88 | 73 |
| 89 // Living TestWebContentsObservers created by this observer. | 74 // Living TestWebContentsObservers created by this observer. |
| 90 std::set<TestWebContentsObserver*> web_contents_observers_; | 75 std::set<TestWebContentsObserver*> web_contents_observers_; |
| 91 | 76 |
| 92 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); | 77 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); |
| 93 }; | 78 }; |
| 94 | 79 |
| 95 } // namespace content | 80 } // namespace content |
| 96 | 81 |
| 97 #endif // CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ | 82 #endif // CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |