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 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 5 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
6 | 6 |
7 #import "base/mac/scoped_nsobject.h" | |
8 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
9 #include "ios/web/public/favicon_url.h" | 8 #include "ios/web/public/favicon_url.h" |
10 #import "ios/web/public/test/fakes/crw_test_web_state_observer.h" | 9 #import "ios/web/public/test/fakes/crw_test_web_state_observer.h" |
11 #import "ios/web/public/test/fakes/test_web_state.h" | 10 #import "ios/web/public/test/fakes/test_web_state.h" |
12 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 11 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
13 #import "ios/web/web_state/navigation_context_impl.h" | 12 #import "ios/web/web_state/navigation_context_impl.h" |
14 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
15 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
16 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
17 namespace web { | 20 namespace web { |
18 namespace { | 21 namespace { |
19 const char kRawResponseHeaders[] = | 22 const char kRawResponseHeaders[] = |
20 "HTTP/1.1 200 OK\0" | 23 "HTTP/1.1 200 OK\0" |
21 "Content-Length: 450\0" | 24 "Content-Length: 450\0" |
22 "Connection: keep-alive\0"; | 25 "Connection: keep-alive\0"; |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 // Test fixture to test WebStateObserverBridge class. | 28 // Test fixture to test WebStateObserverBridge class. |
26 class WebStateObserverBridgeTest : public PlatformTest { | 29 class WebStateObserverBridgeTest : public PlatformTest { |
27 protected: | 30 protected: |
28 WebStateObserverBridgeTest() | 31 WebStateObserverBridgeTest() |
29 : observer_([[CRWTestWebStateObserver alloc] init]), | 32 : observer_([[CRWTestWebStateObserver alloc] init]), |
30 bridge_(base::MakeUnique<WebStateObserverBridge>(&test_web_state_, | 33 bridge_(base::MakeUnique<WebStateObserverBridge>(&test_web_state_, |
31 observer_.get())), | 34 observer_)), |
32 response_headers_(new net::HttpResponseHeaders( | 35 response_headers_(new net::HttpResponseHeaders( |
33 std::string(kRawResponseHeaders, sizeof(kRawResponseHeaders)))) {} | 36 std::string(kRawResponseHeaders, sizeof(kRawResponseHeaders)))) {} |
34 | 37 |
35 web::TestWebState test_web_state_; | 38 web::TestWebState test_web_state_; |
36 base::scoped_nsobject<CRWTestWebStateObserver> observer_; | 39 CRWTestWebStateObserver* observer_; |
37 std::unique_ptr<WebStateObserverBridge> bridge_; | 40 std::unique_ptr<WebStateObserverBridge> bridge_; |
38 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 41 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
39 }; | 42 }; |
40 | 43 |
41 // Tests |webState:didPruneNavigationItemsWithCount:| forwarding. | 44 // Tests |webState:didPruneNavigationItemsWithCount:| forwarding. |
42 TEST_F(WebStateObserverBridgeTest, NavigationItemsPruned) { | 45 TEST_F(WebStateObserverBridgeTest, NavigationItemsPruned) { |
43 ASSERT_FALSE([observer_ navigationItemsPrunedInfo]); | 46 ASSERT_FALSE([observer_ navigationItemsPrunedInfo]); |
44 | 47 |
45 bridge_->NavigationItemsPruned(1); | 48 bridge_->NavigationItemsPruned(1); |
46 | 49 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // Tests |webState:webStateDidStartLoading:| forwarding. | 278 // Tests |webState:webStateDidStartLoading:| forwarding. |
276 TEST_F(WebStateObserverBridgeTest, DidStartLoading) { | 279 TEST_F(WebStateObserverBridgeTest, DidStartLoading) { |
277 ASSERT_FALSE([observer_ startLoadingInfo]); | 280 ASSERT_FALSE([observer_ startLoadingInfo]); |
278 | 281 |
279 bridge_->DidStartLoading(); | 282 bridge_->DidStartLoading(); |
280 ASSERT_TRUE([observer_ startLoadingInfo]); | 283 ASSERT_TRUE([observer_ startLoadingInfo]); |
281 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state); | 284 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state); |
282 } | 285 } |
283 | 286 |
284 } // namespace web | 287 } // namespace web |
OLD | NEW |