Chromium Code Reviews| 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 <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
| 14 #include "net/base/net_errors.h" | |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 class WebContents; | 18 class WebContents; |
| 18 | 19 |
| 19 // For browser_tests, which run on the UI thread, run a second | 20 // For browser_tests, which run on the UI thread, run a second |
| 20 // MessageLoop and quit when the navigation completes loading. | 21 // MessageLoop and quit when the navigation completes loading. |
| 21 class TestNavigationObserver { | 22 class TestNavigationObserver { |
| 22 public: | 23 public: |
| 23 // Create and register a new TestNavigationObserver against the | 24 // Create and register a new TestNavigationObserver against the |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 36 // Runs a nested run loop and blocks until the expected number of | 37 // Runs a nested run loop and blocks until the expected number of |
| 37 // navigations are complete. | 38 // navigations are complete. |
| 38 void Wait(); | 39 void Wait(); |
| 39 | 40 |
| 40 // Start/stop watching newly created WebContents. | 41 // Start/stop watching newly created WebContents. |
| 41 void StartWatchingNewWebContents(); | 42 void StartWatchingNewWebContents(); |
| 42 void StopWatchingNewWebContents(); | 43 void StopWatchingNewWebContents(); |
| 43 | 44 |
| 44 const GURL& last_navigation_url() const { return last_navigation_url_; } | 45 const GURL& last_navigation_url() const { return last_navigation_url_; } |
| 45 | 46 |
| 46 int last_navigation_succeeded() const { return last_navigation_succeeded_; } | 47 bool last_navigation_succeeded() const { return last_navigation_succeeded_; } |
| 48 | |
| 49 net::Error last_net_error_code() const { return last_net_error_code_; } | |
| 47 | 50 |
| 48 protected: | 51 protected: |
| 49 // Register this TestNavigationObserver as an observer of the |web_contents|. | 52 // Register this TestNavigationObserver as an observer of the |web_contents|. |
| 50 void RegisterAsObserver(WebContents* web_contents); | 53 void RegisterAsObserver(WebContents* web_contents); |
| 51 | 54 |
| 52 private: | 55 private: |
| 53 class TestWebContentsObserver; | 56 class TestWebContentsObserver; |
| 54 | 57 |
| 55 // Callbacks for WebContents-related events. | 58 // Callbacks for WebContents-related events. |
| 56 void OnWebContentsCreated(WebContents* web_contents); | 59 void OnWebContentsCreated(WebContents* web_contents); |
| 57 void OnWebContentsDestroyed(TestWebContentsObserver* observer, | 60 void OnWebContentsDestroyed(TestWebContentsObserver* observer, |
| 58 WebContents* web_contents); | 61 WebContents* web_contents); |
| 59 void OnNavigationEntryCommitted( | 62 void OnNavigationEntryCommitted( |
| 60 TestWebContentsObserver* observer, | 63 TestWebContentsObserver* observer, |
| 61 WebContents* web_contents, | 64 WebContents* web_contents, |
| 62 const LoadCommittedDetails& load_details); | 65 const LoadCommittedDetails& load_details); |
| 63 void OnDidAttachInterstitialPage(WebContents* web_contents); | 66 void OnDidAttachInterstitialPage(WebContents* web_contents); |
| 64 void OnDidStartLoading(WebContents* web_contents); | 67 void OnDidStartLoading(WebContents* web_contents); |
| 65 void OnDidStopLoading(WebContents* web_contents); | 68 void OnDidStopLoading(WebContents* web_contents); |
| 66 void OnDidStartNavigation(); | 69 void OnDidStartNavigation(); |
| 67 void OnDidFinishNavigation(bool is_error_page, const GURL& url); | 70 void OnDidFinishNavigation(bool is_error_page, |
| 71 const GURL& url, | |
| 72 net::Error error_code); | |
| 68 | 73 |
| 69 // If true the navigation has started. | 74 // If true the navigation has started. |
| 70 bool navigation_started_; | 75 bool navigation_started_; |
| 71 | 76 |
| 72 // The number of navigations that have been completed. | 77 // The number of navigations that have been completed. |
| 73 int navigations_completed_; | 78 int navigations_completed_; |
| 74 | 79 |
| 75 // The number of navigations to wait for. | 80 // The number of navigations to wait for. |
| 76 int number_of_navigations_; | 81 int number_of_navigations_; |
| 77 | 82 |
| 78 // The url of the navigation that last committed. | 83 // The url of the navigation that last committed. |
| 79 GURL last_navigation_url_; | 84 GURL last_navigation_url_; |
| 80 | 85 |
| 81 // True if the last navigation succeeded. | 86 // True if the last navigation succeeded. |
| 82 bool last_navigation_succeeded_; | 87 bool last_navigation_succeeded_; |
| 83 | 88 |
| 89 // The net error code of the last navigation. | |
| 90 net::Error last_net_error_code_; | |
|
sky
2017/06/06 17:18:26
Doesn't this need to be initialized?
satorux1
2017/06/07 08:00:38
Good catch. Done!
| |
| 91 | |
| 84 // The MessageLoopRunner used to spin the message loop. | 92 // The MessageLoopRunner used to spin the message loop. |
| 85 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 93 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 86 | 94 |
| 87 // Callback invoked on WebContents creation. | 95 // Callback invoked on WebContents creation. |
| 88 base::Callback<void(WebContents*)> web_contents_created_callback_; | 96 base::Callback<void(WebContents*)> web_contents_created_callback_; |
| 89 | 97 |
| 90 // Living TestWebContentsObservers created by this observer. | 98 // Living TestWebContentsObservers created by this observer. |
| 91 std::set<std::unique_ptr<TestWebContentsObserver>> web_contents_observers_; | 99 std::set<std::unique_ptr<TestWebContentsObserver>> web_contents_observers_; |
| 92 | 100 |
| 93 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); | 101 DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); |
| 94 }; | 102 }; |
| 95 | 103 |
| 96 } // namespace content | 104 } // namespace content |
| 97 | 105 |
| 98 #endif // CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ | 106 #endif // CONTENT_PUBLIC_TEST_TEST_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |