OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/web/public/origin_util.h" |
| 6 |
| 7 #import <WebKit/WebKit.h> |
| 8 |
| 9 #include "base/mac/objc_property_releaser.h" |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 // WKSecurityOrigin can not be manually created, hence stub is needed. |
| 15 @interface WKSecurityOriginStub : NSObject |
| 16 // Methods from WKSecurityOrigin class. |
| 17 @property(nonatomic, copy) NSString* protocol; |
| 18 @property(nonatomic, copy) NSString* host; |
| 19 @property(nonatomic) NSInteger port; |
| 20 @end |
| 21 |
| 22 @implementation WKSecurityOriginStub { |
| 23 base::mac::ObjCPropertyReleaser _propertyReleaser; |
| 24 } |
| 25 @synthesize protocol = _protocol; |
| 26 @synthesize host = _host; |
| 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 |
| 35 |
| 36 namespace web { |
| 37 |
| 38 // Tests calling GURLOriginWithWKSecurityOrigin with nil. |
| 39 TEST(OriginUtilTest, GURLOriginWithNilWKSecurityOrigin) { |
| 40 GURL url(GURLOriginWithWKSecurityOrigin(nil)); |
| 41 |
| 42 EXPECT_FALSE(url.is_valid()); |
| 43 EXPECT_TRUE(url.spec().empty()); |
| 44 } |
| 45 |
| 46 // Tests calling GURLOriginWithWKSecurityOrigin with valid origin. |
| 47 TEST(OriginUtilTest, GURLOriginWithValidWKSecurityOrigin) { |
| 48 base::scoped_nsobject<WKSecurityOriginStub> origin( |
| 49 [[WKSecurityOriginStub alloc] init]); |
| 50 [origin setProtocol:@"http"]; |
| 51 [origin setHost:@"chromium.org"]; |
| 52 [origin setPort:80]; |
| 53 |
| 54 GURL url(GURLOriginWithWKSecurityOrigin( |
| 55 static_cast<WKSecurityOrigin*>(origin.get()))); |
| 56 EXPECT_EQ("http://chromium.org/", url.spec()); |
| 57 EXPECT_TRUE(url.port().empty()); |
| 58 } |
| 59 |
| 60 } // namespace web |
OLD | NEW |