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

Unified Diff: ios/web/web_state/navigation_callbacks_inttest.mm

Issue 2912993002: Call WebStateObserver::DidStopLoading for native content reloads. (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/navigation_callbacks_inttest.mm
diff --git a/ios/web/web_state/navigation_callbacks_inttest.mm b/ios/web/web_state/navigation_callbacks_inttest.mm
index cedf3bb930ab36c050ea6e5e50a5caf029448933..ac78fd241a0ca81b1ba8940530f27ab3712860b1 100644
--- a/ios/web/web_state/navigation_callbacks_inttest.mm
+++ b/ios/web/web_state/navigation_callbacks_inttest.mm
@@ -6,6 +6,7 @@
#include <string>
#include "base/memory/ptr_util.h"
+#include "base/strings/stringprintf.h"
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h"
#import "ios/web/public/test/http_server.h"
@@ -38,8 +39,10 @@ ACTION_P3(VerifyNewPageStartedContext, web_state, url, context) {
PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED,
(*context)->GetPageTransition()));
EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_FALSE((*context)->IsPost());
EXPECT_FALSE((*context)->GetError());
ASSERT_FALSE((*context)->GetResponseHeaders());
+ ASSERT_TRUE(web_state->IsLoading());
NavigationManager* navigation_manager = web_state->GetNavigationManager();
NavigationItem* item = navigation_manager->GetPendingItem();
EXPECT_EQ(url, item->GetURL());
@@ -58,10 +61,12 @@ ACTION_P3(VerifyNewPageFinishedContext, web_state, url, context) {
PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED,
(*context)->GetPageTransition()));
EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_FALSE((*context)->IsPost());
EXPECT_FALSE((*context)->GetError());
ASSERT_TRUE((*context)->GetResponseHeaders());
std::string mime_type;
(*context)->GetResponseHeaders()->GetMimeType(&mime_type);
+ ASSERT_TRUE(web_state->IsLoading());
EXPECT_EQ(kExpectedMimeType, mime_type);
NavigationManager* navigation_manager = web_state->GetNavigationManager();
NavigationItem* item = navigation_manager->GetLastCommittedItem();
@@ -69,6 +74,49 @@ ACTION_P3(VerifyNewPageFinishedContext, web_state, url, context) {
EXPECT_EQ(url, item->GetURL());
}
+// Verifies correctness of |NavigationContext| (|arg0|) for navigations via POST
+// HTTP methods passed to |DidStartNavigation|. Stores |NavigationContext| in
+// |context| pointer.
+ACTION_P3(VerifyPostStartedContext, web_state, url, context) {
+ *context = arg0;
+ ASSERT_TRUE(*context);
+ EXPECT_EQ(web_state, (*context)->GetWebState());
+ EXPECT_EQ(url, (*context)->GetUrl());
+ EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_TRUE((*context)->IsPost());
+ EXPECT_FALSE((*context)->GetError());
+ ASSERT_FALSE((*context)->GetResponseHeaders());
+ ASSERT_TRUE(web_state->IsLoading());
+ // TODO(crbug.com/676129): Reload does not create a pending item. Remove this
+ // workaround once the bug is fixed.
+ if (!ui::PageTransitionTypeIncludingQualifiersIs(
+ ui::PageTransition::PAGE_TRANSITION_RELOAD,
+ (*context)->GetPageTransition())) {
+ NavigationManager* navigation_manager = web_state->GetNavigationManager();
+ NavigationItem* item = navigation_manager->GetPendingItem();
+ EXPECT_EQ(url, item->GetURL());
+ }
+}
+
+// Verifies correctness of |NavigationContext| (|arg0|) for navigations via POST
+// HTTP methods passed to |DidFinishNavigation|. Stores |NavigationContext| in
+// |context| pointer.
+ACTION_P3(VerifyPostFinishedContext, web_state, url, context) {
+ ASSERT_EQ(*context, arg0);
+ EXPECT_EQ(web_state, (*context)->GetWebState());
+ ASSERT_TRUE((*context));
+ EXPECT_EQ(web_state, (*context)->GetWebState());
+ EXPECT_EQ(url, (*context)->GetUrl());
+ EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_TRUE((*context)->IsPost());
+ EXPECT_FALSE((*context)->GetError());
+ ASSERT_TRUE(web_state->IsLoading());
+ NavigationManager* navigation_manager = web_state->GetNavigationManager();
+ NavigationItem* item = navigation_manager->GetLastCommittedItem();
+ EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
+ EXPECT_EQ(url, item->GetURL());
+}
+
// Verifies correctness of |NavigationContext| (|arg0|) for same page navigation
// passed to |DidFinishNavigation|. Stores |NavigationContext| in |context|
// pointer.
@@ -84,6 +132,7 @@ ACTION_P4(VerifySameDocumentStartedContext,
EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs(
page_transition, (*context)->GetPageTransition()));
EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_FALSE((*context)->IsPost());
EXPECT_FALSE((*context)->GetError());
EXPECT_FALSE((*context)->GetResponseHeaders());
}
@@ -103,6 +152,7 @@ ACTION_P4(VerifySameDocumentFinishedContext,
EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs(
page_transition, (*context)->GetPageTransition()));
EXPECT_TRUE((*context)->IsSameDocument());
+ EXPECT_FALSE((*context)->IsPost());
EXPECT_FALSE((*context)->GetError());
EXPECT_FALSE((*context)->GetResponseHeaders());
NavigationManager* navigation_manager = web_state->GetNavigationManager();
@@ -123,8 +173,10 @@ ACTION_P3(VerifyNewNativePageStartedContext, web_state, url, context) {
PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED,
(*context)->GetPageTransition()));
EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_FALSE((*context)->IsPost());
EXPECT_FALSE((*context)->GetError());
EXPECT_FALSE((*context)->GetResponseHeaders());
+ ASSERT_TRUE(web_state->IsLoading());
NavigationManager* navigation_manager = web_state->GetNavigationManager();
NavigationItem* item = navigation_manager->GetPendingItem();
EXPECT_EQ(url, item->GetURL());
@@ -142,6 +194,7 @@ ACTION_P3(VerifyNewNativePageFinishedContext, web_state, url, context) {
PageTransitionCoreTypeIs(ui::PageTransition::PAGE_TRANSITION_TYPED,
(*context)->GetPageTransition()));
EXPECT_FALSE((*context)->IsSameDocument());
+ EXPECT_FALSE((*context)->IsPost());
EXPECT_FALSE((*context)->GetError());
EXPECT_FALSE((*context)->GetResponseHeaders());
NavigationManager* navigation_manager = web_state->GetNavigationManager();
@@ -172,7 +225,7 @@ ACTION_P3(VerifyReloadStartedContext, web_state, url, context) {
// Verifies correctness of |NavigationContext| (|arg0|) for reload navigation
// passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as
// |context|.
-ACTION_P3(VerifyReloadFinishedContext, web_state, url, context) {
+ACTION_P4(VerifyReloadFinishedContext, web_state, url, context, is_web_page) {
ASSERT_EQ(*context, arg0);
ASSERT_TRUE(*context);
EXPECT_EQ(web_state, (*context)->GetWebState());
@@ -182,7 +235,14 @@ ACTION_P3(VerifyReloadFinishedContext, web_state, url, context) {
(*context)->GetPageTransition()));
EXPECT_FALSE((*context)->IsSameDocument());
EXPECT_FALSE((*context)->GetError());
- EXPECT_FALSE((*context)->GetResponseHeaders());
+ if (is_web_page) {
+ ASSERT_TRUE((*context)->GetResponseHeaders());
+ std::string mime_type;
+ (*context)->GetResponseHeaders()->GetMimeType(&mime_type);
+ EXPECT_EQ(kExpectedMimeType, mime_type);
+ } else {
+ EXPECT_FALSE((*context)->GetResponseHeaders());
+ }
NavigationManager* navigation_manager = web_state->GetNavigationManager();
NavigationItem* item = navigation_manager->GetLastCommittedItem();
EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
@@ -195,27 +255,31 @@ class WebStateObserverMock : public WebStateObserver {
WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {}
MOCK_METHOD1(DidStartNavigation, void(NavigationContext* context));
MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context));
+ MOCK_METHOD0(DidStartLoading, void());
+ MOCK_METHOD0(DidStopLoading, void());
};
} // namespace
using test::HttpServer;
+using testing::StrictMock;
using testing::_;
-// Test fixture for WebStateDelegate::ProvisionalNavigationStarted and
-// WebStateDelegate::DidFinishNavigation integration tests.
-class StartAndFinishNavigationTest : public WebIntTest {
+// Test fixture for WebStateDelegate::ProvisionalNavigationStarted,
+// WebStateDelegate::DidFinishNavigation, WebStateDelegate::DidStartLoading and
+// WebStateDelegate::DidStopLoading integration tests.
+class NavigationCallbacksTest : public WebIntTest {
void SetUp() override {
WebIntTest::SetUp();
- observer_ = base::MakeUnique<WebStateObserverMock>(web_state());
+ observer_ = base::MakeUnique<StrictMock<WebStateObserverMock>>(web_state());
}
protected:
- std::unique_ptr<WebStateObserverMock> observer_;
+ std::unique_ptr<StrictMock<WebStateObserverMock>> observer_;
};
// Tests successful navigation to a new page.
-TEST_F(StartAndFinishNavigationTest, NewPageNavigation) {
+TEST_F(NavigationCallbacksTest, NewPageNavigation) {
const GURL url = HttpServer::MakeUrl("http://chromium.test");
std::map<GURL, std::string> responses;
responses[url] = "Chromium Test";
@@ -225,13 +289,49 @@ TEST_F(StartAndFinishNavigationTest, NewPageNavigation) {
NavigationContext* context = nullptr;
EXPECT_CALL(*observer_, DidStartNavigation(_))
.WillOnce(VerifyNewPageStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifyNewPageFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(url);
}
+// Tests web page reload navigation.
+TEST_F(NavigationCallbacksTest, WebPageReloadNavigation) {
+ const GURL url = HttpServer::MakeUrl("http://chromium.test");
+ std::map<GURL, std::string> responses;
+ responses[url] = "Chromium Test";
+ web::test::SetUpSimpleHttpServer(responses);
+
+ // Perform new page navigation.
+ NavigationContext* context = nullptr;
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ LoadUrl(url);
+
+ // Reload web page.
+ EXPECT_CALL(*observer_, DidStartNavigation(_))
+ .WillOnce(VerifyReloadStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_))
+ .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context,
+ true /* is_web_page */));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ // TODO(crbug.com/700958): ios/web ignores |check_for_repost| flag and current
+ // delegate does not run callback for ShowRepostFormWarningDialog. Clearing
+ // the delegate will allow form resubmission. Remove this workaround (clearing
+ // the delegate, once |check_for_repost| is supported).
+ web_state()->SetDelegate(nullptr);
+ ExecuteBlockAndWaitForLoad(url, ^{
+ navigation_manager()->Reload(ReloadType::NORMAL,
+ false /*check_for_repost*/);
+ });
+}
+
// Tests user-initiated hash change.
-TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
+TEST_F(NavigationCallbacksTest, UserInitiatedHashChangeNavigation) {
const GURL url = HttpServer::MakeUrl("http://chromium.test");
std::map<GURL, std::string> responses;
responses[url] = "Chromium Test";
@@ -241,8 +341,10 @@ TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
NavigationContext* context = nullptr;
EXPECT_CALL(*observer_, DidStartNavigation(_))
.WillOnce(VerifyNewPageStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifyNewPageFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(url);
// Perform same-page navigation.
@@ -251,10 +353,12 @@ TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
.WillOnce(VerifySameDocumentStartedContext(
web_state(), hash_url, &context,
ui::PageTransition::PAGE_TRANSITION_TYPED));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifySameDocumentFinishedContext(
web_state(), hash_url, &context,
ui::PageTransition::PAGE_TRANSITION_TYPED));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(hash_url);
// Perform same-page navigation by going back.
@@ -262,17 +366,19 @@ TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
.WillOnce(VerifySameDocumentStartedContext(
web_state(), url, &context,
ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifySameDocumentFinishedContext(
web_state(), url, &context,
ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT));
+ EXPECT_CALL(*observer_, DidStopLoading());
ExecuteBlockAndWaitForLoad(url, ^{
navigation_manager()->GoBack();
});
}
// Tests renderer-initiated hash change.
-TEST_F(StartAndFinishNavigationTest, RendererInitiatedHashChangeNavigation) {
+TEST_F(NavigationCallbacksTest, RendererInitiatedHashChangeNavigation) {
const GURL url = HttpServer::MakeUrl("http://chromium.test");
std::map<GURL, std::string> responses;
responses[url] = "Chromium Test";
@@ -282,8 +388,10 @@ TEST_F(StartAndFinishNavigationTest, RendererInitiatedHashChangeNavigation) {
NavigationContext* context = nullptr;
EXPECT_CALL(*observer_, DidStartNavigation(_))
.WillOnce(VerifyNewPageStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifyNewPageFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(url);
// Perform same-page navigation using JavaScript.
@@ -292,15 +400,17 @@ TEST_F(StartAndFinishNavigationTest, RendererInitiatedHashChangeNavigation) {
.WillOnce(VerifySameDocumentStartedContext(
web_state(), hash_url, &context,
ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifySameDocumentFinishedContext(
web_state(), hash_url, &context,
ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT));
+ EXPECT_CALL(*observer_, DidStopLoading());
ExecuteJavaScript(@"window.location.hash = '#1'");
}
// Tests state change.
-TEST_F(StartAndFinishNavigationTest, StateNavigation) {
+TEST_F(NavigationCallbacksTest, StateNavigation) {
const GURL url = HttpServer::MakeUrl("http://chromium.test");
std::map<GURL, std::string> responses;
responses[url] = "Chromium Test";
@@ -310,8 +420,10 @@ TEST_F(StartAndFinishNavigationTest, StateNavigation) {
NavigationContext* context = nullptr;
EXPECT_CALL(*observer_, DidStartNavigation(_))
.WillOnce(VerifyNewPageStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifyNewPageFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(url);
// Perform push state using JavaScript.
@@ -340,30 +452,184 @@ TEST_F(StartAndFinishNavigationTest, StateNavigation) {
}
// Tests native content navigation.
-TEST_F(StartAndFinishNavigationTest, NativeContentNavigation) {
+TEST_F(NavigationCallbacksTest, NativeContentNavigation) {
GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
NavigationContext* context = nullptr;
EXPECT_CALL(*observer_, DidStartNavigation(_))
.WillOnce(VerifyNewNativePageStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
.WillOnce(VerifyNewNativePageFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(url);
}
// Tests native content reload navigation.
-TEST_F(StartAndFinishNavigationTest, NativeContentReload) {
+TEST_F(NavigationCallbacksTest, NativeContentReload) {
GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
NavigationContext* context = nullptr;
EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
LoadUrl(url);
// Reload native content.
EXPECT_CALL(*observer_, DidStartNavigation(_))
.WillOnce(VerifyReloadStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
EXPECT_CALL(*observer_, DidFinishNavigation(_))
- .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context));
+ .WillOnce(VerifyReloadFinishedContext(web_state(), url, &context,
+ false /* is_web_page */));
+ EXPECT_CALL(*observer_, DidStopLoading());
navigation_manager()->Reload(ReloadType::NORMAL, false /*check_for_repost*/);
}
+// Tests successful navigation to a new page with post HTTP method.
+TEST_F(NavigationCallbacksTest, UserInitiatedPostNavigation) {
+ const GURL url = HttpServer::MakeUrl("http://chromium.test");
+ std::map<GURL, std::string> responses;
+ responses[url] = "Chromium Test";
+ web::test::SetUpSimpleHttpServer(responses);
+
+ // Perform new page navigation.
+ NavigationContext* context = nullptr;
+ EXPECT_CALL(*observer_, DidStartNavigation(_))
+ .WillOnce(VerifyPostStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_))
+ .WillOnce(VerifyPostFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
+
+ // Load request using POST HTTP method.
+ web::NavigationManager::WebLoadParams params(url);
+ params.post_data.reset(
+ [[@"foo" dataUsingEncoding:NSUTF8StringEncoding] retain]);
+ params.extra_headers.reset([@{ @"Content-Type" : @"text/html" } retain]);
+ LoadWithParams(params);
+}
+
+// Tests successful navigation to a new page with post HTTP method.
+TEST_F(NavigationCallbacksTest, RendererInitiatedPostNavigation) {
+ const GURL url = HttpServer::MakeUrl("http://chromium.test");
+ std::map<GURL, std::string> responses;
+ responses[url] = "<form method='post' id='form'></form>";
+ web::test::SetUpSimpleHttpServer(responses);
+
+ // Perform new page navigation.
+ NavigationContext* context = nullptr;
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ LoadUrl(url);
+
+ // Submit the form using JavaScript.
+ EXPECT_CALL(*observer_, DidStartNavigation(_))
+ .WillOnce(VerifyPostStartedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_))
+ .WillOnce(VerifyPostFinishedContext(web_state(), url, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ ExecuteJavaScript(@"window.document.getElementById('form').submit();");
+}
+
+// Tests successful reload of a page returned for post request.
+TEST_F(NavigationCallbacksTest, ReloadPostNavigation) {
+ const GURL url = HttpServer::MakeUrl("http://chromium.test");
+ std::map<GURL, std::string> responses;
+ const GURL action = HttpServer::MakeUrl("http://action.test");
+ responses[url] =
+ base::StringPrintf("<form method='post' id='form' action='%s'></form>",
+ action.spec().c_str());
+ web::test::SetUpSimpleHttpServer(responses);
+
+ // Perform new page navigation.
+ NavigationContext* context = nullptr;
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ LoadUrl(url);
+
+ // Submit the form using JavaScript.
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ ExecuteBlockAndWaitForLoad(action, ^{
+ ExecuteJavaScript(@"window.document.getElementById('form').submit();");
+ });
+
+ // Reload the page.
+ EXPECT_CALL(*observer_, DidStartNavigation(_))
+ .WillOnce(VerifyPostStartedContext(web_state(), action, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_))
+ .WillOnce(VerifyPostFinishedContext(web_state(), action, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ // TODO(crbug.com/700958): ios/web ignores |check_for_repost| flag and current
+ // delegate does not run callback for ShowRepostFormWarningDialog. Clearing
+ // the delegate will allow form resubmission. Remove this workaround (clearing
+ // the delegate, once |check_for_repost| is supported).
+ web_state()->SetDelegate(nullptr);
+ ExecuteBlockAndWaitForLoad(action, ^{
+ navigation_manager()->Reload(ReloadType::NORMAL,
+ false /*check_for_repost*/);
+ });
+}
+
+// Tests going forward to a page rendered from post response.
+TEST_F(NavigationCallbacksTest, ForwardPostNavigation) {
+ const GURL url = HttpServer::MakeUrl("http://chromium.test");
+ std::map<GURL, std::string> responses;
+ const GURL action = HttpServer::MakeUrl("http://action.test");
+ responses[url] =
+ base::StringPrintf("<form method='post' id='form' action='%s'></form>",
+ action.spec().c_str());
+ web::test::SetUpSimpleHttpServer(responses);
+
+ // Perform new page navigation.
+ NavigationContext* context = nullptr;
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ LoadUrl(url);
+
+ // Submit the form using JavaScript.
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ ExecuteBlockAndWaitForLoad(action, ^{
+ ExecuteJavaScript(@"window.document.getElementById('form').submit();");
+ });
+
+ // Go Back.
+ EXPECT_CALL(*observer_, DidStartNavigation(_));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ ExecuteBlockAndWaitForLoad(url, ^{
+ navigation_manager()->GoBack();
+ });
+
+ // Go forward.
+ EXPECT_CALL(*observer_, DidStartNavigation(_))
+ .WillOnce(VerifyPostStartedContext(web_state(), action, &context));
+ EXPECT_CALL(*observer_, DidStartLoading());
+ EXPECT_CALL(*observer_, DidFinishNavigation(_))
+ .WillOnce(VerifyPostFinishedContext(web_state(), action, &context));
+ EXPECT_CALL(*observer_, DidStopLoading());
+ // TODO(crbug.com/700958): ios/web ignores |check_for_repost| flag and current
+ // delegate does not run callback for ShowRepostFormWarningDialog. Clearing
+ // the delegate will allow form resubmission. Remove this workaround (clearing
+ // the delegate, once |check_for_repost| is supported).
+ web_state()->SetDelegate(nullptr);
+ ExecuteBlockAndWaitForLoad(action, ^{
+ navigation_manager()->GoForward();
+ });
+}
+
} // namespace web
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698