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

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

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: review comments Created 3 years, 6 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 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "components/content_settings/core/browser/host_content_settings_map.h" 9 #include "components/content_settings/core/browser/host_content_settings_map.h"
10 #include "components/content_settings/core/common/content_settings.h" 10 #include "components/content_settings/core/common/content_settings.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // 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
182 // header and show updated page. 182 // header and show updated page.
183 - (void)testCachingBehaviorOnNavigateBackAndPageReload { 183 - (void)testCachingBehaviorOnNavigateBackAndPageReload {
184 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); 184 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>());
185 185
186 const GURL cacheTestFirstPageURL = 186 const GURL cacheTestFirstPageURL =
187 HttpServer::MakeUrl(kCacheTestFirstPageURL); 187 HttpServer::MakeUrl(kCacheTestFirstPageURL);
188 188
189 // 1st hit to server. Verify that the server has the correct hit count. 189 // 1st hit to server. Verify that the server has the correct hit count.
190 [ChromeEarlGrey loadURL:cacheTestFirstPageURL]; 190 [ChromeEarlGrey loadURL:cacheTestFirstPageURL];
191 [[EarlGrey 191 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 1"];
192 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
193 assertWithMatcher:grey_notNil()];
194 192
195 // Navigate to another page. 2nd hit to server. 193 // Navigate to another page. 2nd hit to server.
196 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID); 194 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID);
197 [[EarlGrey 195 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 2"];
198 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")]
199 assertWithMatcher:grey_notNil()];
200 196
201 // Navigate back. This should not hit the server. Verify the page has been 197 // Navigate back. This should not hit the server. Verify the page has been
202 // loaded from cache. The serverHitCounter will remain the same. 198 // loaded from cache. The serverHitCounter will remain the same.
203 [self goBack]; 199 [self goBack];
204 [[EarlGrey 200 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 1"];
205 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
206 assertWithMatcher:grey_notNil()];
207 201
208 // Reload page. 3rd hit to server. Verify that page reload causes the 202 // Reload page. 3rd hit to server. Verify that page reload causes the
209 // hitCounter to show updated value. 203 // hitCounter to show updated value.
210 [self reloadPage]; 204 [self reloadPage];
211 [[EarlGrey 205 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 3"];
212 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 3")]
213 assertWithMatcher:grey_notNil()];
214 206
215 // Verify that page reload causes Cache-Control value to be sent with request. 207 // Verify that page reload causes Cache-Control value to be sent with request.
216 [[EarlGrey 208 [ChromeEarlGrey waitForWebViewContainingText:"cacheControl: max-age=0"];
217 selectElementWithMatcher:WebViewContainingText("cacheControl: max-age=0")]
218 assertWithMatcher:grey_notNil()];
219 } 209 }
220 210
221 // Tests caching behavior when opening new tab. New tab should not use the 211 // Tests caching behavior when opening new tab. New tab should not use the
222 // cached page. 212 // cached page.
223 - (void)testCachingBehaviorOnOpenNewTab { 213 - (void)testCachingBehaviorOnOpenNewTab {
224 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); 214 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>());
225 215
226 const GURL cacheTestFirstPageURL = 216 const GURL cacheTestFirstPageURL =
227 HttpServer::MakeUrl(kCacheTestFirstPageURL); 217 HttpServer::MakeUrl(kCacheTestFirstPageURL);
228 const GURL cacheTestThirdPageURL = 218 const GURL cacheTestThirdPageURL =
229 HttpServer::MakeUrl(kCacheTestThirdPageURL); 219 HttpServer::MakeUrl(kCacheTestThirdPageURL);
230 220
231 // 1st hit to server. Verify title and hitCount. 221 // 1st hit to server. Verify title and hitCount.
232 [ChromeEarlGrey loadURL:cacheTestFirstPageURL]; 222 [ChromeEarlGrey loadURL:cacheTestFirstPageURL];
233 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 223 [ChromeEarlGrey waitForWebViewContainingText:"First Page"];
234 assertWithMatcher:grey_notNil()]; 224 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 1"];
235 [[EarlGrey
236 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
237 assertWithMatcher:grey_notNil()];
238 225
239 // 2nd hit to server. Verify hitCount. 226 // 2nd hit to server. Verify hitCount.
240 [ChromeEarlGrey loadURL:cacheTestThirdPageURL]; 227 [ChromeEarlGrey loadURL:cacheTestThirdPageURL];
241 [[EarlGrey 228 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 2"];
242 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")]
243 assertWithMatcher:grey_notNil()];
244 229
245 // Open the first page in a new tab. Verify that cache was not used. Must 230 // Open the first page in a new tab. Verify that cache was not used. Must
246 // first allow popups. 231 // first allow popups.
247 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW); 232 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
248 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID); 233 chrome_test_util::TapWebViewElementWithId(kCacheTestLinkID);
249 chrome_test_util::AssertMainTabCount(2); 234 chrome_test_util::AssertMainTabCount(2);
250 [ChromeEarlGrey waitForPageToFinishLoading]; 235 [ChromeEarlGrey waitForPageToFinishLoading];
251 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 236 [ChromeEarlGrey waitForWebViewContainingText:"First Page"];
252 assertWithMatcher:grey_notNil()]; 237 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 3"];
253 [[EarlGrey
254 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 3")]
255 assertWithMatcher:grey_notNil()];
256 } 238 }
257 239
258 // Tests that cache is not used when selecting omnibox suggested website, even 240 // Tests that cache is not used when selecting omnibox suggested website, even
259 // though cache for that website exists. 241 // though cache for that website exists.
260 - (void)testCachingBehaviorOnSelectOmniboxSuggestion { 242 - (void)testCachingBehaviorOnSelectOmniboxSuggestion {
261 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>()); 243 web::test::SetUpHttpServer(base::MakeUnique<CacheTestResponseProvider>());
262 244
263 // Clear the history to ensure expected omnibox autocomplete results. 245 // Clear the history to ensure expected omnibox autocomplete results.
264 chrome_test_util::ClearBrowsingHistory(); 246 chrome_test_util::ClearBrowsingHistory();
265 247
266 const GURL cacheTestFirstPageURL = 248 const GURL cacheTestFirstPageURL =
267 HttpServer::MakeUrl(kCacheTestFirstPageURL); 249 HttpServer::MakeUrl(kCacheTestFirstPageURL);
268 250
269 // 1st hit to server. Verify title and hitCount. 251 // 1st hit to server. Verify title and hitCount.
270 [ChromeEarlGrey loadURL:cacheTestFirstPageURL]; 252 [ChromeEarlGrey loadURL:cacheTestFirstPageURL];
271 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 253 [ChromeEarlGrey waitForWebViewContainingText:"First Page"];
272 assertWithMatcher:grey_notNil()]; 254 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 1"];
273 [[EarlGrey
274 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 1")]
275 assertWithMatcher:grey_notNil()];
276 255
277 // Type a search into omnnibox and select the first suggestion (second row) 256 // Type a search into omnnibox and select the first suggestion (second row)
278 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 257 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
279 performAction:grey_typeText(@"cachetestfirstpage")]; 258 performAction:grey_typeText(@"cachetestfirstpage")];
280 [[EarlGrey 259 [[EarlGrey
281 selectElementWithMatcher:grey_accessibilityID(@"omnibox suggestion 1")] 260 selectElementWithMatcher:grey_accessibilityID(@"omnibox suggestion 1")]
282 performAction:grey_tap()]; 261 performAction:grey_tap()];
283 262
284 // Verify title and hitCount. Cache should not be used. 263 // Verify title and hitCount. Cache should not be used.
285 [[EarlGrey selectElementWithMatcher:WebViewContainingText("First Page")] 264 [ChromeEarlGrey waitForWebViewContainingText:"First Page"];
286 assertWithMatcher:grey_notNil()]; 265 [ChromeEarlGrey waitForWebViewContainingText:"serverHitCounter: 2"];
287 [[EarlGrey
288 selectElementWithMatcher:WebViewContainingText("serverHitCounter: 2")]
289 assertWithMatcher:grey_notNil()];
290 } 266 }
291 267
292 @end 268 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/browsing_prevent_default_egtest.mm ('k') | ios/chrome/browser/web/child_window_open_by_dom_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698