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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2759483002: Revert of Cleaned up old navigation code that did not use pending navigation item. (Closed)
Patch Set: Created 3 years, 9 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/web/web_state/ui/crw_web_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #import "ios/web/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #import "testing/gtest_mac.h" 43 #import "testing/gtest_mac.h"
44 #include "third_party/ocmock/OCMock/OCMock.h" 44 #include "third_party/ocmock/OCMock/OCMock.h"
45 #include "third_party/ocmock/gtest_support.h" 45 #include "third_party/ocmock/gtest_support.h"
46 #include "third_party/ocmock/ocmock_extensions.h" 46 #include "third_party/ocmock/ocmock_extensions.h"
47 #import "ui/base/test/ios/ui_view_test_utils.h" 47 #import "ui/base/test/ios/ui_view_test_utils.h"
48 48
49 using web::NavigationManagerImpl; 49 using web::NavigationManagerImpl;
50 50
51 @interface CRWWebController (PrivateAPI) 51 @interface CRWWebController (PrivateAPI)
52 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; 52 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState;
53 - (GURL)URLForHistoryNavigationToItem:(web::NavigationItem*)toItem
54 previousURL:(const GURL&)previousURL;
53 @end 55 @end
54 56
55 @interface CountingObserver : NSObject<CRWWebControllerObserver> 57 @interface CountingObserver : NSObject<CRWWebControllerObserver>
56 58
57 @property(nonatomic, readonly) int pageLoadedCount; 59 @property(nonatomic, readonly) int pageLoadedCount;
58 @end 60 @end
59 61
60 @implementation CountingObserver 62 @implementation CountingObserver
61 @synthesize pageLoadedCount = _pageLoadedCount; 63 @synthesize pageLoadedCount = _pageLoadedCount;
62 64
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 context:nullptr]; 163 context:nullptr];
162 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY]; 164 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY];
163 165
164 return result; 166 return result;
165 } 167 }
166 168
167 base::scoped_nsobject<UIScrollView> scroll_view_; 169 base::scoped_nsobject<UIScrollView> scroll_view_;
168 base::scoped_nsobject<id> mock_web_view_; 170 base::scoped_nsobject<id> mock_web_view_;
169 }; 171 };
170 172
173 #define MAKE_URL(url_string) GURL([url_string UTF8String])
174
175 TEST_F(CRWWebControllerTest, UrlForHistoryNavigation) {
176 NSArray* urls_without_fragments = @[
177 @"http://one.com", @"http://two.com/", @"http://three.com/bar",
178 @"http://four.com/bar/", @"five", @"/six", @"/seven/", @""
179 ];
180
181 NSArray* fragments = @[ @"#", @"#bar" ];
182 NSMutableArray* urls_with_fragments = [NSMutableArray array];
183 for (NSString* url in urls_without_fragments) {
184 for (NSString* fragment in fragments) {
185 [urls_with_fragments addObject:[url stringByAppendingString:fragment]];
186 }
187 }
188
189 GURL previous_url;
190 web::NavigationItemImpl to_item;
191
192 // No start fragment: the end url is never changed.
193 for (NSString* start in urls_without_fragments) {
194 for (NSString* end in urls_with_fragments) {
195 previous_url = MAKE_URL(start);
196 to_item.SetURL(MAKE_URL(end));
197 EXPECT_EQ(MAKE_URL(end),
198 [web_controller() URLForHistoryNavigationToItem:&to_item
199 previousURL:previous_url]);
200 }
201 }
202 // Both contain fragments: the end url is never changed.
203 for (NSString* start in urls_with_fragments) {
204 for (NSString* end in urls_with_fragments) {
205 previous_url = MAKE_URL(start);
206 to_item.SetURL(MAKE_URL(end));
207 EXPECT_EQ(MAKE_URL(end),
208 [web_controller() URLForHistoryNavigationToItem:&to_item
209 previousURL:previous_url]);
210 }
211 }
212 for (unsigned start_index = 0; start_index < urls_with_fragments.count;
213 ++start_index) {
214 NSString* start = urls_with_fragments[start_index];
215 for (unsigned end_index = 0; end_index < urls_without_fragments.count;
216 ++end_index) {
217 NSString* end = urls_without_fragments[end_index];
218 previous_url = MAKE_URL(start);
219 if (start_index / 2 != end_index) {
220 // The URLs have nothing in common, they are left untouched.
221 to_item.SetURL(MAKE_URL(end));
222 EXPECT_EQ(
223 MAKE_URL(end),
224 [web_controller() URLForHistoryNavigationToItem:&to_item
225 previousURL:previous_url]);
226 } else {
227 // Start contains a fragment and matches end: An empty fragment is
228 // added.
229 to_item.SetURL(MAKE_URL(end));
230 EXPECT_EQ(
231 MAKE_URL([end stringByAppendingString:@"#"]),
232 [web_controller() URLForHistoryNavigationToItem:&to_item
233 previousURL:previous_url]);
234 }
235 }
236 }
237 }
238
171 // Tests that AllowCertificateError is called with correct arguments if 239 // Tests that AllowCertificateError is called with correct arguments if
172 // WKWebView fails to load a page with bad SSL cert. 240 // WKWebView fails to load a page with bad SSL cert.
173 TEST_F(CRWWebControllerTest, SslCertError) { 241 TEST_F(CRWWebControllerTest, SslCertError) {
174 web::TestWebStateObserver observer(web_state()); 242 web::TestWebStateObserver observer(web_state());
175 ASSERT_FALSE(observer.did_change_visible_security_state_info()); 243 ASSERT_FALSE(observer.did_change_visible_security_state_info());
176 244
177 // Last arguments passed to AllowCertificateError must be in default state. 245 // Last arguments passed to AllowCertificateError must be in default state.
178 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); 246 ASSERT_FALSE(GetWebClient()->last_cert_error_code());
179 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); 247 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid());
180 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); 248 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status);
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 web::TestWebStateObserver* observer_ptr = &observer; 955 web::TestWebStateObserver* observer_ptr = &observer;
888 web::SimulateWKWebViewCrash(webView_); 956 web::SimulateWKWebViewCrash(webView_);
889 base::test::ios::WaitUntilCondition(^bool() { 957 base::test::ios::WaitUntilCondition(^bool() {
890 return observer_ptr->render_process_gone_info(); 958 return observer_ptr->render_process_gone_info();
891 }); 959 });
892 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); 960 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state);
893 EXPECT_FALSE([web_controller() isViewAlive]); 961 EXPECT_FALSE([web_controller() isViewAlive]);
894 }; 962 };
895 963
896 } // namespace 964 } // namespace
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698