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

Side by Side Diff: ios/chrome/browser/web/cache_egtest.mm

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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" 7 #import "base/mac/scoped_nsobject.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h" 10 #include "components/content_settings/core/browser/host_content_settings_map.h"
11 #include "components/content_settings/core/common/content_settings.h" 11 #include "components/content_settings/core/common/content_settings.h"
12 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h" 12 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h"
13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
15 #import "ios/chrome/test/app/chrome_test_util.h" 15 #import "ios/chrome/test/app/chrome_test_util.h"
16 #include "ios/chrome/test/app/history_test_util.h" 16 #include "ios/chrome/test/app/history_test_util.h"
17 #include "ios/chrome/test/app/navigation_test_util.h" 17 #include "ios/chrome/test/app/navigation_test_util.h"
18 #include "ios/chrome/test/app/web_view_interaction_test_util.h" 18 #include "ios/chrome/test/app/web_view_interaction_test_util.h"
19 #import "ios/chrome/test/earl_grey/chrome_assertions.h" 19 #import "ios/chrome/test/earl_grey/chrome_assertions.h"
20 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 20 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
21 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 21 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
22 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 22 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
23 #import "ios/testing/wait_util.h" 23 #import "ios/testing/wait_util.h"
24 #import "ios/web/public/test/http_server.h" 24 #import "ios/web/public/test/http_server.h"
25 #include "ios/web/public/test/http_server_util.h" 25 #include "ios/web/public/test/http_server_util.h"
26 #include "ios/web/public/test/response_providers/html_response_provider.h" 26 #include "ios/web/public/test/response_providers/html_response_provider.h"
27 #include "url/gurl.h" 27 #include "url/gurl.h"
28 28
29 using chrome_test_util::WebViewContainingText;
30 using web::test::HttpServer; 29 using web::test::HttpServer;
31 30
32 namespace { 31 namespace {
33 32
34 // First page for cache testing. 33 // First page for cache testing.
35 const char kCacheTestFirstPageURL[] = "http://cacheTestFirstPage"; 34 const char kCacheTestFirstPageURL[] = "http://cacheTestFirstPage";
36 35
37 // Second page for cache testing. 36 // Second page for cache testing.
38 const char kCacheTestSecondPageURL[] = "http://cacheTestSecondPage"; 37 const char kCacheTestSecondPageURL[] = "http://cacheTestSecondPage";
39 38
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // use the cached page. Page reload should use cache-control in the request 177 // use the cached page. Page reload should use cache-control in the request
179 // header and show updated page. 178 // header and show updated page.
180 - (void)testCachingBehaviorOnNavigateBackAndPageReload { 179 - (void)testCachingBehaviorOnNavigateBackAndPageReload {
181 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); 180 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>());
182 181
183 const GURL cacheTestFirstPageURL = 182 const GURL cacheTestFirstPageURL =
184 HttpServer::MakeUrl(kCacheTestFirstPageURL); 183 HttpServer::MakeUrl(kCacheTestFirstPageURL);
185 184
186 // 1st hit to server. Verify that the server has the correct hit count. 185 // 1st hit to server. Verify that the server has the correct hit count.
187 [ChromeEarlGrey loadURL:cacheTestFirstPageURL]; 186 [ChromeEarlGrey loadURL:cacheTestFirstPageURL];
188 [[EarlGrey 187 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 1"];
189 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
190 assertWithMatcher:grey_notNil()];
191 188
192 // Navigate to another page. 2nd hit to server. 189 // Navigate to another page. 2nd hit to server.
193 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID); 190 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID);
194 [[EarlGrey 191 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 2"];
195 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")]
196 assertWithMatcher:grey_notNil()];
197 192
198 // Navigate back. This should not hit the server. Verify the page has been 193 // Navigate back. This should not hit the server. Verify the page has been
199 // loaded from cache. The serverHitCounter will remain the same. 194 // loaded from cache. The serverHitCounter will remain the same.
200 [self goBack]; 195 [self goBack];
201 [[EarlGrey 196 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 1"];
202 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
203 assertWithMatcher:grey_notNil()];
204 197
205 // Reload page. 3rd hit to server. Verify that page reload causes the 198 // Reload page. 3rd hit to server. Verify that page reload causes the
206 // hitCounter to show updated value. 199 // hitCounter to show updated value.
207 [self reloadPage]; 200 [self reloadPage];
208 [[EarlGrey 201 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 3"];
209 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 3")]
210 assertWithMatcher:grey_notNil()];
211 202
212 // Verify that page reload causes Cache-Control value to be sent with request. 203 // Verify that page reload causes Cache-Control value to be sent with request.
213 [[EarlGrey 204 [ChromeEarlGrey waitForWebViewContainingText:@"cacheControl: max-age=0"];
214 selectElementWithMatcher:WebViewContainingText("cacheControl: max-age=0")]
215 assertWithMatcher:grey_notNil()];
216 } 205 }
217 206
218 // Tests caching behavior when opening new tab. New tab should not use the 207 // Tests caching behavior when opening new tab. New tab should not use the
219 // cached page. 208 // cached page.
220 - (void)testCachingBehaviorOnOpenNewTab { 209 - (void)testCachingBehaviorOnOpenNewTab {
221 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); 210 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>());
222 211
223 const GURL cacheTestFirstPageURL = 212 const GURL cacheTestFirstPageURL =
224 HttpServer::MakeUrl(kCacheTestFirstPageURL); 213 HttpServer::MakeUrl(kCacheTestFirstPageURL);
225 const GURL cacheTestThirdPageURL = 214 const GURL cacheTestThirdPageURL =
226 HttpServer::MakeUrl(kCacheTestThirdPageURL); 215 HttpServer::MakeUrl(kCacheTestThirdPageURL);
227 216
228 // 1st hit to server. Verify title and hitCount. 217 // 1st hit to server. Verify title and hitCount.
229 [ChromeEarlGrey loadURL:cacheTestFirstPageURL]; 218 [ChromeEarlGrey loadURL:cacheTestFirstPageURL];
230 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 219 [ChromeEarlGrey waitForWebViewContainingText:@"First Page"];
231 assertWithMatcher:grey_notNil()]; 220 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 1"];
232 [[EarlGrey
233 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
234 assertWithMatcher:grey_notNil()];
235 221
236 // 2nd hit to server. Verify hitCount. 222 // 2nd hit to server. Verify hitCount.
237 [ChromeEarlGrey loadURL:cacheTestThirdPageURL]; 223 [ChromeEarlGrey loadURL:cacheTestThirdPageURL];
238 [[EarlGrey 224 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 2"];
239 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")]
240 assertWithMatcher:grey_notNil()];
241 225
242 // Open the first page in a new tab. Verify that cache was not used. Must 226 // Open the first page in a new tab. Verify that cache was not used. Must
243 // first allow popups. 227 // first allow popups.
244 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW); 228 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
245 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID); 229 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID);
246 chrome_test_util::AssertMainTabCount(2); 230 chrome_test_util::AssertMainTabCount(2);
247 [ChromeEarlGrey waitForPageToFinishLoading]; 231 [ChromeEarlGrey waitForPageToFinishLoading];
248 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 232 [ChromeEarlGrey waitForWebViewContainingText:@"First Page"];
249 assertWithMatcher:grey_notNil()]; 233 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 3"];
250 [[EarlGrey
251 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 3")]
252 assertWithMatcher:grey_notNil()];
253 } 234 }
254 235
255 // Tests that cache is not used when selecting omnibox suggested website, even 236 // Tests that cache is not used when selecting omnibox suggested website, even
256 // though cache for that website exists. 237 // though cache for that website exists.
257 - (void)testCachingBehaviorOnSelectOmniboxSuggestion { 238 - (void)testCachingBehaviorOnSelectOmniboxSuggestion {
258 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); 239 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>());
259 240
260 // Clear the history to ensure expected omnibox autocomplete results. 241 // Clear the history to ensure expected omnibox autocomplete results.
261 chrome_test_util::ClearBrowsingHistory(); 242 chrome_test_util::ClearBrowsingHistory();
262 243
263 const GURL cacheTestFirstPageURL = 244 const GURL cacheTestFirstPageURL =
264 HttpServer::MakeUrl(kCacheTestFirstPageURL); 245 HttpServer::MakeUrl(kCacheTestFirstPageURL);
265 246
266 // 1st hit to server. Verify title and hitCount. 247 // 1st hit to server. Verify title and hitCount.
267 [ChromeEarlGrey loadURL:cacheTestFirstPageURL]; 248 [ChromeEarlGrey loadURL:cacheTestFirstPageURL];
268 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 249 [ChromeEarlGrey waitForWebViewContainingText:@"First Page"];
269 assertWithMatcher:grey_notNil()]; 250 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 1"];
270 [[EarlGrey
271 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
272 assertWithMatcher:grey_notNil()];
273 251
274 // Type a search into omnnibox and select the first suggestion (second row) 252 // Type a search into omnnibox and select the first suggestion (second row)
275 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 253 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
276 performAction:grey_typeText(@"cachetestfirstpage")]; 254 performAction:grey_typeText(@"cachetestfirstpage")];
277 [[EarlGrey 255 [[EarlGrey
278 selectElementWithMatcher:grey_accessibilityID(@"omnibox suggestion 1")] 256 selectElementWithMatcher:grey_accessibilityID(@"omnibox suggestion 1")]
279 performAction:grey_tap()]; 257 performAction:grey_tap()];
280 258
281 // Verify title and hitCount. Cache should not be used. 259 // Verify title and hitCount. Cache should not be used.
282 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 260 [ChromeEarlGrey waitForWebViewContainingText:@"First Page"];
283 assertWithMatcher:grey_notNil()]; 261 [ChromeEarlGrey waitForWebViewContainingText:@"serverHitCounter: 2"];
284 [[EarlGrey
285 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")]
286 assertWithMatcher:grey_notNil()];
287 } 262 }
288 263
289 @end 264 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698