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

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

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