dfff70aac5ecf1f948e43b8f383e79d28c74fccf
[platform/framework/web/crosswalk.git] / src / chrome / browser / renderer_context_menu / context_menu_content_type_unittest.cc
1 // Copyright 2014 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 #include "chrome/browser/renderer_context_menu/context_menu_content_type.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
13
14
15 using extensions::MenuItem;
16
17 class ContextMenuContentTypeTest : public ChromeRenderViewHostTestHarness {
18  public:
19   static ContextMenuContentType* Create(
20       content::WebContents* web_contents,
21       content::ContextMenuParams& params) {
22     return new ContextMenuContentType(web_contents, params, true);
23   }
24 };
25
26 // Generates a ContextMenuParams that matches the specified contexts.
27 content::ContextMenuParams CreateParams(int contexts) {
28   content::ContextMenuParams rv;
29   rv.is_editable = false;
30   rv.media_type = blink::WebContextMenuData::MediaTypeNone;
31   rv.page_url = GURL("http://test.page/");
32
33   static const base::string16 selected_text = base::ASCIIToUTF16("sel");
34   if (contexts & MenuItem::SELECTION)
35     rv.selection_text = selected_text;
36
37   if (contexts & MenuItem::LINK) {
38     rv.link_url = GURL("http://test.link/");
39     rv.unfiltered_link_url = GURL("http://test.link/");
40   }
41
42   if (contexts & MenuItem::EDITABLE)
43     rv.is_editable = true;
44
45   if (contexts & MenuItem::IMAGE) {
46     rv.src_url = GURL("http://test.image/");
47     rv.media_type = blink::WebContextMenuData::MediaTypeImage;
48   }
49
50   if (contexts & MenuItem::VIDEO) {
51     rv.src_url = GURL("http://test.video/");
52     rv.media_type = blink::WebContextMenuData::MediaTypeVideo;
53   }
54
55   if (contexts & MenuItem::AUDIO) {
56     rv.src_url = GURL("http://test.audio/");
57     rv.media_type = blink::WebContextMenuData::MediaTypeAudio;
58   }
59
60   if (contexts & MenuItem::FRAME)
61     rv.frame_url = GURL("http://test.frame/");
62
63   return rv;
64 }
65
66 TEST_F(ContextMenuContentTypeTest, CheckTypes) {
67   {
68     content::ContextMenuParams params = CreateParams(MenuItem::LINK);
69     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
70                                                            params));
71     EXPECT_TRUE(content_type->SupportsGroup(
72                     ContextMenuContentType::ITEM_GROUP_LINK));
73     EXPECT_TRUE(content_type->SupportsGroup(
74                     ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION));
75     EXPECT_FALSE(content_type->SupportsGroup(
76                     ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION));
77   }
78
79   {
80     content::ContextMenuParams params = CreateParams(MenuItem::SELECTION);
81     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
82                                                            params));
83     EXPECT_FALSE(content_type->SupportsGroup(
84                     ContextMenuContentType::ITEM_GROUP_LINK));
85     EXPECT_TRUE(content_type->SupportsGroup(
86                     ContextMenuContentType::ITEM_GROUP_COPY));
87     EXPECT_FALSE(content_type->SupportsGroup(
88                     ContextMenuContentType::ITEM_GROUP_EDITABLE));
89     EXPECT_TRUE(content_type->SupportsGroup(
90                     ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER));
91   }
92
93   {
94     content::ContextMenuParams params = CreateParams(MenuItem::EDITABLE);
95     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
96                                                            params));
97     EXPECT_FALSE(content_type->SupportsGroup(
98                     ContextMenuContentType::ITEM_GROUP_LINK));
99     EXPECT_FALSE(content_type->SupportsGroup(
100                     ContextMenuContentType::ITEM_GROUP_COPY));
101     EXPECT_TRUE(content_type->SupportsGroup(
102                     ContextMenuContentType::ITEM_GROUP_EDITABLE));
103   }
104
105   {
106     content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
107     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
108                                                            params));
109     EXPECT_TRUE(content_type->SupportsGroup(
110                     ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE));
111     EXPECT_TRUE(content_type->SupportsGroup(
112                     ContextMenuContentType::ITEM_GROUP_SEARCHWEBFORIMAGE));
113     EXPECT_TRUE(content_type->SupportsGroup(
114                     ContextMenuContentType::ITEM_GROUP_PRINT));
115
116     EXPECT_FALSE(content_type->SupportsGroup(
117                     ContextMenuContentType::ITEM_GROUP_MEDIA_VIDEO));
118     EXPECT_FALSE(content_type->SupportsGroup(
119                     ContextMenuContentType::ITEM_GROUP_MEDIA_AUDIO));
120     EXPECT_FALSE(content_type->SupportsGroup(
121                     ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN));
122   }
123
124   {
125     content::ContextMenuParams params = CreateParams(MenuItem::VIDEO);
126     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
127                                                            params));
128     EXPECT_TRUE(content_type->SupportsGroup(
129                     ContextMenuContentType::ITEM_GROUP_MEDIA_VIDEO));
130
131     EXPECT_FALSE(content_type->SupportsGroup(
132                     ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE));
133     EXPECT_FALSE(content_type->SupportsGroup(
134                     ContextMenuContentType::ITEM_GROUP_MEDIA_AUDIO));
135     EXPECT_FALSE(content_type->SupportsGroup(
136                     ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN));
137   }
138
139   {
140     content::ContextMenuParams params = CreateParams(MenuItem::AUDIO);
141     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
142                                                            params));
143     EXPECT_TRUE(content_type->SupportsGroup(
144                     ContextMenuContentType::ITEM_GROUP_MEDIA_AUDIO));
145
146     EXPECT_FALSE(content_type->SupportsGroup(
147                     ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE));
148     EXPECT_FALSE(content_type->SupportsGroup(
149                     ContextMenuContentType::ITEM_GROUP_MEDIA_VIDEO));
150     EXPECT_FALSE(content_type->SupportsGroup(
151                     ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN));
152   }
153
154   {
155     content::ContextMenuParams params = CreateParams(MenuItem::FRAME);
156     scoped_ptr<ContextMenuContentType> content_type(Create(web_contents(),
157                                                            params));
158     EXPECT_TRUE(content_type->SupportsGroup(
159                     ContextMenuContentType::ITEM_GROUP_FRAME));
160     EXPECT_TRUE(content_type->SupportsGroup(
161                     ContextMenuContentType::ITEM_GROUP_PAGE));
162   }
163 }