| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" |
| 7 #import "ios/web/public/test/http_server.h" | 8 #import "ios/web/public/test/http_server.h" |
| 8 #include "ios/web/public/test/http_server_util.h" | 9 #include "ios/web/public/test/http_server_util.h" |
| 9 #import "ios/web/public/test/response_providers/html_response_provider.h" | 10 #import "ios/web/public/test/response_providers/html_response_provider.h" |
| 10 #import "ios/web/public/test/response_providers/html_response_provider_impl.h" | 11 #import "ios/web/public/test/response_providers/html_response_provider_impl.h" |
| 11 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" | 12 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
| 12 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 13 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| 13 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" | 14 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" |
| 14 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 15 | 16 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 using web::AddressFieldText; | 21 using web::AddressFieldText; |
| 21 using web::test::HttpServer; | 22 using web::test::HttpServer; |
| 22 using web::WebViewContainingText; | |
| 23 | 23 |
| 24 // Redirect test cases for the web shell. | 24 // Redirect test cases for the web shell. |
| 25 @interface RedirectTestCase : WebShellTestCase | 25 @interface RedirectTestCase : WebShellTestCase |
| 26 @end | 26 @end |
| 27 | 27 |
| 28 @implementation RedirectTestCase | 28 @implementation RedirectTestCase |
| 29 | 29 |
| 30 // Tests loading of page that is redirected 3 times using a 301 redirect. | 30 // Tests loading of page that is redirected 3 times using a 301 redirect. |
| 31 - (void)testMultipleRedirects { | 31 - (void)testMultipleRedirects { |
| 32 // Create map of canned responses and set up the test HTML server. | 32 // Create map of canned responses and set up the test HTML server. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 responses[destinationURL] = | 46 responses[destinationURL] = |
| 47 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); | 47 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); |
| 48 std::unique_ptr<web::DataResponseProvider> provider( | 48 std::unique_ptr<web::DataResponseProvider> provider( |
| 49 new HtmlResponseProvider(responses)); | 49 new HtmlResponseProvider(responses)); |
| 50 web::test::SetUpHttpServer(std::move(provider)); | 50 web::test::SetUpHttpServer(std::move(provider)); |
| 51 | 51 |
| 52 // Load first URL and expect destination URL to load. | 52 // Load first URL and expect destination URL to load. |
| 53 [ShellEarlGrey loadURL:firstRedirectURL]; | 53 [ShellEarlGrey loadURL:firstRedirectURL]; |
| 54 [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())] | 54 [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())] |
| 55 assertWithMatcher:grey_notNil()]; | 55 assertWithMatcher:grey_notNil()]; |
| 56 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFinalPageContent)] | 56 [ShellEarlGrey |
| 57 assertWithMatcher:grey_notNil()]; | 57 waitForWebViewContainingText:base::SysUTF8ToNSString(kFinalPageContent)]; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Tests simple 301 redirection. | 60 // Tests simple 301 redirection. |
| 61 - (void)testRedirection301 { | 61 - (void)testRedirection301 { |
| 62 // Create map of canned responses and set up the test HTML server. | 62 // Create map of canned responses and set up the test HTML server. |
| 63 std::map<GURL, HtmlResponseProviderImpl::Response> responses; | 63 std::map<GURL, HtmlResponseProviderImpl::Response> responses; |
| 64 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); | 64 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); |
| 65 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); | 65 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); |
| 66 | 66 |
| 67 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | 67 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( |
| 68 destinationURL, net::HTTP_MOVED_PERMANENTLY); | 68 destinationURL, net::HTTP_MOVED_PERMANENTLY); |
| 69 const char kFinalPageContent[] = "testRedirection301 complete"; | 69 const char kFinalPageContent[] = "testRedirection301 complete"; |
| 70 responses[destinationURL] = | 70 responses[destinationURL] = |
| 71 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); | 71 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); |
| 72 std::unique_ptr<web::DataResponseProvider> provider( | 72 std::unique_ptr<web::DataResponseProvider> provider( |
| 73 new HtmlResponseProvider(responses)); | 73 new HtmlResponseProvider(responses)); |
| 74 web::test::SetUpHttpServer(std::move(provider)); | 74 web::test::SetUpHttpServer(std::move(provider)); |
| 75 | 75 |
| 76 // Load first URL and expect destination URL to load. | 76 // Load first URL and expect destination URL to load. |
| 77 [ShellEarlGrey loadURL:firstRedirectURL]; | 77 [ShellEarlGrey loadURL:firstRedirectURL]; |
| 78 [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())] | 78 [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())] |
| 79 assertWithMatcher:grey_notNil()]; | 79 assertWithMatcher:grey_notNil()]; |
| 80 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFinalPageContent)] | 80 [ShellEarlGrey |
| 81 assertWithMatcher:grey_notNil()]; | 81 waitForWebViewContainingText:base::SysUTF8ToNSString(kFinalPageContent)]; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Tests simple 302 redirection. | 84 // Tests simple 302 redirection. |
| 85 - (void)testRedirection302 { | 85 - (void)testRedirection302 { |
| 86 // Create map of canned responses and set up the test HTML server. | 86 // Create map of canned responses and set up the test HTML server. |
| 87 std::map<GURL, HtmlResponseProviderImpl::Response> responses; | 87 std::map<GURL, HtmlResponseProviderImpl::Response> responses; |
| 88 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); | 88 const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/"); |
| 89 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); | 89 const GURL destinationURL = HttpServer::MakeUrl("http://destination/"); |
| 90 | 90 |
| 91 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( | 91 responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse( |
| 92 destinationURL, net::HTTP_FOUND); | 92 destinationURL, net::HTTP_FOUND); |
| 93 const char kFinalPageContent[] = "testRedirection302 complete"; | 93 const char kFinalPageContent[] = "testRedirection302 complete"; |
| 94 responses[destinationURL] = | 94 responses[destinationURL] = |
| 95 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); | 95 HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent); |
| 96 std::unique_ptr<web::DataResponseProvider> provider( | 96 std::unique_ptr<web::DataResponseProvider> provider( |
| 97 new HtmlResponseProvider(responses)); | 97 new HtmlResponseProvider(responses)); |
| 98 web::test::SetUpHttpServer(std::move(provider)); | 98 web::test::SetUpHttpServer(std::move(provider)); |
| 99 | 99 |
| 100 // Load first URL and expect destination URL to load. | 100 // Load first URL and expect destination URL to load. |
| 101 [ShellEarlGrey loadURL:firstRedirectURL]; | 101 [ShellEarlGrey loadURL:firstRedirectURL]; |
| 102 [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())] | 102 [[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())] |
| 103 assertWithMatcher:grey_notNil()]; | 103 assertWithMatcher:grey_notNil()]; |
| 104 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFinalPageContent)] | 104 [ShellEarlGrey |
| 105 assertWithMatcher:grey_notNil()]; | 105 waitForWebViewContainingText:base::SysUTF8ToNSString(kFinalPageContent)]; |
| 106 } | 106 } |
| 107 | 107 |
| 108 @end | 108 @end |
| OLD | NEW |