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

Unified Diff: ios/web/public/origin_util_unittest.mm

Issue 1919473003: [ios Mojo] Added util function to convert WKSecurityOrigin to GURL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/public/origin_util.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/public/origin_util_unittest.mm
diff --git a/ios/web/public/origin_util_unittest.mm b/ios/web/public/origin_util_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..c79786488018fd126fc922f57f7314bc41b2edb4
--- /dev/null
+++ b/ios/web/public/origin_util_unittest.mm
@@ -0,0 +1,60 @@
+// 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;
+@end
+
+@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;
+}
+@end
+
+namespace web {
+
+// Tests calling GURLOriginWithWKSecurityOrigin with nil.
+TEST(OriginUtilTest, GURLOriginWithNilWKSecurityOrigin) {
+ GURL url(GURLOriginWithWKSecurityOrigin(nil));
+
+ EXPECT_FALSE(url.is_valid());
+ EXPECT_TRUE(url.spec().empty());
+}
+
+// Tests calling GURLOriginWithWKSecurityOrigin with valid origin.
+TEST(OriginUtilTest, GURLOriginWithValidWKSecurityOrigin) {
+ base::scoped_nsobject<WKSecurityOriginStub> origin(
+ [[WKSecurityOriginStub alloc] init]);
+ [origin setProtocol:@"http"];
+ [origin setHost:@"chromium.org"];
+ [origin setPort:80];
+
+ GURL url(GURLOriginWithWKSecurityOrigin(
+ static_cast<WKSecurityOrigin*>(origin.get())));
+ EXPECT_EQ("http://chromium.org/", url.spec());
+ EXPECT_TRUE(url.port().empty());
+}
+
+} // namespace web
« no previous file with comments | « ios/web/public/origin_util.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698