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

Unified Diff: ios/web/public/test/test_redirect_observer.h

Issue 2048123002: Created TestRedirectObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@const_navigation_manager_getter
Patch Set: Added comments Created 4 years, 6 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
« no previous file with comments | « ios/web/ios_web.gyp ('k') | ios/web/public/test/test_redirect_observer.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/public/test/test_redirect_observer.h
diff --git a/ios/web/public/test/test_redirect_observer.h b/ios/web/public/test/test_redirect_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..6e112fa11a2887d04b15c7dc4a6c21f8c78a5b15
--- /dev/null
+++ b/ios/web/public/test/test_redirect_observer.h
@@ -0,0 +1,61 @@
+// Copyright 2016 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 IOS_WEB_PUBLIC_TEST_TEST_REDIRECT_OBSERVER_H_
+#define IOS_WEB_PUBLIC_TEST_TEST_REDIRECT_OBSERVER_H_
+
+#include <map>
+#include <set>
+
+#include "ios/web/public/web_state/web_state_observer.h"
+#include "url/gurl.h"
+
+namespace web {
+
+class NavigationItem;
+
+// A utility class that is used to track redirects during tests to enable URL
+// verification for redirected page loads.
+class TestRedirectObserver : public web::WebStateObserver {
+ public:
+ // Getter that lazily instantiates a TestRedirectObserver that is stored in
+ // |web_state|'s user data.
+ static TestRedirectObserver* FromWebState(WebState* web_state);
+
+ // Notifies the observer that |url| is about to be loaded by the associated
+ // WebState, triggering the TestRedirectObserver to start observing redirects.
+ void BeginObservingRedirectsForUrl(const GURL& url);
+
+ // Returns the final url in the redirect chain that began with |url|.
+ GURL GetFinalUrlForUrl(const GURL& url);
+
+ private:
+ // TestRedirectObservers must be instantiated using |FromWebState()|.
+ friend class TestRedirectObserverUserDataWrapper;
+ TestRedirectObserver();
+ TestRedirectObserver(WebState* web_state);
+ ~TestRedirectObserver() final;
+
+ // WebStateObserver:
+ void ProvisionalNavigationStarted(const GURL& url) override;
+
+ // RedirectChains store the original and final redirect URLs for a given page
+ // load.
+ typedef struct RedirectChain {
+ GURL original_url;
+ GURL final_url;
+ } RedirectChain;
+
+ // Stores redirect chains with their corresponding NavigationItems.
+ std::map<NavigationItem*, RedirectChain> redirect_chains_;
+ // Stores URLs passed into |BeginObservingRedirectsForUrl()|. Once a
+ // provisional load has begin for a URL contained in this set, the URL will
+ // be removed and the redirect chain originating from that URL will be stored
+ // in |redirect_chains_|.
+ std::set<GURL> expected_urls_;
+};
+
+} // namespace web
+
+#endif // IOS_WEB_PUBLIC_TEST_TEST_REDIRECT_OBSERVER_H_
« no previous file with comments | « ios/web/ios_web.gyp ('k') | ios/web/public/test/test_redirect_observer.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698