Chromium Code Reviews| Index: content/public/test/navigation_simulator.h |
| diff --git a/content/public/test/navigation_simulator.h b/content/public/test/navigation_simulator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0803e13f3defee894ad118ce87fe094b30735e92 |
| --- /dev/null |
| +++ b/content/public/test/navigation_simulator.h |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ |
| +#define CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ |
| + |
| +#include <memory> |
| + |
| +#include "ui/base/page_transition_types.h" |
| + |
| +class GURL; |
| + |
| +namespace content { |
| + |
| +class RenderFrameHost; |
| +struct Referrer; |
| + |
| +// An interface for simulating a navigation. Currently this only supports |
| +// renderer-initiated navigations. |
|
ncarter (slow)
2017/02/16 23:36:31
Should this comment, or the comment before CreateR
clamy
2017/02/17 17:34:52
Done.
|
| +// TODO(clamy): support browser-initiated navigations. |
| +class NavigationSimulator { |
| + public: |
| + // Creates a NavigationSimulator that will be used to simulate a |
| + // renderer-initiated navigation to |original_url| received by |
|
nasko
2017/02/16 18:47:59
It isn't immediately clear to me what "received by
clamy
2017/02/17 17:34:52
It's a renderer-initiated navigation, so it's the
|
| + // |render_frame_host|. |
| + static std::unique_ptr<NavigationSimulator> CreateRendererInitiated( |
|
ncarter (slow)
2017/02/16 23:36:31
If we want a shorter name for this, it could be Fr
clamy
2017/02/17 17:34:52
I'm not sure it's clearer in that case, but I've u
|
| + const GURL& original_url, |
| + RenderFrameHost* render_frame_host); |
| + |
|
nasko
2017/02/16 18:47:59
Side node: It will be great to later on have stati
ncarter (slow)
2017/02/16 23:36:31
An alternative to consider would be to support cha
clamy
2017/02/17 17:34:52
I have updated the CL so that methods call any ear
|
| + virtual ~NavigationSimulator(); |
| + |
| + // -------------------------------------------------------------------------- |
| + |
| + // The following functions should be used to simulate events happening during |
| + // a navigation. |
| + // |
| + // Example of usage for a successful renderer-initiated navigation: |
| + // unique_ptr<NavigationSimulator> simulator = |
| + // NavigationSimulator::CreateRendererInitiated( |
| + // original_url, render_frame_host); |
| + // simulator.Start(); |
|
ncarter (slow)
2017/02/16 23:36:32
These would be ->'s, not .'s, right?
clamy
2017/02/17 17:34:52
Done.
|
| + // for (GURL redirect_url : redirects) |
| + // simulator.Redirect(redirect_url); |
| + // simulator.Commit(); |
| + // |
| + // Example of usage for a failed renderer-initiated navigation: |
| + // unique_ptr<NavigationSimulator> simulator = |
| + // NavigationSimulator::CreateRendererInitiated( |
| + // original_url, render_frame_host); |
| + // simulator.Start(); |
| + // for (GURL redirect_url : redirects) |
| + // simulator.Redirect(redirect_url); |
| + // simulator.Fail(net_error); |
|
ncarter (slow)
2017/02/16 23:36:31
It's not clear what the identifier |net_error| ind
clamy
2017/02/17 17:34:52
Done.
|
| + // simulator.CommitErrorPage(); |
| + // |
| + // Example of usage for a same-page renderer-initiated navigation: |
| + // unique_ptr<NavigationSimulator> simulator = |
| + // NavigationSimulator::CreateRendererInitiated( |
| + // original_url, render_frame_host); |
| + // simulator.CommitSamePage(); |
| + |
| + // Simulates the start of the navigation. |
| + virtual void Start() {} |
|
ncarter (slow)
2017/02/16 23:36:32
I'm curious what makes requiring Start() to be an
clamy
2017/02/17 17:34:52
The goal is for people to create the NavigationSim
|
| + |
| + // Simulates a redirect to |new_url| for the navigation. |
| + virtual void Redirect(const GURL& new_url) {} |
| + |
| + // Simulates the commit of the navigation in the RenderFrameHost. |
| + virtual void Commit() {} |
| + |
| + // Simulates the navigation failing with the error code |error_code|. |
| + virtual void Fail(int error_code) {} |
| + |
| + // Simulates the commit of an error page following a navigation failure. |
| + virtual void CommitErrorPage() {} |
| + |
| + // Simulates the commit of a same-page navigation. |
|
nasko
2017/02/16 18:47:59
It will be nice to list what navigations are same-
clamy
2017/02/17 17:34:52
Done.
|
| + virtual void CommitSamePage() {} |
| + |
| + // -------------------------------------------------------------------------- |
| + |
| + // The following functions are used to specify the parameters of the |
| + // navigation. Changes should be made before calling |Start|, unless they are |
| + // meant to apply to a redirect. In that case, they should be made before |
| + // calling |Redirect|. |
| + |
| + // The following parameters are constant during the navigation and may only be |
| + // specified before calling |Start|. |
| + virtual void SetTransition(ui::PageTransition transition) {} |
| + |
| + // The following parameters can change during redirects. They should be |
| + // specified before calling |Start| if they need to apply to the navigation to |
| + // the original url. Otherwise, they should be specified before calling |
| + // |Redirect|. |
| + virtual void SetReferrer(const Referrer& referrer) {} |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_PUBLIC_TEST_NAVIGATION_SIMULATOR_H_ |