OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ |
| 6 #define CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "ui/base/page_transition_types.h" |
| 11 |
| 12 class GURL; |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class RenderFrameHost; |
| 17 struct Referrer; |
| 18 |
| 19 // An interface for simulating a navigation in unit tests. Currently this only |
| 20 // supports renderer-initiated navigations. |
| 21 // Note: this should not be used in browser tests. |
| 22 // TODO(clamy): support browser-initiated navigations. |
| 23 class NavigationSimulator { |
| 24 public: |
| 25 // Simulates a renderer-initiated navigation to |url| started in |
| 26 // |render_frame_host| from start to commit. |
| 27 static void NavigateAndCommitFromDocument(const GURL& original_url, |
| 28 RenderFrameHost* render_frame_host); |
| 29 |
| 30 // Simulates a failed renderer-initiated navigation to |url| started in |
| 31 // |render_frame_host| from start to commit. |
| 32 static void NavigateAndFailFromDocument(const GURL& original_url, |
| 33 int net_error_code, |
| 34 RenderFrameHost* render_frame_host); |
| 35 |
| 36 // --------------------------------------------------------------------------- |
| 37 |
| 38 // All the following methods should be used when more precise control over the |
| 39 // navigation is needed. |
| 40 |
| 41 // Creates a NavigationSimulator that will be used to simulate a |
| 42 // renderer-initiated navigation to |original_url| started by |
| 43 // |render_frame_host|. |
| 44 static std::unique_ptr<NavigationSimulator> CreateRendererInitiated( |
| 45 const GURL& original_url, |
| 46 RenderFrameHost* render_frame_host); |
| 47 |
| 48 virtual ~NavigationSimulator(); |
| 49 |
| 50 // -------------------------------------------------------------------------- |
| 51 |
| 52 // The following functions should be used to simulate events happening during |
| 53 // a navigation. |
| 54 // |
| 55 // Example of usage for a successful renderer-initiated navigation: |
| 56 // unique_ptr<NavigationSimulator> simulator = |
| 57 // NavigationSimulator::CreateRendererInitiated( |
| 58 // original_url, render_frame_host); |
| 59 // simulator->SetTransition(ui::PAGE_TRANSITION_LINK); |
| 60 // simulator->Start(); |
| 61 // for (GURL redirect_url : redirects) |
| 62 // simulator->Redirect(redirect_url); |
| 63 // simulator->Commit(); |
| 64 // |
| 65 // Example of usage for a failed renderer-initiated navigation: |
| 66 // unique_ptr<NavigationSimulator> simulator = |
| 67 // NavigationSimulator::CreateRendererInitiated( |
| 68 // original_url, render_frame_host); |
| 69 // simulator->SetTransition(ui::PAGE_TRANSITION_LINK); |
| 70 // simulator->Start(); |
| 71 // for (GURL redirect_url : redirects) |
| 72 // simulator->Redirect(redirect_url); |
| 73 // simulator->Fail(net::ERR_TIMED_OUT); |
| 74 // simulator->CommitErrorPage(); |
| 75 // |
| 76 // Example of usage for a same-page renderer-initiated navigation: |
| 77 // unique_ptr<NavigationSimulator> simulator = |
| 78 // NavigationSimulator::CreateRendererInitiated( |
| 79 // original_url, render_frame_host); |
| 80 // simulator->CommitSamePage(); |
| 81 |
| 82 // Simulates the start of the navigation. |
| 83 virtual void Start() {} |
| 84 |
| 85 // Simulates a redirect to |new_url| for the navigation. |
| 86 virtual void Redirect(const GURL& new_url) {} |
| 87 |
| 88 // Simulates the commit of the navigation in the RenderFrameHost. |
| 89 virtual void Commit() {} |
| 90 |
| 91 // Simulates the navigation failing with the error code |error_code|. |
| 92 virtual void Fail(int error_code) {} |
| 93 |
| 94 // Simulates the commit of an error page following a navigation failure. |
| 95 virtual void CommitErrorPage() {} |
| 96 |
| 97 // Simulates the commit of a same-page navigation, ie fragment navigations or |
| 98 // pushState/popState navigations. |
| 99 virtual void CommitSamePage() {} |
| 100 |
| 101 // -------------------------------------------------------------------------- |
| 102 |
| 103 // The following functions are used to specify the parameters of the |
| 104 // navigation. Changes should be made before calling |Start|, unless they are |
| 105 // meant to apply to a redirect. In that case, they should be made before |
| 106 // calling |Redirect|. |
| 107 |
| 108 // The following parameters are constant during the navigation and may only be |
| 109 // specified before calling |Start|. |
| 110 virtual void SetTransition(ui::PageTransition transition) {} |
| 111 |
| 112 // The following parameters can change during redirects. They should be |
| 113 // specified before calling |Start| if they need to apply to the navigation to |
| 114 // the original url. Otherwise, they should be specified before calling |
| 115 // |Redirect|. |
| 116 virtual void SetReferrer(const Referrer& referrer) {} |
| 117 }; |
| 118 |
| 119 } // namespace content |
| 120 |
| 121 #endif // CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ |
OLD | NEW |