| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/stringprintf.h" |
| 9 #import "ios/web/public/navigation_item.h" | 10 #import "ios/web/public/navigation_item.h" |
| 10 #import "ios/web/public/navigation_manager.h" | 11 #import "ios/web/public/navigation_manager.h" |
| 11 #import "ios/web/public/test/http_server.h" | 12 #import "ios/web/public/test/http_server.h" |
| 12 #include "ios/web/public/test/http_server_util.h" | 13 #include "ios/web/public/test/http_server_util.h" |
| 13 #import "ios/web/public/web_state/navigation_context.h" | 14 #import "ios/web/public/web_state/navigation_context.h" |
| 14 #include "ios/web/public/web_state/web_state_observer.h" | 15 #include "ios/web/public/web_state/web_state_observer.h" |
| 15 #include "ios/web/test/test_url_constants.h" | 16 #include "ios/web/test/test_url_constants.h" |
| 16 #import "ios/web/test/web_int_test.h" | 17 #import "ios/web/test/web_int_test.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 31 // pointer. | 32 // pointer. |
| 32 ACTION_P3(VerifyNewPageStartedContext, web_state, url, context) { | 33 ACTION_P3(VerifyNewPageStartedContext, web_state, url, context) { |
| 33 *context = arg0; | 34 *context = arg0; |
| 34 ASSERT_TRUE(*context); | 35 ASSERT_TRUE(*context); |
| 35 EXPECT_EQ(web_state, (*context)->GetWebState()); | 36 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 36 EXPECT_EQ(url, (*context)->GetUrl()); | 37 EXPECT_EQ(url, (*context)->GetUrl()); |
| 37 EXPECT_TRUE( | 38 EXPECT_TRUE( |
| 38 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, | 39 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, |
| 39 (*context)->GetPageTransition())); | 40 (*context)->GetPageTransition())); |
| 40 EXPECT_FALSE((*context)->IsSameDocument()); | 41 EXPECT_FALSE((*context)->IsSameDocument()); |
| 42 EXPECT_FALSE((*context)->IsPost()); |
| 41 EXPECT_FALSE((*context)->GetError()); | 43 EXPECT_FALSE((*context)->GetError()); |
| 42 ASSERT_FALSE((*context)->GetResponseHeaders()); | 44 ASSERT_FALSE((*context)->GetResponseHeaders()); |
| 43 NavigationManager* navigation_manager = web_state->GetNavigationManager(); | 45 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 44 NavigationItem* item = navigation_manager->GetPendingItem(); | 46 NavigationItem* item = navigation_manager->GetPendingItem(); |
| 45 EXPECT_EQ(url, item->GetURL()); | 47 EXPECT_EQ(url, item->GetURL()); |
| 46 } | 48 } |
| 47 | 49 |
| 48 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation | 50 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation |
| 49 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as | 51 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as |
| 50 // |context|. | 52 // |context|. |
| 51 ACTION_P3(VerifyNewPageFinishedContext, web_state, url, context) { | 53 ACTION_P3(VerifyNewPageFinishedContext, web_state, url, context) { |
| 52 ASSERT_EQ(*context, arg0); | 54 ASSERT_EQ(*context, arg0); |
| 53 EXPECT_EQ(web_state, (*context)->GetWebState()); | 55 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 54 ASSERT_TRUE((*context)); | 56 ASSERT_TRUE((*context)); |
| 55 EXPECT_EQ(web_state, (*context)->GetWebState()); | 57 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 56 EXPECT_EQ(url, (*context)->GetUrl()); | 58 EXPECT_EQ(url, (*context)->GetUrl()); |
| 57 EXPECT_TRUE( | 59 EXPECT_TRUE( |
| 58 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, | 60 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, |
| 59 (*context)->GetPageTransition())); | 61 (*context)->GetPageTransition())); |
| 60 EXPECT_FALSE((*context)->IsSameDocument()); | 62 EXPECT_FALSE((*context)->IsSameDocument()); |
| 63 EXPECT_FALSE((*context)->IsPost()); |
| 61 EXPECT_FALSE((*context)->GetError()); | 64 EXPECT_FALSE((*context)->GetError()); |
| 62 ASSERT_TRUE((*context)->GetResponseHeaders()); | 65 ASSERT_TRUE((*context)->GetResponseHeaders()); |
| 63 std::string mime_type; | 66 std::string mime_type; |
| 64 (*context)->GetResponseHeaders()->GetMimeType(&mime_type); | 67 (*context)->GetResponseHeaders()->GetMimeType(&mime_type); |
| 65 EXPECT_EQ(kExpectedMimeType, mime_type); | 68 EXPECT_EQ(kExpectedMimeType, mime_type); |
| 66 NavigationManager* navigation_manager = web_state->GetNavigationManager(); | 69 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 67 NavigationItem* item = navigation_manager->GetLastCommittedItem(); | 70 NavigationItem* item = navigation_manager->GetLastCommittedItem(); |
| 68 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); | 71 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); |
| 69 EXPECT_EQ(url, item->GetURL()); | 72 EXPECT_EQ(url, item->GetURL()); |
| 70 } | 73 } |
| 71 | 74 |
| 75 // Verifies correctness of |NavigationContext| (|arg0|) for navigations via POST |
| 76 // HTTP methods passed to |DidStartNavigation|. Stores |NavigationContext| in |
| 77 // |context| pointer. |
| 78 ACTION_P3(VerifyPostStartedContext, web_state, url, context) { |
| 79 *context = arg0; |
| 80 ASSERT_TRUE(*context); |
| 81 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 82 EXPECT_EQ(url, (*context)->GetUrl()); |
| 83 EXPECT_FALSE((*context)->IsSameDocument()); |
| 84 EXPECT_TRUE((*context)->IsPost()); |
| 85 EXPECT_FALSE((*context)->GetError()); |
| 86 ASSERT_FALSE((*context)->GetResponseHeaders()); |
| 87 // TODO(crbug.com/676129): Reload does not create a pending item. Remove this |
| 88 // workaround once the bug is fixed. |
| 89 if (!ui::PageTransitionTypeIncludingQualifiersIs( |
| 90 ui::PageTransition::PAGE_TRANSITION_RELOAD, |
| 91 (*context)->GetPageTransition())) { |
| 92 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 93 NavigationItem* item = navigation_manager->GetPendingItem(); |
| 94 EXPECT_EQ(url, item->GetURL()); |
| 95 } |
| 96 } |
| 97 |
| 98 // Verifies correctness of |NavigationContext| (|arg0|) for navigations via POST |
| 99 // HTTP methods passed to |DidFinishNavigation|. Stores |NavigationContext| in |
| 100 // |context| pointer. |
| 101 ACTION_P3(VerifyPostFinishedContext, web_state, url, context) { |
| 102 ASSERT_EQ(*context, arg0); |
| 103 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 104 ASSERT_TRUE((*context)); |
| 105 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 106 EXPECT_EQ(url, (*context)->GetUrl()); |
| 107 EXPECT_FALSE((*context)->IsSameDocument()); |
| 108 EXPECT_TRUE((*context)->IsPost()); |
| 109 EXPECT_FALSE((*context)->GetError()); |
| 110 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 111 NavigationItem* item = navigation_manager->GetLastCommittedItem(); |
| 112 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); |
| 113 EXPECT_EQ(url, item->GetURL()); |
| 114 } |
| 115 |
| 72 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation | 116 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation |
| 73 // passed to |DidFinishNavigation|. Stores |NavigationContext| in |context| | 117 // passed to |DidFinishNavigation|. Stores |NavigationContext| in |context| |
| 74 // pointer. | 118 // pointer. |
| 75 ACTION_P4(VerifySameDocumentStartedContext, | 119 ACTION_P4(VerifySameDocumentStartedContext, |
| 76 web_state, | 120 web_state, |
| 77 url, | 121 url, |
| 78 context, | 122 context, |
| 79 page_transition) { | 123 page_transition) { |
| 80 *context = arg0; | 124 *context = arg0; |
| 81 ASSERT_TRUE(*context); | 125 ASSERT_TRUE(*context); |
| 82 EXPECT_EQ(web_state, (*context)->GetWebState()); | 126 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 83 EXPECT_EQ(url, (*context)->GetUrl()); | 127 EXPECT_EQ(url, (*context)->GetUrl()); |
| 84 EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs( | 128 EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs( |
| 85 page_transition, (*context)->GetPageTransition())); | 129 page_transition, (*context)->GetPageTransition())); |
| 86 EXPECT_FALSE((*context)->IsSameDocument()); | 130 EXPECT_FALSE((*context)->IsSameDocument()); |
| 131 EXPECT_FALSE((*context)->IsPost()); |
| 87 EXPECT_FALSE((*context)->GetError()); | 132 EXPECT_FALSE((*context)->GetError()); |
| 88 EXPECT_FALSE((*context)->GetResponseHeaders()); | 133 EXPECT_FALSE((*context)->GetResponseHeaders()); |
| 89 } | 134 } |
| 90 | 135 |
| 91 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation | 136 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation |
| 92 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as | 137 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as |
| 93 // |context|. | 138 // |context|. |
| 94 ACTION_P4(VerifySameDocumentFinishedContext, | 139 ACTION_P4(VerifySameDocumentFinishedContext, |
| 95 web_state, | 140 web_state, |
| 96 url, | 141 url, |
| 97 context, | 142 context, |
| 98 page_transition) { | 143 page_transition) { |
| 99 ASSERT_EQ(*context, arg0); | 144 ASSERT_EQ(*context, arg0); |
| 100 ASSERT_TRUE(*context); | 145 ASSERT_TRUE(*context); |
| 101 EXPECT_EQ(web_state, (*context)->GetWebState()); | 146 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 102 EXPECT_EQ(url, (*context)->GetUrl()); | 147 EXPECT_EQ(url, (*context)->GetUrl()); |
| 103 EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs( | 148 EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs( |
| 104 page_transition, (*context)->GetPageTransition())); | 149 page_transition, (*context)->GetPageTransition())); |
| 105 EXPECT_TRUE((*context)->IsSameDocument()); | 150 EXPECT_TRUE((*context)->IsSameDocument()); |
| 151 EXPECT_FALSE((*context)->IsPost()); |
| 106 EXPECT_FALSE((*context)->GetError()); | 152 EXPECT_FALSE((*context)->GetError()); |
| 107 EXPECT_FALSE((*context)->GetResponseHeaders()); | 153 EXPECT_FALSE((*context)->GetResponseHeaders()); |
| 108 NavigationManager* navigation_manager = web_state->GetNavigationManager(); | 154 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 109 NavigationItem* item = navigation_manager->GetLastCommittedItem(); | 155 NavigationItem* item = navigation_manager->GetLastCommittedItem(); |
| 110 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); | 156 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); |
| 111 EXPECT_EQ(url, item->GetURL()); | 157 EXPECT_EQ(url, item->GetURL()); |
| 112 } | 158 } |
| 113 | 159 |
| 114 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation | 160 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation |
| 115 // to native URLs passed to |DidStartNavigation|. Stores |NavigationContext| in | 161 // to native URLs passed to |DidStartNavigation|. Stores |NavigationContext| in |
| 116 // |context| pointer. | 162 // |context| pointer. |
| 117 ACTION_P3(VerifyNewNativePageStartedContext, web_state, url, context) { | 163 ACTION_P3(VerifyNewNativePageStartedContext, web_state, url, context) { |
| 118 *context = arg0; | 164 *context = arg0; |
| 119 ASSERT_TRUE(*context); | 165 ASSERT_TRUE(*context); |
| 120 EXPECT_EQ(web_state, (*context)->GetWebState()); | 166 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 121 EXPECT_EQ(url, (*context)->GetUrl()); | 167 EXPECT_EQ(url, (*context)->GetUrl()); |
| 122 EXPECT_TRUE( | 168 EXPECT_TRUE( |
| 123 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, | 169 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, |
| 124 (*context)->GetPageTransition())); | 170 (*context)->GetPageTransition())); |
| 125 EXPECT_FALSE((*context)->IsSameDocument()); | 171 EXPECT_FALSE((*context)->IsSameDocument()); |
| 172 EXPECT_FALSE((*context)->IsPost()); |
| 126 EXPECT_FALSE((*context)->GetError()); | 173 EXPECT_FALSE((*context)->GetError()); |
| 127 EXPECT_FALSE((*context)->GetResponseHeaders()); | 174 EXPECT_FALSE((*context)->GetResponseHeaders()); |
| 128 NavigationManager* navigation_manager = web_state->GetNavigationManager(); | 175 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 129 NavigationItem* item = navigation_manager->GetPendingItem(); | 176 NavigationItem* item = navigation_manager->GetPendingItem(); |
| 130 EXPECT_EQ(url, item->GetURL()); | 177 EXPECT_EQ(url, item->GetURL()); |
| 131 } | 178 } |
| 132 | 179 |
| 133 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation | 180 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation |
| 134 // to native URLs passed to |DidFinishNavigation|. Asserts that | 181 // to native URLs passed to |DidFinishNavigation|. Asserts that |
| 135 // |NavigationContext| the same as |context|. | 182 // |NavigationContext| the same as |context|. |
| 136 ACTION_P3(VerifyNewNativePageFinishedContext, web_state, url, context) { | 183 ACTION_P3(VerifyNewNativePageFinishedContext, web_state, url, context) { |
| 137 ASSERT_EQ(*context, arg0); | 184 ASSERT_EQ(*context, arg0); |
| 138 ASSERT_TRUE(*context); | 185 ASSERT_TRUE(*context); |
| 139 EXPECT_EQ(web_state, (*context)->GetWebState()); | 186 EXPECT_EQ(web_state, (*context)->GetWebState()); |
| 140 EXPECT_EQ(url, (*context)->GetUrl()); | 187 EXPECT_EQ(url, (*context)->GetUrl()); |
| 141 EXPECT_TRUE( | 188 EXPECT_TRUE( |
| 142 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, | 189 PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED, |
| 143 (*context)->GetPageTransition())); | 190 (*context)->GetPageTransition())); |
| 144 EXPECT_FALSE((*context)->IsSameDocument()); | 191 EXPECT_FALSE((*context)->IsSameDocument()); |
| 192 EXPECT_FALSE((*context)->IsPost()); |
| 145 EXPECT_FALSE((*context)->GetError()); | 193 EXPECT_FALSE((*context)->GetError()); |
| 146 EXPECT_FALSE((*context)->GetResponseHeaders()); | 194 EXPECT_FALSE((*context)->GetResponseHeaders()); |
| 147 NavigationManager* navigation_manager = web_state->GetNavigationManager(); | 195 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 148 NavigationItem* item = navigation_manager->GetLastCommittedItem(); | 196 NavigationItem* item = navigation_manager->GetLastCommittedItem(); |
| 149 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); | 197 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); |
| 150 EXPECT_EQ(url, item->GetURL()); | 198 EXPECT_EQ(url, item->GetURL()); |
| 151 } | 199 } |
| 152 | 200 |
| 153 // Verifies correctness of |NavigationContext| (|arg0|) for reload navigation | 201 // Verifies correctness of |NavigationContext| (|arg0|) for reload navigation |
| 154 // passed to |DidStartNavigation|. Stores |NavigationContext| in |context| | 202 // passed to |DidStartNavigation|. Stores |NavigationContext| in |context| |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 445 |
| 398 // Reload native content. | 446 // Reload native content. |
| 399 EXPECT_CALL(*observer_, DidStartNavigation(_)) | 447 EXPECT_CALL(*observer_, DidStartNavigation(_)) |
| 400 .WillOnce(VerifyReloadStartedContext(web_state(), url, &context)); | 448 .WillOnce(VerifyReloadStartedContext(web_state(), url, &context)); |
| 401 EXPECT_CALL(*observer_, DidFinishNavigation(_)) | 449 EXPECT_CALL(*observer_, DidFinishNavigation(_)) |
| 402 .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context, | 450 .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context, |
| 403 false /* is_web_page */)); | 451 false /* is_web_page */)); |
| 404 navigation_manager()->Reload(ReloadType::NORMAL, false /*check_for_repost*/); | 452 navigation_manager()->Reload(ReloadType::NORMAL, false /*check_for_repost*/); |
| 405 } | 453 } |
| 406 | 454 |
| 455 // Tests successful navigation to a new page with post HTTP method. |
| 456 TEST_F(StartAndFinishNavigationTest, UserInitiatedPostNavigation) { |
| 457 const GURL url = HttpServer::MakeUrl("http://chromium.test"); |
| 458 std::map<GURL, std::string> responses; |
| 459 responses[url] = "Chromium Test"; |
| 460 web::test::SetUpSimpleHttpServer(responses); |
| 461 |
| 462 // Perform new page navigation. |
| 463 NavigationContext* context = nullptr; |
| 464 EXPECT_CALL(*observer_, DidStartNavigation(_)) |
| 465 .WillOnce(VerifyPostStartedContext(web_state(), url, &context)); |
| 466 EXPECT_CALL(*observer_, DidFinishNavigation(_)) |
| 467 .WillOnce(VerifyPostFinishedContext(web_state(), url, &context)); |
| 468 |
| 469 // Load request using POST HTTP method. |
| 470 web::NavigationManager::WebLoadParams params(url); |
| 471 params.post_data.reset( |
| 472 [[@"foo" dataUsingEncoding:NSUTF8StringEncoding] retain]); |
| 473 params.extra_headers.reset([@{ @"Content-Type" : @"text/html" } retain]); |
| 474 LoadWithParams(params); |
| 475 } |
| 476 |
| 477 // Tests successful navigation to a new page with post HTTP method. |
| 478 TEST_F(StartAndFinishNavigationTest, RendererInitiatedPostNavigation) { |
| 479 const GURL url = HttpServer::MakeUrl("http://chromium.test"); |
| 480 std::map<GURL, std::string> responses; |
| 481 responses[url] = "<form method='post' id='form'></form>"; |
| 482 web::test::SetUpSimpleHttpServer(responses); |
| 483 |
| 484 // Perform new page navigation. |
| 485 NavigationContext* context = nullptr; |
| 486 EXPECT_CALL(*observer_, DidStartNavigation(_)); |
| 487 EXPECT_CALL(*observer_, DidFinishNavigation(_)); |
| 488 LoadUrl(url); |
| 489 |
| 490 // Submit the form using JavaScript. |
| 491 EXPECT_CALL(*observer_, DidStartNavigation(_)) |
| 492 .WillOnce(VerifyPostStartedContext(web_state(), url, &context)); |
| 493 EXPECT_CALL(*observer_, DidFinishNavigation(_)) |
| 494 .WillOnce(VerifyPostFinishedContext(web_state(), url, &context)); |
| 495 ExecuteJavaScript(@"window.document.getElementById('form').submit();"); |
| 496 } |
| 497 |
| 498 // Tests successful reload of a page returned for post request. |
| 499 TEST_F(StartAndFinishNavigationTest, ReloadPostNavigation) { |
| 500 const GURL url = HttpServer::MakeUrl("http://chromium.test"); |
| 501 std::map<GURL, std::string> responses; |
| 502 const GURL action = HttpServer::MakeUrl("http://action.test"); |
| 503 responses[url] = |
| 504 base::StringPrintf("<form method='post' id='form' action='%s'></form>", |
| 505 action.spec().c_str()); |
| 506 web::test::SetUpSimpleHttpServer(responses); |
| 507 |
| 508 // Perform new page navigation. |
| 509 NavigationContext* context = nullptr; |
| 510 EXPECT_CALL(*observer_, DidStartNavigation(_)); |
| 511 EXPECT_CALL(*observer_, DidFinishNavigation(_)); |
| 512 LoadUrl(url); |
| 513 |
| 514 // Submit the form using JavaScript. |
| 515 EXPECT_CALL(*observer_, DidStartNavigation(_)); |
| 516 EXPECT_CALL(*observer_, DidFinishNavigation(_)); |
| 517 ExecuteBlockAndWaitForLoad(action, ^{ |
| 518 ExecuteJavaScript(@"window.document.getElementById('form').submit();"); |
| 519 }); |
| 520 |
| 521 // Reload the page. |
| 522 EXPECT_CALL(*observer_, DidStartNavigation(_)) |
| 523 .WillOnce(VerifyPostStartedContext(web_state(), action, &context)); |
| 524 EXPECT_CALL(*observer_, DidFinishNavigation(_)) |
| 525 .WillOnce(VerifyPostFinishedContext(web_state(), action, &context)); |
| 526 // TODO(crbug.com/700958): ios/web ignores |check_for_repost| flag and current |
| 527 // delegate does not run callback for ShowRepostFormWarningDialog. Clearing |
| 528 // the delegate will allow form resubmission. Remove this workaround (clearing |
| 529 // the delegate, once |check_for_repost| is supported). |
| 530 web_state()->SetDelegate(nullptr); |
| 531 ExecuteBlockAndWaitForLoad(action, ^{ |
| 532 navigation_manager()->Reload(ReloadType::NORMAL, |
| 533 false /*check_for_repost*/); |
| 534 }); |
| 535 } |
| 536 |
| 537 // Tests going forward to a page rendered from post response. |
| 538 TEST_F(StartAndFinishNavigationTest, ForwardPostNavigation) { |
| 539 const GURL url = HttpServer::MakeUrl("http://chromium.test"); |
| 540 std::map<GURL, std::string> responses; |
| 541 const GURL action = HttpServer::MakeUrl("http://action.test"); |
| 542 responses[url] = |
| 543 base::StringPrintf("<form method='post' id='form' action='%s'></form>", |
| 544 action.spec().c_str()); |
| 545 web::test::SetUpSimpleHttpServer(responses); |
| 546 |
| 547 // Perform new page navigation. |
| 548 NavigationContext* context = nullptr; |
| 549 EXPECT_CALL(*observer_, DidStartNavigation(_)); |
| 550 EXPECT_CALL(*observer_, DidFinishNavigation(_)); |
| 551 LoadUrl(url); |
| 552 |
| 553 // Submit the form using JavaScript. |
| 554 EXPECT_CALL(*observer_, DidStartNavigation(_)); |
| 555 EXPECT_CALL(*observer_, DidFinishNavigation(_)); |
| 556 ExecuteBlockAndWaitForLoad(action, ^{ |
| 557 ExecuteJavaScript(@"window.document.getElementById('form').submit();"); |
| 558 }); |
| 559 |
| 560 // Go Back. |
| 561 EXPECT_CALL(*observer_, DidStartNavigation(_)); |
| 562 EXPECT_CALL(*observer_, DidFinishNavigation(_)); |
| 563 ExecuteBlockAndWaitForLoad(url, ^{ |
| 564 navigation_manager()->GoBack(); |
| 565 }); |
| 566 |
| 567 // Go forward. |
| 568 EXPECT_CALL(*observer_, DidStartNavigation(_)) |
| 569 .WillOnce(VerifyPostStartedContext(web_state(), action, &context)); |
| 570 EXPECT_CALL(*observer_, DidFinishNavigation(_)) |
| 571 .WillOnce(VerifyPostFinishedContext(web_state(), action, &context)); |
| 572 // TODO(crbug.com/700958): ios/web ignores |check_for_repost| flag and current |
| 573 // delegate does not run callback for ShowRepostFormWarningDialog. Clearing |
| 574 // the delegate will allow form resubmission. Remove this workaround (clearing |
| 575 // the delegate, once |check_for_repost| is supported). |
| 576 web_state()->SetDelegate(nullptr); |
| 577 ExecuteBlockAndWaitForLoad(action, ^{ |
| 578 navigation_manager()->GoForward(); |
| 579 }); |
| 580 } |
| 581 |
| 407 } // namespace web | 582 } // namespace web |
| OLD | NEW |