Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #import <EarlGrey/EarlGrey.h> | |
| 6 | |
| 7 #import "ios/web/public/test/http_server.h" | |
| 8 #include "ios/web/public/test/http_server_util.h" | |
| 9 #include "ios/web/public/test/response_providers/html_response_provider.h" | |
| 10 #include "ios/web/public/test/response_providers/html_response_provider_impl.h" | |
| 11 #include "ios/web/shell/test/app/navigation_test_util.h" | |
| 12 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" | |
| 13 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | |
| 14 #include "net/http/http_status_code.h" | |
| 15 | |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 17 #error "This file requires ARC support." | |
| 18 #endif | |
| 19 | |
| 20 using web::addressFieldText; | |
| 21 using web::test::HttpServer; | |
| 22 using web::webViewContainingText; | |
| 23 | |
| 24 // Redirect test cases for the web shell. | |
| 25 @interface RedirectTest : ShellBaseTestCase | |
| 26 @end | |
| 27 | |
| 28 @implementation RedirectTest | |
| 29 | |
| 30 // Tests loading of page that is redirected 3 times using a 301 redirect. | |
| 31 - (void)testMultipleRedirects { | |
| 32 // Create map of canned responses and set up the test HTML server. | |
| 33 std::map<GURL, HtmlResponseProviderImpl::Response> responses; | |
| 34 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); | |
| 35 const GURL secondRedirectURL = HttpServer::MakeUrl("http://secondRedirect/"); | |
| 36 const GURL thirdRedirectURL = HttpServer::MakeUrl("http://thirdRedirect/"); | |
| 37 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); | |
| 38 | |
| 39 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | |
| 40 secondRedirectURL, net::HTTP_MOVED_PERMANENTLY); | |
| 41 responses[secondRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | |
| 42 thirdRedirectURL, net::HTTP_MOVED_PERMANENTLY); | |
| 43 responses[thirdRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | |
| 44 destinationURL, net::HTTP_MOVED_PERMANENTLY); | |
| 45 const char kFinalPageContent[] = "testMultipleRedirects complete"; | |
| 46 responses[destinationURL] = | |
| 47 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); | |
| 48 std::unique_ptr<web::DataResponseProvider> provider( | |
| 49 new HtmlResponseProvider(responses)); | |
| 50 web::test::SetUpHttpServer(std::move(provider)); | |
| 51 | |
| 52 // Load forst URL and expect destination URL to load. | |
|
baxley
2016/07/28 22:06:37
typo: s/forst/first
Eugene But (OOO till 7-30)
2016/07/28 22:13:35
Done.
| |
| 53 web::shell_test_util::LoadUrl(firstRedirectURL); | |
| 54 [[EarlGrey selectElementWithMatcher:addressFieldText(destinationURL.spec())] | |
| 55 assertWithMatcher:grey_notNil()]; | |
| 56 [[EarlGrey selectElementWithMatcher:webViewContainingText(kFinalPageContent)] | |
| 57 assertWithMatcher:grey_notNil()]; | |
| 58 } | |
| 59 | |
| 60 // Tests simple 301 redirection. | |
| 61 - (void)testRedirection301 { | |
|
baxley
2016/07/28 22:06:37
What is the purpose of this test? Does the previou
Eugene But (OOO till 7-30)
2016/07/28 22:13:35
I think redirect chain is more complex flow and it
| |
| 62 // Create map of canned responses and set up the test HTML server. | |
| 63 std::map<GURL, HtmlResponseProviderImpl::Response> responses; | |
| 64 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); | |
| 65 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); | |
| 66 | |
| 67 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | |
| 68 destinationURL, net::HTTP_MOVED_PERMANENTLY); | |
| 69 const char kFinalPageContent[] = "testRedirection301 complete"; | |
| 70 responses[destinationURL] = | |
| 71 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); | |
| 72 std::unique_ptr<web::DataResponseProvider> provider( | |
| 73 new HtmlResponseProvider(responses)); | |
| 74 web::test::SetUpHttpServer(std::move(provider)); | |
| 75 | |
| 76 // Load forst URL and expect destination URL to load. | |
|
baxley
2016/07/28 22:06:37
typo: first
Eugene But (OOO till 7-30)
2016/07/28 22:13:35
Done.
| |
| 77 web::shell_test_util::LoadUrl(firstRedirectURL); | |
| 78 [[EarlGrey selectElementWithMatcher:addressFieldText(destinationURL.spec())] | |
| 79 assertWithMatcher:grey_notNil()]; | |
| 80 [[EarlGrey selectElementWithMatcher:webViewContainingText(kFinalPageContent)] | |
| 81 assertWithMatcher:grey_notNil()]; | |
| 82 } | |
| 83 | |
| 84 // Tests simple 302 redirection. | |
| 85 - (void)testRedirection302 { | |
| 86 // Create map of canned responses and set up the test HTML server. | |
| 87 std::map<GURL, HtmlResponseProviderImpl::Response> responses; | |
| 88 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); | |
| 89 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); | |
| 90 | |
| 91 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | |
| 92 destinationURL, net::HTTP_FOUND); | |
| 93 const char kFinalPageContent[] = "testRedirection301 complete"; | |
|
baxley
2016/07/28 22:06:37
s/301/302 ?
Eugene But (OOO till 7-30)
2016/07/28 22:13:35
Done.
| |
| 94 responses[destinationURL] = | |
| 95 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); | |
| 96 std::unique_ptr<web::DataResponseProvider> provider( | |
| 97 new HtmlResponseProvider(responses)); | |
| 98 web::test::SetUpHttpServer(std::move(provider)); | |
| 99 | |
| 100 // Load forst URL and expect destination URL to load. | |
|
baxley
2016/07/28 22:06:37
first! :)
Eugene But (OOO till 7-30)
2016/07/28 22:13:35
Done.
| |
| 101 web::shell_test_util::LoadUrl(firstRedirectURL); | |
| 102 [[EarlGrey selectElementWithMatcher:addressFieldText(destinationURL.spec())] | |
| 103 assertWithMatcher:grey_notNil()]; | |
| 104 [[EarlGrey selectElementWithMatcher:webViewContainingText(kFinalPageContent)] | |
| 105 assertWithMatcher:grey_notNil()]; | |
| 106 } | |
| 107 | |
| 108 @end | |
| OLD | NEW |