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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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/web_state/context_menu_params.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #include "components/url_formatter/url_formatter.h"
9 #include "ios/web/public/referrer_util.h"
10 #import "net/base/mac/url_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #import "testing/gtest_mac.h"
13 #include "testing/platform_test.h"
14
15 namespace {
16 // Text values for the tapped element triggering the context menu.
17 const char* kLinkUrl = "http://link.url/";
18 const char* kSrcUrl = "http://src.url/";
19 const char* kTitle = "title";
20 const char* kReferrerPolicy = "always";
21 const char* kLinkText = "link text";
22 const char* kJavaScriptLinkUrl = "javascript://src.url/";
23 const char* kDataUrl = "data://foo.bar/";
24 }
25
26 // Test fixture for error translation testing.
27 typedef PlatformTest ContextMenuParamsTest;
28
29 // 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.
30 TEST_F(ContextMenuParamsTest, EmptyParams) {
31 web::ContextMenuParams params;
32 EXPECT_EQ(params.menu_title.get(), nil);
33 EXPECT_FALSE(params.link_url.is_valid());
34 EXPECT_FALSE(params.src_url.is_valid());
35 EXPECT_EQ(params.referrer_policy, web::ReferrerPolicyDefault);
36 EXPECT_EQ(params.view.get(), nil);
37 EXPECT_TRUE(CGPointEqualToPoint(params.location, CGPointZero));
38 EXPECT_EQ(params.link_text.get(), nil);
39 }
40
41 // Test the the parsing of the element NSDictionary.
42 TEST_F(ContextMenuParamsTest, DictionaryConstructorTest) {
43 web::ContextMenuParams params(@{
44 @"href" : @(kLinkUrl),
45 @"src" : @(kSrcUrl),
46 @"title" : @(kTitle),
47 @"referrerPolicy" : @(kReferrerPolicy),
48 @"innerText" : @(kLinkText),
49 });
50
51 EXPECT_NSEQ(params.menu_title.get(), @(kTitle));
52 EXPECT_EQ(params.link_url, GURL(kLinkUrl));
53 EXPECT_EQ(params.src_url, GURL(kSrcUrl));
54 EXPECT_NSEQ(params.link_text.get(), @(kLinkText));
55 EXPECT_EQ(params.referrer_policy,
56 web::ReferrerPolicyFromString(kReferrerPolicy));
57
58 EXPECT_EQ(params.view.get(), nil);
59 EXPECT_TRUE(CGPointEqualToPoint(params.location, CGPointZero));
60 }
61
62 // Test title is set as the formatted URL there is no title.
63 TEST_F(ContextMenuParamsTest, DictionaryConstructorTestNoTitle) {
64 web::ContextMenuParams params(@{
65 @"href" : @(kLinkUrl),
66 });
67 base::string16 urlText = url_formatter::FormatUrl(GURL(kLinkUrl));
68 NSString* title = base::SysUTF16ToNSString(urlText);
69
70 EXPECT_NSEQ(params.menu_title.get(), title);
71 }
72
73 // Test title is set to "JavaScript" if there is no title and "href" links to
74 // JavaScript URL.
75 TEST_F(ContextMenuParamsTest, DictionaryConstructorTestJavascriptTitle) {
76 web::ContextMenuParams params(@{
77 @"href" : @(kJavaScriptLinkUrl),
78 });
79 EXPECT_NSEQ(params.menu_title.get(), @"JavaScript");
80 }
81
82 // Test title is set to |src_url| if there is no title.
83 TEST_F(ContextMenuParamsTest, DictionaryConstructorTestSrcTitle) {
84 web::ContextMenuParams params(@{
85 @"src" : @(kSrcUrl),
86 });
87 EXPECT_EQ(params.src_url, GURL(kSrcUrl));
88 EXPECT_NSEQ(params.menu_title.get(), @(kSrcUrl));
89 }
90
91 // Test title is set to nil if there is no title and src is a data URL.
92 TEST_F(ContextMenuParamsTest, DictionaryConstructorTestDataTitle) {
93 web::ContextMenuParams params(@{
94 @"src" : @(kDataUrl),
95 });
96 EXPECT_EQ(params.src_url, GURL(kDataUrl));
97 EXPECT_NSEQ(params.menu_title.get(), nil);
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698