| 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 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 10 #include "components/content_settings/core/browser/host_content_settings_map.h" | 9 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 11 #include "components/content_settings/core/common/content_settings.h" | 10 #include "components/content_settings/core/common/content_settings.h" |
| 12 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.
h" | 11 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.
h" |
| 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 12 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 13 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 15 #import "ios/chrome/test/app/chrome_test_util.h" | 14 #import "ios/chrome/test/app/chrome_test_util.h" |
| 16 #include "ios/chrome/test/app/history_test_util.h" | 15 #include "ios/chrome/test/app/history_test_util.h" |
| 17 #include "ios/chrome/test/app/navigation_test_util.h" | 16 #include "ios/chrome/test/app/navigation_test_util.h" |
| 18 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 17 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 19 #import "ios/chrome/test/earl_grey/chrome_assertions.h" | 18 #import "ios/chrome/test/earl_grey/chrome_assertions.h" |
| 20 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 19 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 21 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 20 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 21 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 23 #import "ios/testing/wait_util.h" | 22 #import "ios/testing/wait_util.h" |
| 24 #import "ios/web/public/test/http_server.h" | 23 #import "ios/web/public/test/http_server.h" |
| 25 #include "ios/web/public/test/http_server_util.h" | 24 #include "ios/web/public/test/http_server_util.h" |
| 26 #include "ios/web/public/test/response_providers/html_response_provider.h" | 25 #include "ios/web/public/test/response_providers/html_response_provider.h" |
| 27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 28 | 27 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." |
| 30 #endif |
| 31 |
| 29 using chrome_test_util::WebViewContainingText; | 32 using chrome_test_util::WebViewContainingText; |
| 30 using web::test::HttpServer; | 33 using web::test::HttpServer; |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 | 36 |
| 34 // First page for cache testing. | 37 // First page for cache testing. |
| 35 const char kCacheTestFirstPageURL[] = "http://cacheTestFirstPage"; | 38 const char kCacheTestFirstPageURL[] = "http://cacheTestFirstPage"; |
| 36 | 39 |
| 37 // Second page for cache testing. | 40 // Second page for cache testing. |
| 38 const char kCacheTestSecondPageURL[] = "http://cacheTestSecondPage"; | 41 const char kCacheTestSecondPageURL[] = "http://cacheTestSecondPage"; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 153 |
| 151 // Tests the browser cache behavior when navigating to cached pages. | 154 // Tests the browser cache behavior when navigating to cached pages. |
| 152 @interface CacheTestCase : ChromeTestCase | 155 @interface CacheTestCase : ChromeTestCase |
| 153 @end | 156 @end |
| 154 | 157 |
| 155 @implementation CacheTestCase | 158 @implementation CacheTestCase |
| 156 | 159 |
| 157 // Reloads the web view and waits for the loading to complete. | 160 // Reloads the web view and waits for the loading to complete. |
| 158 // TODO(crbug.com/638674): Evaluate if this can move to shared code | 161 // TODO(crbug.com/638674): Evaluate if this can move to shared code |
| 159 - (void)reloadPage { | 162 - (void)reloadPage { |
| 160 base::scoped_nsobject<GenericChromeCommand> reloadCommand( | 163 GenericChromeCommand* reloadCommand = |
| 161 [[GenericChromeCommand alloc] initWithTag:IDC_RELOAD]); | 164 [[GenericChromeCommand alloc] initWithTag:IDC_RELOAD]; |
| 162 chrome_test_util::RunCommandWithActiveViewController(reloadCommand); | 165 chrome_test_util::RunCommandWithActiveViewController(reloadCommand); |
| 163 | 166 |
| 164 [ChromeEarlGrey waitForPageToFinishLoading]; | 167 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 165 } | 168 } |
| 166 | 169 |
| 167 // Navigates back to the previous webpage. | 170 // Navigates back to the previous webpage. |
| 168 // TODO(crbug.com/638674): Evaluate if this can move to shared code. | 171 // TODO(crbug.com/638674): Evaluate if this can move to shared code. |
| 169 - (void)goBack { | 172 - (void)goBack { |
| 170 base::scoped_nsobject<GenericChromeCommand> backCommand( | 173 GenericChromeCommand* backCommand = |
| 171 [[GenericChromeCommand alloc] initWithTag:IDC_BACK]); | 174 [[GenericChromeCommand alloc] initWithTag:IDC_BACK]; |
| 172 chrome_test_util::RunCommandWithActiveViewController(backCommand); | 175 chrome_test_util::RunCommandWithActiveViewController(backCommand); |
| 173 | 176 |
| 174 [ChromeEarlGrey waitForPageToFinishLoading]; | 177 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 175 } | 178 } |
| 176 | 179 |
| 177 // Tests caching behavior on navigate back and page reload. Navigate back should | 180 // Tests caching behavior on navigate back and page reload. Navigate back should |
| 178 // use the cached page. Page reload should use cache-control in the request | 181 // use the cached page. Page reload should use cache-control in the request |
| 179 // header and show updated page. | 182 // header and show updated page. |
| 180 - (void)testCachingBehaviorOnNavigateBackAndPageReload { | 183 - (void)testCachingBehaviorOnNavigateBackAndPageReload { |
| 181 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); | 184 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 283 |
| 281 // Verify title and hitCount. Cache should not be used. | 284 // Verify title and hitCount. Cache should not be used. |
| 282 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] | 285 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] |
| 283 assertWithMatcher:grey_notNil()]; | 286 assertWithMatcher:grey_notNil()]; |
| 284 [[EarlGrey | 287 [[EarlGrey |
| 285 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")] | 288 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")] |
| 286 assertWithMatcher:grey_notNil()]; | 289 assertWithMatcher:grey_notNil()]; |
| 287 } | 290 } |
| 288 | 291 |
| 289 @end | 292 @end |
| OLD | NEW |