Migrate RedirectTestCase to web_state_observer_inttest.mm.
This CL merges RedirectTestCase into
WebStateObserverTest.RedirectNavigation.
Bug: 930859
Change-Id: I903d9da7799ec15850ff1c241f96bf9a9cf36ebe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1503461
Reviewed-by: Eugene But <eugenebut@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638046}
diff --git a/ios/web/shell/test/BUILD.gn b/ios/web/shell/test/BUILD.gn
index 4cf9c16b..e05de3f 100644
--- a/ios/web/shell/test/BUILD.gn
+++ b/ios/web/shell/test/BUILD.gn
@@ -20,7 +20,6 @@
sources = [
"context_menu_egtest.mm",
"page_state_egtest.mm",
- "redirect_egtest.mm",
"service_manager_egtest.mm",
]
diff --git a/ios/web/shell/test/redirect_egtest.mm b/ios/web/shell/test/redirect_egtest.mm
deleted file mode 100644
index 0c32da3..0000000
--- a/ios/web/shell/test/redirect_egtest.mm
+++ /dev/null
@@ -1,105 +0,0 @@
-// 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.
-
-#import <EarlGrey/EarlGrey.h>
-
-#import "ios/web/public/test/http_server/html_response_provider.h"
-#import "ios/web/public/test/http_server/html_response_provider_impl.h"
-#import "ios/web/public/test/http_server/http_server.h"
-#include "ios/web/public/test/http_server/http_server_util.h"
-#import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
-#import "ios/web/shell/test/earl_grey/shell_matchers.h"
-#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
-#import "ios/web/shell/test/earl_grey/web_shell_test_case.h"
-#include "net/http/http_status_code.h"
-
-#if !defined(__has_feature) || !__has_feature(objc_arc)
-#error "This file requires ARC support."
-#endif
-
-using web::AddressFieldText;
-using web::test::HttpServer;
-
-// Redirect test cases for the web shell.
-@interface RedirectTestCase : WebShellTestCase
-@end
-
-@implementation RedirectTestCase
-
-// Tests loading of page that is redirected 3 times using a 301 redirect.
-- (void)testMultipleRedirects {
- // Create map of canned responses and set up the test HTML server.
- std::map<GURL, HtmlResponseProviderImpl::Response> responses;
- const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/");
- const GURL secondRedirectURL = HttpServer::MakeUrl("http://secondRedirect/");
- const GURL thirdRedirectURL = HttpServer::MakeUrl("http://thirdRedirect/");
- const GURL destinationURL = HttpServer::MakeUrl("http://destination/");
-
- responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse(
- secondRedirectURL, net::HTTP_MOVED_PERMANENTLY);
- responses[secondRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse(
- thirdRedirectURL, net::HTTP_MOVED_PERMANENTLY);
- responses[thirdRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse(
- destinationURL, net::HTTP_MOVED_PERMANENTLY);
- const char kFinalPageContent[] = "testMultipleRedirects complete";
- responses[destinationURL] =
- HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent);
- std::unique_ptr<web::DataResponseProvider> provider(
- new HtmlResponseProvider(responses));
- web::test::SetUpHttpServer(std::move(provider));
-
- // Load first URL and expect destination URL to load.
- [ShellEarlGrey loadURL:firstRedirectURL];
- [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())]
- assertWithMatcher:grey_notNil()];
- [ShellEarlGrey waitForWebViewContainingText:kFinalPageContent];
-}
-
-// Tests simple 301 redirection.
-- (void)testRedirection301 {
- // Create map of canned responses and set up the test HTML server.
- std::map<GURL, HtmlResponseProviderImpl::Response> responses;
- const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/");
- const GURL destinationURL = HttpServer::MakeUrl("http://destination/");
-
- responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse(
- destinationURL, net::HTTP_MOVED_PERMANENTLY);
- const char kFinalPageContent[] = "testRedirection301 complete";
- responses[destinationURL] =
- HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent);
- std::unique_ptr<web::DataResponseProvider> provider(
- new HtmlResponseProvider(responses));
- web::test::SetUpHttpServer(std::move(provider));
-
- // Load first URL and expect destination URL to load.
- [ShellEarlGrey loadURL:firstRedirectURL];
- [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())]
- assertWithMatcher:grey_notNil()];
- [ShellEarlGrey waitForWebViewContainingText:kFinalPageContent];
-}
-
-// Tests simple 302 redirection.
-- (void)testRedirection302 {
- // Create map of canned responses and set up the test HTML server.
- std::map<GURL, HtmlResponseProviderImpl::Response> responses;
- const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/");
- const GURL destinationURL = HttpServer::MakeUrl("http://destination/");
-
- responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse(
- destinationURL, net::HTTP_FOUND);
- const char kFinalPageContent[] = "testRedirection302 complete";
- responses[destinationURL] =
- HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent);
- std::unique_ptr<web::DataResponseProvider> provider(
- new HtmlResponseProvider(responses));
- web::test::SetUpHttpServer(std::move(provider));
-
- // Load first URL and expect destination URL to load.
- [ShellEarlGrey loadURL:firstRedirectURL];
- [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())]
- assertWithMatcher:grey_notNil()];
- [ShellEarlGrey waitForWebViewContainingText:kFinalPageContent];
-}
-
-@end
diff --git a/ios/web/web_state/web_state_observer_inttest.mm b/ios/web/web_state/web_state_observer_inttest.mm
index 349d5b40..434fc67 100644
--- a/ios/web/web_state/web_state_observer_inttest.mm
+++ b/ios/web/web_state/web_state_observer_inttest.mm
@@ -1895,7 +1895,12 @@
// Tests server redirect navigation.
TEST_P(WebStateObserverTest, RedirectNavigation) {
- const GURL url = test_server_->GetURL("/server-redirect?echoall");
+ const GURL url = test_server_->GetURL("/server-redirect-301?"
+ "server-redirect-302?"
+ "server-redirect-303?"
+ "server-redirect-307?"
+ "server-redirect-308?"
+ "echoall");
const GURL redirect_url = test_server_->GetURL("/echoall");
// Load url which replies with redirect.
@@ -1912,14 +1917,17 @@
.WillOnce(VerifyPageStartedContext(
web_state(), url, ui::PageTransition::PAGE_TRANSITION_TYPED, &context,
&nav_id));
- // Second ShouldAllowRequest call is for redirect_url.
+
+ // 5 calls on ShouldAllowRequest for redirections.
WebStatePolicyDecider::RequestInfo expected_redirect_request_info(
ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT,
/*target_main_frame=*/true, /*has_user_gesture=*/false);
EXPECT_CALL(
*decider_,
ShouldAllowRequest(_, RequestInfoMatch(expected_redirect_request_info)))
- .WillOnce(Return(true));
+ .Times(5)
+ .WillRepeatedly(Return(true));
+
EXPECT_CALL(*decider_, ShouldAllowResponse(_, /*for_main_frame=*/true))
.WillOnce(Return(true));
EXPECT_CALL(observer_, DidFinishNavigation(web_state(), _))