| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/origin_util.h" | 5 #import "ios/web/public/origin_util.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import "base/mac/objc_property_releaser.h" | |
| 10 #import "base/mac/scoped_nsobject.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 13 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 14 // WKSecurityOrigin can not be manually created, hence stub is needed. | 16 // WKSecurityOrigin can not be manually created, hence stub is needed. |
| 15 @interface WKSecurityOriginStub : NSObject | 17 @interface WKSecurityOriginStub : NSObject |
| 16 // Methods from WKSecurityOrigin class. | 18 // Methods from WKSecurityOrigin class. |
| 17 @property(nonatomic, copy) NSString* protocol; | 19 @property(nonatomic, copy) NSString* protocol; |
| 18 @property(nonatomic, copy) NSString* host; | 20 @property(nonatomic, copy) NSString* host; |
| 19 @property(nonatomic) NSInteger port; | 21 @property(nonatomic) NSInteger port; |
| 20 @end | 22 @end |
| 21 | 23 |
| 22 @implementation WKSecurityOriginStub { | 24 @implementation WKSecurityOriginStub |
| 23 base::mac::ObjCPropertyReleaser _propertyReleaser; | |
| 24 } | |
| 25 @synthesize protocol = _protocol; | 25 @synthesize protocol = _protocol; |
| 26 @synthesize host = _host; | 26 @synthesize host = _host; |
| 27 @synthesize port = _port; | 27 @synthesize port = _port; |
| 28 - (instancetype)init { | |
| 29 if (self = [super init]) { | |
| 30 _propertyReleaser.Init(self, [WKSecurityOriginStub class]); | |
| 31 } | |
| 32 return self; | |
| 33 } | |
| 34 @end | 28 @end |
| 35 | 29 |
| 36 namespace web { | 30 namespace web { |
| 37 | 31 |
| 38 // Tests calling GURLOriginWithWKSecurityOrigin with nil. | 32 // Tests calling GURLOriginWithWKSecurityOrigin with nil. |
| 39 TEST(OriginUtilTest, GURLOriginWithNilWKSecurityOrigin) { | 33 TEST(OriginUtilTest, GURLOriginWithNilWKSecurityOrigin) { |
| 40 GURL url(GURLOriginWithWKSecurityOrigin(nil)); | 34 GURL url(GURLOriginWithWKSecurityOrigin(nil)); |
| 41 | 35 |
| 42 EXPECT_FALSE(url.is_valid()); | 36 EXPECT_FALSE(url.is_valid()); |
| 43 EXPECT_TRUE(url.spec().empty()); | 37 EXPECT_TRUE(url.spec().empty()); |
| 44 } | 38 } |
| 45 | 39 |
| 46 // Tests calling GURLOriginWithWKSecurityOrigin with valid origin. | 40 // Tests calling GURLOriginWithWKSecurityOrigin with valid origin. |
| 47 TEST(OriginUtilTest, GURLOriginWithValidWKSecurityOrigin) { | 41 TEST(OriginUtilTest, GURLOriginWithValidWKSecurityOrigin) { |
| 48 base::scoped_nsobject<WKSecurityOriginStub> origin( | 42 WKSecurityOriginStub* origin = [[WKSecurityOriginStub alloc] init]; |
| 49 [[WKSecurityOriginStub alloc] init]); | |
| 50 [origin setProtocol:@"http"]; | 43 [origin setProtocol:@"http"]; |
| 51 [origin setHost:@"chromium.org"]; | 44 [origin setHost:@"chromium.org"]; |
| 52 [origin setPort:80]; | 45 [origin setPort:80]; |
| 53 | 46 |
| 54 GURL url(GURLOriginWithWKSecurityOrigin( | 47 GURL url( |
| 55 static_cast<WKSecurityOrigin*>(origin.get()))); | 48 GURLOriginWithWKSecurityOrigin(static_cast<WKSecurityOrigin*>(origin))); |
| 56 EXPECT_EQ("http://chromium.org/", url.spec()); | 49 EXPECT_EQ("http://chromium.org/", url.spec()); |
| 57 EXPECT_TRUE(url.port().empty()); | 50 EXPECT_TRUE(url.port().empty()); |
| 58 } | 51 } |
| 59 | 52 |
| 60 } // namespace web | 53 } // namespace web |
| OLD | NEW |