Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1636)

Unified Diff: content/test/navigation_simulator_impl.h

Issue 2682313002: Introduce NavigationSimulator to use in unit tests (Closed)
Patch Set: Added same-page navigation simulation Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/test/navigation_simulator_impl.h
diff --git a/content/test/navigation_simulator_impl.h b/content/test/navigation_simulator_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..062360fd73bbce1e8d140d13a8e591f5e280e5f1
--- /dev/null
+++ b/content/test/navigation_simulator_impl.h
@@ -0,0 +1,83 @@
+// 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_TEST_NAVIGATION_SIMULATOR_IMPL_H_
+#define CONTENT_TEST_NAVIGATION_SIMULATOR_IMPL_H_
+
+#include <vector>
+
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/referrer.h"
+#include "content/public/test/navigation_simulator.h"
+#include "ui/base/page_transition_types.h"
+
+namespace content {
+
+class NavigationHandleImpl;
+class TestRenderFrameHost;
+
+// See NavigationSimulator for a description of what this class does.
+class NavigationSimulatorImpl : public NavigationSimulator,
+ WebContentsObserver {
+ public:
+ NavigationSimulatorImpl(const GURL& original_url,
+ TestRenderFrameHost* render_frame_host);
+ ~NavigationSimulatorImpl() override;
+
+ // NavigationSimulator:
+ void Start() override;
+ void Redirect(const GURL& new_url) override;
+ void Commit() override;
+ void Fail(int error_code) override;
+ void CommitErrorPage() override;
+ void CommitSamePage() override;
+ void SetTransition(ui::PageTransition transition) override;
+ void SetReferrer(const Referrer& referrer) override;
+
+ // WebContentsObservor:
nasko 2017/02/16 18:47:59 Observer, not Observor.
clamy 2017/02/17 17:34:52 Done.
+ void DidStartNavigation(NavigationHandle* navigation_handle) override;
+ void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
+ void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
+ void DidFinishNavigation(NavigationHandle* navigation_handle) override;
+
+ private:
+ void OnWillStartRequest();
+ void OnWillRedirectRequest();
+ void OnWillProcessResponse();
+
+ enum State {
+ INITIALIZATION,
+ STARTED,
+ FAILED,
+ FINISHED,
+ };
+
+ State state_;
+
+ // The renderer associated to this navigation.
nasko 2017/02/16 18:47:59 nit: "associated with"
clamy 2017/02/17 17:34:52 Done.
+ TestRenderFrameHost* render_frame_host_;
+
+ // The NavigationHandle associated to this navigation.
+ NavigationHandleImpl* handle_;
+
+ GURL navigation_url_;
+ Referrer referrer_;
+ ui::PageTransition transition_;
+
+ // These are used to sanity check the content/public/ API calls emitted as
+ // part of the navigation.
+ int num_did_start_navigation_called_;
+ int num_will_start_request_called_;
+ int num_will_redirect_request_called_;
+ int num_did_redirect_navigation_called_;
+ int num_will_process_response_called_;
+ int num_ready_to_commit_called_;
+ int num_did_finish_navigation_called_;
+
+ base::WeakPtrFactory<NavigationSimulatorImpl> weak_factory_;
+};
+
+} // namespace content
+
+#endif // CONTENT_TEST_NAVIGATION_SIMULATOR_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698