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

Side by Side Diff: ios/web/web_state/navigation_callbacks_inttest.mm

Issue 2873023002: Call WebStateObserver::ProvisionalNavigationStarted for state navigations (Closed)
Patch Set: Rebased 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "ios/web/public/navigation_item.h" 9 #import "ios/web/public/navigation_item.h"
10 #import "ios/web/public/navigation_manager.h" 10 #import "ios/web/public/navigation_manager.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 NavigationItem* item = navigation_manager->GetLastCommittedItem(); 74 NavigationItem* item = navigation_manager->GetLastCommittedItem();
75 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); 75 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
76 EXPECT_EQ(url, item->GetURL()); 76 EXPECT_EQ(url, item->GetURL());
77 } 77 }
78 78
79 // Mocks DidFinishNavigation navigation callback. 79 // Mocks DidFinishNavigation navigation callback.
80 class WebStateObserverMock : public WebStateObserver { 80 class WebStateObserverMock : public WebStateObserver {
81 public: 81 public:
82 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {} 82 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {}
83 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context)); 83 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context));
84 MOCK_METHOD1(ProvisionalNavigationStarted, void(const GURL& url));
84 }; 85 };
85 86
86 } // namespace 87 } // namespace
87 88
88 using test::HttpServer; 89 using test::HttpServer;
89 using testing::_; 90 using testing::_;
90 91
91 // Test fixture for WebStateDelegate::DidFinishNavigation integration tests. 92 // Test fixture for WebStateDelegate::ProvisionalNavigationStarted and
92 class DidFinishNavigationTest : public WebIntTest { 93 // WebStateDelegate::DidFinishNavigation integration tests.
94 class StartAndFinishNavigationTest : public WebIntTest {
93 void SetUp() override { 95 void SetUp() override {
94 WebIntTest::SetUp(); 96 WebIntTest::SetUp();
95 observer_ = base::MakeUnique<WebStateObserverMock>(web_state()); 97 observer_ = base::MakeUnique<WebStateObserverMock>(web_state());
96 } 98 }
97 99
98 protected: 100 protected:
99 std::unique_ptr<WebStateObserverMock> observer_; 101 std::unique_ptr<WebStateObserverMock> observer_;
100 }; 102 };
101 103
102 // Tests successful navigation to a new page. 104 // Tests successful navigation to a new page.
103 TEST_F(DidFinishNavigationTest, NewPageNavigation) { 105 TEST_F(StartAndFinishNavigationTest, NewPageNavigation) {
104 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 106 const GURL url = HttpServer::MakeUrl("http://chromium.test");
105 std::map<GURL, std::string> responses; 107 std::map<GURL, std::string> responses;
106 responses[url] = "Chromium Test"; 108 responses[url] = "Chromium Test";
107 web::test::SetUpSimpleHttpServer(responses); 109 web::test::SetUpSimpleHttpServer(responses);
108 110
109 // Perform new page navigation. 111 // Perform new page navigation.
112 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
110 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 113 EXPECT_CALL(*observer_, DidFinishNavigation(_))
111 .WillOnce(VerifyNewPageContext(web_state(), url)); 114 .WillOnce(VerifyNewPageContext(web_state(), url));
112 LoadUrl(url); 115 LoadUrl(url);
113 } 116 }
114 117
115 // Tests user-initiated hash change. 118 // Tests user-initiated hash change.
116 TEST_F(DidFinishNavigationTest, UserInitiatedHashChangeNavigation) { 119 TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
117 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 120 const GURL url = HttpServer::MakeUrl("http://chromium.test");
118 std::map<GURL, std::string> responses; 121 std::map<GURL, std::string> responses;
119 responses[url] = "Chromium Test"; 122 responses[url] = "Chromium Test";
120 web::test::SetUpSimpleHttpServer(responses); 123 web::test::SetUpSimpleHttpServer(responses);
121 124
122 // Perform new page navigation. 125 // Perform new page navigation.
126 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
123 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 127 EXPECT_CALL(*observer_, DidFinishNavigation(_))
124 .WillOnce(VerifyNewPageContext(web_state(), url)); 128 .WillOnce(VerifyNewPageContext(web_state(), url));
125 LoadUrl(url); 129 LoadUrl(url);
126 130
127 // Perform same-page navigation. 131 // Perform same-page navigation.
128 const GURL hash_url = HttpServer::MakeUrl("http://chromium.test#1"); 132 const GURL hash_url = HttpServer::MakeUrl("http://chromium.test#1");
133 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
129 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 134 EXPECT_CALL(*observer_, DidFinishNavigation(_))
130 .WillOnce(VerifySameDocumentContext(web_state(), hash_url)); 135 .WillOnce(VerifySameDocumentContext(web_state(), hash_url));
131 LoadUrl(hash_url); 136 LoadUrl(hash_url);
132 137
133 // Perform same-page navigation by going back. 138 // Perform same-page navigation by going back.
139 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
134 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 140 EXPECT_CALL(*observer_, DidFinishNavigation(_))
135 .WillOnce(VerifySameDocumentContext(web_state(), url)); 141 .WillOnce(VerifySameDocumentContext(web_state(), url));
136 ExecuteBlockAndWaitForLoad(url, ^{ 142 ExecuteBlockAndWaitForLoad(url, ^{
137 navigation_manager()->GoBack(); 143 navigation_manager()->GoBack();
138 }); 144 });
139 } 145 }
140 146
141 // Tests renderer-initiated hash change. 147 // Tests renderer-initiated hash change.
142 TEST_F(DidFinishNavigationTest, RendererInitiatedHashChangeNavigation) { 148 TEST_F(StartAndFinishNavigationTest, RendererInitiatedHashChangeNavigation) {
143 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 149 const GURL url = HttpServer::MakeUrl("http://chromium.test");
144 std::map<GURL, std::string> responses; 150 std::map<GURL, std::string> responses;
145 responses[url] = "Chromium Test"; 151 responses[url] = "Chromium Test";
146 web::test::SetUpSimpleHttpServer(responses); 152 web::test::SetUpSimpleHttpServer(responses);
147 153
148 // Perform new page navigation. 154 // Perform new page navigation.
155 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
149 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 156 EXPECT_CALL(*observer_, DidFinishNavigation(_))
150 .WillOnce(VerifyNewPageContext(web_state(), url)); 157 .WillOnce(VerifyNewPageContext(web_state(), url));
151 LoadUrl(url); 158 LoadUrl(url);
152 159
153 // Perform same-page navigation using JavaScript. 160 // Perform same-page navigation using JavaScript.
154 const GURL hash_url = HttpServer::MakeUrl("http://chromium.test#1"); 161 const GURL hash_url = HttpServer::MakeUrl("http://chromium.test#1");
162 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
155 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 163 EXPECT_CALL(*observer_, DidFinishNavigation(_))
156 .WillOnce(VerifySameDocumentContext(web_state(), hash_url)); 164 .WillOnce(VerifySameDocumentContext(web_state(), hash_url));
157 ExecuteJavaScript(@"window.location.hash = '#1'"); 165 ExecuteJavaScript(@"window.location.hash = '#1'");
158 } 166 }
159 167
160 // Tests state change. 168 // Tests state change.
161 TEST_F(DidFinishNavigationTest, StateNavigation) { 169 TEST_F(StartAndFinishNavigationTest, StateNavigation) {
162 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 170 const GURL url = HttpServer::MakeUrl("http://chromium.test");
163 std::map<GURL, std::string> responses; 171 std::map<GURL, std::string> responses;
164 responses[url] = "Chromium Test"; 172 responses[url] = "Chromium Test";
165 web::test::SetUpSimpleHttpServer(responses); 173 web::test::SetUpSimpleHttpServer(responses);
166 174
167 // Perform new page navigation. 175 // Perform new page navigation.
176 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
168 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 177 EXPECT_CALL(*observer_, DidFinishNavigation(_))
169 .WillOnce(VerifyNewPageContext(web_state(), url)); 178 .WillOnce(VerifyNewPageContext(web_state(), url));
170 LoadUrl(url); 179 LoadUrl(url);
171 180
172 // Perform push state using JavaScript. 181 // Perform push state using JavaScript.
173 const GURL push_url = HttpServer::MakeUrl("http://chromium.test/test.html"); 182 const GURL push_url = HttpServer::MakeUrl("http://chromium.test/test.html");
183 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
174 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 184 EXPECT_CALL(*observer_, DidFinishNavigation(_))
175 .WillOnce(VerifySameDocumentContext(web_state(), push_url)); 185 .WillOnce(VerifySameDocumentContext(web_state(), push_url));
176 ExecuteJavaScript(@"window.history.pushState('', 'Test', 'test.html')"); 186 ExecuteJavaScript(@"window.history.pushState('', 'Test', 'test.html')");
177 187
178 // Perform replace state using JavaScript. 188 // Perform replace state using JavaScript.
179 const GURL replace_url = HttpServer::MakeUrl("http://chromium.test/1.html"); 189 const GURL replace_url = HttpServer::MakeUrl("http://chromium.test/1.html");
190 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
180 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 191 EXPECT_CALL(*observer_, DidFinishNavigation(_))
181 .WillOnce(VerifySameDocumentContext(web_state(), replace_url)); 192 .WillOnce(VerifySameDocumentContext(web_state(), replace_url));
182 ExecuteJavaScript(@"window.history.replaceState('', 'Test', '1.html')"); 193 ExecuteJavaScript(@"window.history.replaceState('', 'Test', '1.html')");
183 } 194 }
184 195
185 // Tests native content navigation. 196 // Tests native content navigation.
186 TEST_F(DidFinishNavigationTest, NativeContentNavigation) { 197 TEST_F(StartAndFinishNavigationTest, NativeContentNavigation) {
187 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); 198 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
199 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_));
188 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 200 EXPECT_CALL(*observer_, DidFinishNavigation(_))
189 .WillOnce(VerifyNewNativePageContext(web_state(), url)); 201 .WillOnce(VerifyNewNativePageContext(web_state(), url));
190 LoadUrl(url); 202 LoadUrl(url);
191 } 203 }
192 204
193 } // namespace web 205 } // namespace web
OLDNEW
« 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