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

Unified Diff: ios/web/web_state/context_menu_params_unittest.mm

Issue 2640433002: Clean the new CRWContextMenuController (Closed)
Patch Set: feedback Created 3 years, 11 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
Index: ios/web/web_state/context_menu_params_unittest.mm
diff --git a/ios/web/web_state/context_menu_params_unittest.mm b/ios/web/web_state/context_menu_params_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..bf72c8da372ba2d548a9d602fe9eb016692e40f6
--- /dev/null
+++ b/ios/web/web_state/context_menu_params_unittest.mm
@@ -0,0 +1,98 @@
+// Copyright 2017 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/web_state/context_menu_params.h"
+
+#include "base/strings/sys_string_conversions.h"
+#include "components/url_formatter/url_formatter.h"
+#include "ios/web/public/referrer_util.h"
+#import "net/base/mac/url_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#import "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+namespace {
+// Text values for the tapped element triggering the context menu.
+const char* kLinkUrl = "http://link.url/";
+const char* kSrcUrl = "http://src.url/";
+const char* kTitle = "title";
+const char* kReferrerPolicy = "always";
+const char* kLinkText = "link text";
+const char* kJavaScriptLinkUrl = "javascript://src.url/";
+const char* kDataUrl = "data://foo.bar/";
+}
+
+// Test fixture for error translation testing.
+typedef PlatformTest ContextMenuParamsTest;
+
+// Test the empty contructor.
Eugene But (OOO till 7-30) 2017/01/17 18:12:48 nit: s/Test/Tests Same comment for other places
Olivier 2017/01/18 08:55:54 Done.
+TEST_F(ContextMenuParamsTest, EmptyParams) {
+ web::ContextMenuParams params;
+ EXPECT_EQ(params.menu_title.get(), nil);
+ EXPECT_FALSE(params.link_url.is_valid());
+ EXPECT_FALSE(params.src_url.is_valid());
+ EXPECT_EQ(params.referrer_policy, web::ReferrerPolicyDefault);
+ EXPECT_EQ(params.view.get(), nil);
+ EXPECT_TRUE(CGPointEqualToPoint(params.location, CGPointZero));
+ EXPECT_EQ(params.link_text.get(), nil);
+}
+
+// Test the the parsing of the element NSDictionary.
+TEST_F(ContextMenuParamsTest, DictionaryConstructorTest) {
+ web::ContextMenuParams params(@{
+ @"href" : @(kLinkUrl),
+ @"src" : @(kSrcUrl),
+ @"title" : @(kTitle),
+ @"referrerPolicy" : @(kReferrerPolicy),
+ @"innerText" : @(kLinkText),
+ });
+
+ EXPECT_NSEQ(params.menu_title.get(), @(kTitle));
+ EXPECT_EQ(params.link_url, GURL(kLinkUrl));
+ EXPECT_EQ(params.src_url, GURL(kSrcUrl));
+ EXPECT_NSEQ(params.link_text.get(), @(kLinkText));
+ EXPECT_EQ(params.referrer_policy,
+ web::ReferrerPolicyFromString(kReferrerPolicy));
+
+ EXPECT_EQ(params.view.get(), nil);
+ EXPECT_TRUE(CGPointEqualToPoint(params.location, CGPointZero));
+}
+
+// Test title is set as the formatted URL there is no title.
+TEST_F(ContextMenuParamsTest, DictionaryConstructorTestNoTitle) {
+ web::ContextMenuParams params(@{
+ @"href" : @(kLinkUrl),
+ });
+ base::string16 urlText = url_formatter::FormatUrl(GURL(kLinkUrl));
+ NSString* title = base::SysUTF16ToNSString(urlText);
+
+ EXPECT_NSEQ(params.menu_title.get(), title);
+}
+
+// Test title is set to "JavaScript" if there is no title and "href" links to
+// JavaScript URL.
+TEST_F(ContextMenuParamsTest, DictionaryConstructorTestJavascriptTitle) {
+ web::ContextMenuParams params(@{
+ @"href" : @(kJavaScriptLinkUrl),
+ });
+ EXPECT_NSEQ(params.menu_title.get(), @"JavaScript");
+}
+
+// Test title is set to |src_url| if there is no title.
+TEST_F(ContextMenuParamsTest, DictionaryConstructorTestSrcTitle) {
+ web::ContextMenuParams params(@{
+ @"src" : @(kSrcUrl),
+ });
+ EXPECT_EQ(params.src_url, GURL(kSrcUrl));
+ EXPECT_NSEQ(params.menu_title.get(), @(kSrcUrl));
+}
+
+// Test title is set to nil if there is no title and src is a data URL.
+TEST_F(ContextMenuParamsTest, DictionaryConstructorTestDataTitle) {
+ web::ContextMenuParams params(@{
+ @"src" : @(kDataUrl),
+ });
+ EXPECT_EQ(params.src_url, GURL(kDataUrl));
+ EXPECT_NSEQ(params.menu_title.get(), nil);
+}

Powered by Google App Engine
This is Rietveld 408576698