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

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

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « ios/chrome/browser/web/stop_loading_egtest.mm ('k') | ios/chrome/browser/web/web_mediator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <EarlGrey/EarlGrey.h>
6
7 #include "base/memory/ptr_util.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "ios/chrome/browser/experimental_flags.h"
11 #include "ios/chrome/browser/ui/ui_util.h"
12 #import "ios/chrome/test/app/chrome_test_util.h"
13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
14 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
15 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
16 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
17 #import "ios/testing/earl_grey/disabled_test_macros.h"
18 #import "ios/web/public/test/http_server.h"
19 #include "ios/web/public/test/http_server_util.h"
20 #include "ios/web/public/test/response_providers/html_response_provider.h"
21 #include "url/gurl.h"
22
23 using chrome_test_util::webViewContainingText;
24 using chrome_test_util::omniboxText;
25
26 namespace {
27
28 const char kTestPage1[] = "Test Page 1";
29 const char kTestPage2[] = "Test Page 2";
30 const char kTestPage3[] = "Test Page 3";
31 const char kGoBackLink[] = "go-back";
32 const char kGoForwardLink[] = "go-forward";
33 const char kGoNegativeDeltaLink[] = "go-negative-delta";
34 const char kGoPositiveDeltaLink[] = "go-positive-delta";
35 const char kPage1Link[] = "page-1";
36 const char kPage2Link[] = "page-2";
37 const char kPage3Link[] = "page-3";
38
39 // Purges all cached web view pages, so the next time back navigation will not
40 // use cached page. Browsers don't have to use fresh version for back forward
41 // navigation for HTTP pages and may serve version from the cache even if
42 // Cache-Control response header says otherwise.
43 void PurgeCachedWebViewPages() {
44 chrome_test_util::ResetAllWebViews();
45
46 BOOL reloaded = [[GREYCondition
47 conditionWithName:@"Wait for reload"
48 block:^{
49 return chrome_test_util::GetCurrentWebState()->IsLoading()
50 ? NO
51 : YES;
52 }] waitWithTimeout:10];
53 GREYAssert(reloaded, @"page did not reload");
54 }
55
56 // Response provider which can be paused. When it is paused it buffers all
57 // requests and does not respond to them until |set_paused(false)| is called.
58 class PausableResponseProvider : public HtmlResponseProvider {
59 public:
60 explicit PausableResponseProvider(
61 const std::map<GURL, std::string>& responses)
62 : HtmlResponseProvider(responses) {}
63
64 void GetResponseHeadersAndBody(
65 const Request& request,
66 scoped_refptr<net::HttpResponseHeaders>* headers,
67 std::string* body) override {
68 set_last_request_url(request.url);
69 while (is_paused()) {
70 }
71 HtmlResponseProvider::GetResponseHeadersAndBody(request, headers, body);
72 }
73 // URL for the last seen request.
74 const GURL& last_request_url() const {
75 base::AutoLock autolock(lock_);
76 return last_request_url_;
77 }
78
79 // If true buffers all incoming requests and will not reply until is_paused is
80 // changed to false.
81 bool is_paused() const {
82 base::AutoLock autolock(lock_);
83 return is_paused_;
84 }
85 void set_paused(bool paused) {
86 base::AutoLock last_request_url_autolock(lock_);
87 is_paused_ = paused;
88 }
89
90 private:
91 void set_last_request_url(const GURL& url) {
92 base::AutoLock last_request_url_autolock(lock_);
93 last_request_url_ = url;
94 }
95
96 mutable base::Lock lock_;
97 GURL last_request_url_;
98 bool is_paused_ = false;
99 };
100
101 } // namespace
102
103 // Test case for back forward and delta navigations focused on making sure that
104 // omnibox visible URL always represents the current page.
105 @interface VisibleURLTestCase : ChromeTestCase {
106 PausableResponseProvider* _responseProvider;
107 GURL _testURL1;
108 GURL _testURL2;
109 GURL _testURL3;
110 }
111
112 // Spec of the last request URL that reached the server.
113 @property(nonatomic, copy, readonly) NSString* lastRequestURLSpec;
114
115 // Pauses reponse server and disables EG synchronization if |paused| is YES.
116 // Pending navigation will not complete until server is unpaused.
117 - (void)setServerPaused:(BOOL)paused;
118
119 // Waits until |_responseProvider| receives a request with the given |URL|.
120 // Returns YES if request was received, NO on timeout.
121 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL;
122
123 @end
124
125 @implementation VisibleURLTestCase
126
127 - (void)setUp {
128 [super setUp];
129
130 _testURL1 = web::test::HttpServer::MakeUrl("http://url1.test/");
131 _testURL2 = web::test::HttpServer::MakeUrl("http://url2.test/");
132 _testURL3 = web::test::HttpServer::MakeUrl("http://url3.test/");
133
134 // Every page has links for window.history navigations (back, forward, go).
135 const std::string pageContent = base::StringPrintf(
136 "<a onclick='window.history.back()' id='%s'>Go Back</a>"
137 "<a onclick='window.history.forward()' id='%s'>Go Forward</a>"
138 "<a onclick='window.history.go(-1)' id='%s'>Go Delta -1</a>"
139 "<a onclick='window.history.go(1)' id='%s'>Go Delta +1</a>"
140 "<a href='%s' id='%s'>Page 1</a>"
141 "<a href='%s' id='%s'>Page 2</a>"
142 "<a href='%s' id='%s'>Page 3</a>",
143 kGoBackLink, kGoForwardLink, kGoNegativeDeltaLink, kGoPositiveDeltaLink,
144 _testURL1.spec().c_str(), kPage1Link, _testURL2.spec().c_str(),
145 kPage2Link, _testURL3.spec().c_str(), kPage3Link);
146
147 // Create map of canned responses and set up the test HTML server.
148 std::map<GURL, std::string> responses;
149 responses[_testURL1] = std::string(kTestPage1) + pageContent;
150 responses[_testURL2] = std::string(kTestPage2) + pageContent;
151 responses[_testURL3] = std::string(kTestPage3) + pageContent;
152
153 std::unique_ptr<PausableResponseProvider> unique_provider =
154 base::MakeUnique<PausableResponseProvider>(responses);
155 _responseProvider = unique_provider.get();
156 web::test::SetUpHttpServer(std::move(unique_provider));
157
158 [ChromeEarlGrey loadURL:_testURL1];
159 [ChromeEarlGrey loadURL:_testURL2];
160 }
161
162 - (void)tearDown {
163 // This test case disables synchronization, so make sure that it is enabled
164 // if that test has failed and did not enable it back.
165 [[GREYConfiguration sharedInstance]
166 setValue:@YES
167 forConfigKey:kGREYConfigKeySynchronizationEnabled];
168 [super tearDown];
169 }
170
171 #pragma mark -
172 #pragma mark Tests
173
174 // Tests that visible URL is always the same as last committed URL during
175 // pending back and forward navigations.
176 - (void)testBackForwardNavigation {
177 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
178 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
179 }
180
181 // Purge web view caches and pause the server to make sure that tests can
182 // verify omnibox state before server starts responding.
183 PurgeCachedWebViewPages();
184 [self setServerPaused:YES];
185
186 // Tap the back button in the toolbar and verify that URL2 (committed URL) is
187 // displayed even though URL1 is a pending URL.
188 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
189 performAction:grey_tap()];
190 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
191 @"Last request URL: %@", self.lastRequestURLSpec);
192 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
193 assertWithMatcher:grey_notNil()];
194
195 // Make server respond so URL1 becomes committed.
196 [self setServerPaused:NO];
197 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
198 assertWithMatcher:grey_notNil()];
199 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
200 assertWithMatcher:grey_notNil()];
201
202 // Purge web view caches and pause the server to make sure that tests can
203 // verify omnibox state before server starts responding.
204 PurgeCachedWebViewPages();
205 [self setServerPaused:YES];
206
207 // Tap the forward button in the toolbar and verify that URL1 (committed URL)
208 // is displayed even though URL2 is a pending URL.
209 [[EarlGrey selectElementWithMatcher:chrome_test_util::forwardButton()]
210 performAction:grey_tap()];
211 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
212 @"Last request URL: %@", self.lastRequestURLSpec);
213 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
214 assertWithMatcher:grey_notNil()];
215
216 // Make server respond so URL2 becomes committed.
217 [self setServerPaused:NO];
218 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)]
219 assertWithMatcher:grey_notNil()];
220 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
221 assertWithMatcher:grey_notNil()];
222 }
223
224 // Tests that visible URL is always the same as last committed URL during
225 // pending navigations initialted from back history popover.
226 - (void)testHistoryNavigation {
227 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
228 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
229 }
230
231 // Purge web view caches and pause the server to make sure that tests can
232 // verify omnibox state before server starts responding.
233 PurgeCachedWebViewPages();
234 [self setServerPaused:YES];
235
236 // Go back in history and verify that URL2 (committed URL) is displayed even
237 // though URL1 is a pending URL.
238 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
239 performAction:grey_longPress()];
240 NSString* URL1Spec = base::SysUTF8ToNSString(_testURL1.spec());
241 [[EarlGrey selectElementWithMatcher:grey_text(URL1Spec)]
242 performAction:grey_tap()];
243 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
244 @"Last request URL: %@", self.lastRequestURLSpec);
245 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
246 assertWithMatcher:grey_notNil()];
247
248 // Make server respond so URL1 becomes committed.
249 [self setServerPaused:NO];
250 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
251 assertWithMatcher:grey_notNil()];
252 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
253 assertWithMatcher:grey_notNil()];
254 }
255
256 // Tests that stopping a pending Back navigation and reloading reloads committed
257 // URL, not pending URL.
258 - (void)testStoppingPendingBackNavigationAndReload {
259 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
260 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
261 }
262
263 // Purge web view caches and pause the server to make sure that tests can
264 // verify omnibox state before server starts responding.
265 PurgeCachedWebViewPages();
266 [self setServerPaused:YES];
267
268 // Tap the back button, stop pending navigation and reload.
269 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
270 performAction:grey_tap()];
271 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
272 @"Last request URL: %@", self.lastRequestURLSpec);
273 // On iPhone Stop/Reload button is a part of tools menu, so open it.
274 if (!IsIPadIdiom()) {
275 // Enable EG synchronization to make test wait for popover animations.
276 [[GREYConfiguration sharedInstance]
277 setValue:@YES
278 forConfigKey:kGREYConfigKeySynchronizationEnabled];
279 [ChromeEarlGreyUI openToolsMenu];
280 }
281 [[EarlGrey selectElementWithMatcher:chrome_test_util::stopButton()]
282 performAction:grey_tap()];
283 [ChromeEarlGreyUI reload];
284
285 // Make server respond and verify that page2 was reloaded, not page1.
286 [self setServerPaused:NO];
287 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)]
288 assertWithMatcher:grey_notNil()];
289 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
290 assertWithMatcher:grey_notNil()];
291 }
292
293 // Tests that visible URL is always the same as last committed URL during
294 // back forward navigations initiated with JS.
295 - (void)testJSBackForwardNavigation {
296 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
297 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
298 }
299
300 // Purge web view caches and pause the server to make sure that tests can
301 // verify omnibox state before server starts responding.
302 PurgeCachedWebViewPages();
303 [self setServerPaused:YES];
304
305 // Tap the back button on the page and verify that URL2 (committed URL) is
306 // displayed even though URL1 is a pending URL.
307 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)];
308 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
309 @"Last request URL: %@", self.lastRequestURLSpec);
310 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
311 assertWithMatcher:grey_notNil()];
312
313 // Make server respond so URL1 becomes committed.
314 [self setServerPaused:NO];
315 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
316 assertWithMatcher:grey_notNil()];
317 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
318 assertWithMatcher:grey_notNil()];
319
320 // Purge web view caches and pause the server to make sure that tests can
321 // verify omnibox state before server starts responding.
322 PurgeCachedWebViewPages();
323 [self setServerPaused:YES];
324
325 // Tap the forward button on the page and verify that URL1 (committed URL)
326 // is displayed even though URL2 is a pending URL.
327 [ChromeEarlGrey
328 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoForwardLink)];
329 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
330 @"Last request URL: %@", self.lastRequestURLSpec);
331 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
332 assertWithMatcher:grey_notNil()];
333
334 // Make server respond so URL2 becomes committed.
335 [self setServerPaused:NO];
336 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)]
337 assertWithMatcher:grey_notNil()];
338 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
339 assertWithMatcher:grey_notNil()];
340 }
341
342 // Tests that visible URL is always the same as last committed URL during go
343 // navigations initiated with JS.
344 - (void)testJSGoNavigation {
345 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
346 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
347 }
348
349 // Purge web view caches and pause the server to make sure that tests can
350 // verify omnibox state before server starts responding.
351 PurgeCachedWebViewPages();
352 [self setServerPaused:YES];
353
354 // Tap the go negative delta button on the page and verify that URL2
355 // (committed URL) is displayed even though URL1 is a pending URL.
356 [ChromeEarlGrey
357 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoNegativeDeltaLink)];
358 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
359 @"Last request URL: %@", self.lastRequestURLSpec);
360 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
361 assertWithMatcher:grey_notNil()];
362
363 // Make server respond so URL1 becomes committed.
364 [self setServerPaused:NO];
365 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
366 assertWithMatcher:grey_notNil()];
367 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
368 assertWithMatcher:grey_notNil()];
369
370 // Purge web view caches and pause the server to make sure that tests can
371 // verify omnibox state before server starts responding.
372 PurgeCachedWebViewPages();
373 [self setServerPaused:YES];
374
375 // Tap go positive delta button on the page and verify that URL1 (committed
376 // URL) is displayed even though URL2 is a pending URL.
377 [ChromeEarlGrey
378 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoPositiveDeltaLink)];
379 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
380 @"Last request URL: %@", self.lastRequestURLSpec);
381 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
382 assertWithMatcher:grey_notNil()];
383
384 // Make server respond so URL2 becomes committed.
385 [self setServerPaused:NO];
386 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)]
387 assertWithMatcher:grey_notNil()];
388 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
389 assertWithMatcher:grey_notNil()];
390 }
391
392 // Tests that visible URL is always the same as last committed URL during go
393 // back navigation started with pending reload in progress.
394 - (void)testBackNavigationWithPendingReload {
395 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
396 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
397 }
398
399 // Purge web view caches and pause the server to make sure that tests can
400 // verify omnibox state before server starts responding.
401 PurgeCachedWebViewPages();
402 [self setServerPaused:YES];
403
404 // Start reloading the page.
405 if (!IsIPadIdiom()) {
406 // Enable EG synchronization to make test wait for popover animations.
407 [[GREYConfiguration sharedInstance]
408 setValue:@YES
409 forConfigKey:kGREYConfigKeySynchronizationEnabled];
410 [ChromeEarlGreyUI openToolsMenu];
411 }
412 [[EarlGrey selectElementWithMatcher:chrome_test_util::reloadButton()]
413 performAction:grey_tap()];
414
415 // Do not wait until reload is finished, tap the back button in the toolbar
416 // and verify that URL2 (committed URL) is displayed even though URL1 is a
417 // pending URL.
418 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
419 performAction:grey_tap()];
420 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
421 @"Last request URL: %@", self.lastRequestURLSpec);
422 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
423 assertWithMatcher:grey_notNil()];
424
425 // Make server respond so URL1 becomes committed.
426 [self setServerPaused:NO];
427 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
428 assertWithMatcher:grey_notNil()];
429 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
430 assertWithMatcher:grey_notNil()];
431 }
432
433 // Tests that visible URL is always the same as last committed URL during go
434 // back navigation initiated with pending renderer-initiated navigation in
435 // progress.
436 - (void)testBackNavigationWithPendingRendererInitiatedNavigation {
437 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
438 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
439 }
440
441 // Purge web view caches and pause the server to make sure that tests can
442 // verify omnibox state before server starts responding.
443 PurgeCachedWebViewPages();
444 [self setServerPaused:YES];
445
446 // Start renderer initiated navigation.
447 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)];
448
449 // Do not wait until renderer-initiated navigation is finished, tap the back
450 // button in the toolbar and verify that URL2 (committed URL) is displayed
451 // even though URL1 is a pending URL.
452 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
453 performAction:grey_tap()];
454 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
455 @"Last request URL: %@", self.lastRequestURLSpec);
456 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
457 assertWithMatcher:grey_notNil()];
458
459 // Make server respond so URL1 becomes committed.
460 [self setServerPaused:NO];
461 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
462 assertWithMatcher:grey_notNil()];
463 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
464 assertWithMatcher:grey_notNil()];
465 }
466
467 // Tests that visible URL is always the same as last committed URL during
468 // renderer-initiated navigation started with pending back navigation in
469 // progress.
470 - (void)testRendererInitiatedNavigationWithPendingBackNavigation {
471 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
472 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
473 }
474
475 // Purge web view caches and pause the server to make sure that tests can
476 // verify omnibox state before server starts responding.
477 PurgeCachedWebViewPages();
478 [self setServerPaused:YES];
479
480 // Tap the back button in the toolbar and verify that URL2 (committed URL) is
481 // displayed even though URL1 is a pending URL.
482 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
483 performAction:grey_tap()];
484 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
485 @"Last request URL: %@", self.lastRequestURLSpec);
486 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
487 assertWithMatcher:grey_notNil()];
488
489 // Interrupt back navigation with renderer initiated navigation.
490 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)];
491 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())]
492 assertWithMatcher:grey_notNil()];
493
494 // Make server respond so URL1 becomes committed.
495 [self setServerPaused:NO];
496 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage3)]
497 assertWithMatcher:grey_notNil()];
498 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL3.GetContent())]
499 assertWithMatcher:grey_notNil()];
500 }
501
502 // Tests that visible URL is always the same as last committed URL if user
503 // issues 2 go back commands.
504 - (void)testDoubleBackNavigation {
505 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
506 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
507 }
508
509 // Create 3rd entry in the history, to be able to go back twice.
510 [ChromeEarlGrey loadURL:_testURL3];
511
512 // Purge web view caches and pause the server to make sure that tests can
513 // verify omnibox state before server starts responding.
514 PurgeCachedWebViewPages();
515 [self setServerPaused:YES];
516
517 // Tap the back button twice in the toolbar and verify that URL3 (committed
518 // URL) is displayed even though URL1 is a pending URL.
519 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
520 performAction:grey_tap()];
521 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()]
522 performAction:grey_tap()];
523 // Server will receive only one request either for |_testURL2| or for
524 // |_testURL1| depending on load timing and then will pause. So there is no
525 // need to wait for particular request.
526 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL3.GetContent())]
527 assertWithMatcher:grey_notNil()];
528
529 // Make server respond so URL1 becomes committed.
530 [self setServerPaused:NO];
531 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
532 assertWithMatcher:grey_notNil()];
533 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
534 assertWithMatcher:grey_notNil()];
535 }
536
537 // Tests that visible URL is always the same as last committed URL if page calls
538 // window.history.back() twice.
539 - (void)testDoubleBackJSNavigation {
540 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
541 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
542 }
543
544 // Create 3rd entry in the history, to be able to go back twice.
545 [ChromeEarlGrey loadURL:_testURL3];
546
547 // Purge web view caches and pause the server to make sure that tests can
548 // verify omnibox state before server starts responding.
549 PurgeCachedWebViewPages();
550 [self setServerPaused:YES];
551
552 // Tap the back button twice on the page and verify that URL3 (committed URL)
553 // is displayed even though URL1 is a pending URL.
554 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)];
555 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)];
556 // Server will receive only one request either for |_testURL2| or for
557 // |_testURL1| depending on load timing and then will pause. So there is no
558 // need to wait for particular request.
559 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL3.GetContent())]
560 assertWithMatcher:grey_notNil()];
561
562 // Make server respond so URL1 becomes committed.
563 [self setServerPaused:NO];
564 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)]
565 assertWithMatcher:grey_notNil()];
566 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())]
567 assertWithMatcher:grey_notNil()];
568 }
569
570 #pragma mark -
571 #pragma mark Private
572
573 - (NSString*)lastRequestURLSpec {
574 return base::SysUTF8ToNSString(_responseProvider->last_request_url().spec());
575 }
576
577 - (void)setServerPaused:(BOOL)paused {
578 // Disable EG synchronization if server is paused so the framework does not
579 // wait until the tab loading spinner or progress bar indicator becomes idle
580 // (which will not happen until server responds and the navigation is
581 // finished).
582 [[GREYConfiguration sharedInstance]
583 setValue:@(!paused)
584 forConfigKey:kGREYConfigKeySynchronizationEnabled];
585
586 _responseProvider->set_paused(paused);
587 }
588
589 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL {
590 return [[GREYCondition
591 conditionWithName:@"Wait for received request"
592 block:^{
593 return _responseProvider->last_request_url() == URL ? YES
594 : NO;
595 }] waitWithTimeout:10];
596 }
597
598 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/stop_loading_egtest.mm ('k') | ios/chrome/browser/web/web_mediator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698