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

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

Issue 2879413002: Pass NavigationContext to WebStateImpl::OnNavigationStarted. (Closed)
Patch Set: Fixed tests 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 | « ios/chrome/browser/tabs/tab_unittest.mm ('k') | 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }; 102 };
103 103
104 // Tests successful navigation to a new page. 104 // Tests successful navigation to a new page.
105 TEST_F(StartAndFinishNavigationTest, NewPageNavigation) { 105 TEST_F(StartAndFinishNavigationTest, NewPageNavigation) {
106 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 106 const GURL url = HttpServer::MakeUrl("http://chromium.test");
107 std::map<GURL, std::string> responses; 107 std::map<GURL, std::string> responses;
108 responses[url] = "Chromium Test"; 108 responses[url] = "Chromium Test";
109 web::test::SetUpSimpleHttpServer(responses); 109 web::test::SetUpSimpleHttpServer(responses);
110 110
111 // Perform new page navigation. 111 // Perform new page navigation.
112 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_)); 112 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(url));
113 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 113 EXPECT_CALL(*observer_, DidFinishNavigation(_))
114 .WillOnce(VerifyNewPageContext(web_state(), url)); 114 .WillOnce(VerifyNewPageContext(web_state(), url));
115 LoadUrl(url); 115 LoadUrl(url);
116 } 116 }
117 117
118 // Tests user-initiated hash change. 118 // Tests user-initiated hash change.
119 TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) { 119 TEST_F(StartAndFinishNavigationTest, UserInitiatedHashChangeNavigation) {
120 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 120 const GURL url = HttpServer::MakeUrl("http://chromium.test");
121 std::map<GURL, std::string> responses; 121 std::map<GURL, std::string> responses;
122 responses[url] = "Chromium Test"; 122 responses[url] = "Chromium Test";
123 web::test::SetUpSimpleHttpServer(responses); 123 web::test::SetUpSimpleHttpServer(responses);
124 124
125 // Perform new page navigation. 125 // Perform new page navigation.
126 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_)); 126 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(url));
127 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 127 EXPECT_CALL(*observer_, DidFinishNavigation(_))
128 .WillOnce(VerifyNewPageContext(web_state(), url)); 128 .WillOnce(VerifyNewPageContext(web_state(), url));
129 LoadUrl(url); 129 LoadUrl(url);
130 130
131 // Perform same-page navigation. 131 // Perform same-page navigation.
132 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(_)); 133 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(hash_url));
134 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 134 EXPECT_CALL(*observer_, DidFinishNavigation(_))
135 .WillOnce(VerifySameDocumentContext(web_state(), hash_url)); 135 .WillOnce(VerifySameDocumentContext(web_state(), hash_url));
136 LoadUrl(hash_url); 136 LoadUrl(hash_url);
137 137
138 // Perform same-page navigation by going back. 138 // Perform same-page navigation by going back.
139 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_)); 139 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(url));
140 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 140 EXPECT_CALL(*observer_, DidFinishNavigation(_))
141 .WillOnce(VerifySameDocumentContext(web_state(), url)); 141 .WillOnce(VerifySameDocumentContext(web_state(), url));
142 ExecuteBlockAndWaitForLoad(url, ^{ 142 ExecuteBlockAndWaitForLoad(url, ^{
143 navigation_manager()->GoBack(); 143 navigation_manager()->GoBack();
144 }); 144 });
145 } 145 }
146 146
147 // Tests renderer-initiated hash change. 147 // Tests renderer-initiated hash change.
148 TEST_F(StartAndFinishNavigationTest, RendererInitiatedHashChangeNavigation) { 148 TEST_F(StartAndFinishNavigationTest, RendererInitiatedHashChangeNavigation) {
149 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 149 const GURL url = HttpServer::MakeUrl("http://chromium.test");
150 std::map<GURL, std::string> responses; 150 std::map<GURL, std::string> responses;
151 responses[url] = "Chromium Test"; 151 responses[url] = "Chromium Test";
152 web::test::SetUpSimpleHttpServer(responses); 152 web::test::SetUpSimpleHttpServer(responses);
153 153
154 // Perform new page navigation. 154 // Perform new page navigation.
155 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_)); 155 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(url));
156 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 156 EXPECT_CALL(*observer_, DidFinishNavigation(_))
157 .WillOnce(VerifyNewPageContext(web_state(), url)); 157 .WillOnce(VerifyNewPageContext(web_state(), url));
158 LoadUrl(url); 158 LoadUrl(url);
159 159
160 // Perform same-page navigation using JavaScript. 160 // Perform same-page navigation using JavaScript.
161 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(_)); 162 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(hash_url));
163 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 163 EXPECT_CALL(*observer_, DidFinishNavigation(_))
164 .WillOnce(VerifySameDocumentContext(web_state(), hash_url)); 164 .WillOnce(VerifySameDocumentContext(web_state(), hash_url));
165 ExecuteJavaScript(@"window.location.hash = '#1'"); 165 ExecuteJavaScript(@"window.location.hash = '#1'");
166 } 166 }
167 167
168 // Tests state change. 168 // Tests state change.
169 TEST_F(StartAndFinishNavigationTest, StateNavigation) { 169 TEST_F(StartAndFinishNavigationTest, StateNavigation) {
170 const GURL url = HttpServer::MakeUrl("http://chromium.test"); 170 const GURL url = HttpServer::MakeUrl("http://chromium.test");
171 std::map<GURL, std::string> responses; 171 std::map<GURL, std::string> responses;
172 responses[url] = "Chromium Test"; 172 responses[url] = "Chromium Test";
173 web::test::SetUpSimpleHttpServer(responses); 173 web::test::SetUpSimpleHttpServer(responses);
174 174
175 // Perform new page navigation. 175 // Perform new page navigation.
176 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_)); 176 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(url));
177 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 177 EXPECT_CALL(*observer_, DidFinishNavigation(_))
178 .WillOnce(VerifyNewPageContext(web_state(), url)); 178 .WillOnce(VerifyNewPageContext(web_state(), url));
179 LoadUrl(url); 179 LoadUrl(url);
180 180
181 // Perform push state using JavaScript. 181 // Perform push state using JavaScript.
182 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(_)); 183 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(push_url));
184 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 184 EXPECT_CALL(*observer_, DidFinishNavigation(_))
185 .WillOnce(VerifySameDocumentContext(web_state(), push_url)); 185 .WillOnce(VerifySameDocumentContext(web_state(), push_url));
186 ExecuteJavaScript(@"window.history.pushState('', 'Test', 'test.html')"); 186 ExecuteJavaScript(@"window.history.pushState('', 'Test', 'test.html')");
187 187
188 // Perform replace state using JavaScript. 188 // Perform replace state using JavaScript.
189 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(_)); 190 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(replace_url));
191 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 191 EXPECT_CALL(*observer_, DidFinishNavigation(_))
192 .WillOnce(VerifySameDocumentContext(web_state(), replace_url)); 192 .WillOnce(VerifySameDocumentContext(web_state(), replace_url));
193 ExecuteJavaScript(@"window.history.replaceState('', 'Test', '1.html')"); 193 ExecuteJavaScript(@"window.history.replaceState('', 'Test', '1.html')");
194 } 194 }
195 195
196 // Tests native content navigation. 196 // Tests native content navigation.
197 TEST_F(StartAndFinishNavigationTest, NativeContentNavigation) { 197 TEST_F(StartAndFinishNavigationTest, NativeContentNavigation) {
198 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); 198 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
199 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(_)); 199 EXPECT_CALL(*observer_, ProvisionalNavigationStarted(url));
200 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 200 EXPECT_CALL(*observer_, DidFinishNavigation(_))
201 .WillOnce(VerifyNewNativePageContext(web_state(), url)); 201 .WillOnce(VerifyNewNativePageContext(web_state(), url));
202 LoadUrl(url); 202 LoadUrl(url);
203 } 203 }
204 204
205 } // namespace web 205 } // namespace web
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_unittest.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698