blob: c79786488018fd126fc922f57f7314bc41b2edb4 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/public/origin_util.h"
#import <WebKit/WebKit.h>
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
// WKSecurityOrigin can not be manually created, hence stub is needed.
@interface WKSecurityOriginStub : NSObject
// Methods from WKSecurityOrigin class.
@property(nonatomic, copy) NSString* protocol;
@property(nonatomic, copy) NSString* host;
@property(nonatomic) NSInteger port;
@implementation WKSecurityOriginStub {
base::mac::ObjCPropertyReleaser _propertyReleaser;
@synthesize protocol = _protocol;
@synthesize host = _host;
@synthesize port = _port;
- (instancetype)init {
if (self = [super init]) {
_propertyReleaser.Init(self, [WKSecurityOriginStub class]);
return self;
namespace web {
// Tests calling GURLOriginWithWKSecurityOrigin with nil.
TEST(OriginUtilTest, GURLOriginWithNilWKSecurityOrigin) {
GURL url(GURLOriginWithWKSecurityOrigin(nil));
// Tests calling GURLOriginWithWKSecurityOrigin with valid origin.
TEST(OriginUtilTest, GURLOriginWithValidWKSecurityOrigin) {
base::scoped_nsobject<WKSecurityOriginStub> origin(
[[WKSecurityOriginStub alloc] init]);
[origin setProtocol:@"http"];
[origin setHost:@""];
[origin setPort:80];
GURL url(GURLOriginWithWKSecurityOrigin(
EXPECT_EQ("", url.spec());
} // namespace web