OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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/intents/web_intents_util.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/utf_string_conversions.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace web_intents { | |
13 namespace { | |
14 | |
15 bool IsRecognized(const std::string& value) { | |
16 return web_intents::IsRecognizedAction(ASCIIToUTF16(value)); | |
17 } | |
18 | |
19 ActionId ToAction(const std::string& value) { | |
20 return web_intents::ToActionId(ASCIIToUTF16(value)); | |
21 } | |
22 | |
23 bool TypesMatch(const std::string& a, const std::string& b) { | |
24 return MimeTypesMatch(ASCIIToUTF16(a), ASCIIToUTF16(b)); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 TEST(WebIntentsUtilTest, IsRecognizedAction) { | |
30 EXPECT_TRUE(IsRecognized(kActionEdit)); | |
31 EXPECT_FALSE(IsRecognized("http://webintents.org/eDit")); // case matters | |
32 EXPECT_TRUE(IsRecognized(kActionPick)); | |
33 EXPECT_TRUE(IsRecognized(kActionSave)); | |
34 EXPECT_TRUE(IsRecognized(kActionShare)); | |
35 EXPECT_TRUE(IsRecognized(kActionSubscribe)); | |
36 EXPECT_TRUE(IsRecognized(kActionView)); | |
37 } | |
38 | |
39 TEST(WebIntentsUtilTest, IsRecognizedActionFailure) { | |
40 EXPECT_FALSE(IsRecognized(std::string(kActionPick) + "lezooka")); | |
41 EXPECT_FALSE(IsRecognized("Chrome LAX")); | |
42 EXPECT_FALSE(IsRecognized("_zoom ")); | |
43 EXPECT_FALSE(IsRecognized(" ")); | |
44 EXPECT_FALSE(IsRecognized("")); | |
45 } | |
46 | |
47 TEST(WebIntentsUtilTest, ToActionId) { | |
48 EXPECT_EQ(ACTION_ID_EDIT, ToAction(kActionEdit)); | |
49 EXPECT_EQ(ACTION_ID_PICK, ToAction(kActionPick)); | |
50 EXPECT_EQ(ACTION_ID_SAVE, ToAction(kActionSave)); | |
51 EXPECT_EQ(ACTION_ID_SHARE, ToAction(kActionShare)); | |
52 EXPECT_EQ(ACTION_ID_SUBSCRIBE, ToAction(kActionSubscribe)); | |
53 EXPECT_EQ(ACTION_ID_VIEW, ToAction(kActionView)); | |
54 } | |
55 | |
56 TEST(WebIntentsUtilTest, MimeTypesMatchLiteral) { | |
57 EXPECT_TRUE(TypesMatch("image/png", "image/png")); | |
58 | |
59 EXPECT_FALSE(TypesMatch(" image/png", "image/png")); | |
60 EXPECT_FALSE(TypesMatch("image/png", " image/png")); | |
61 EXPECT_FALSE(TypesMatch("image/png ", "image/png")); | |
62 EXPECT_FALSE(TypesMatch("image/png", "image/png ")); | |
63 EXPECT_FALSE(TypesMatch("image/jpg", "image/png")); | |
64 EXPECT_FALSE(TypesMatch("image/png", "image/jpg")); | |
65 } | |
66 | |
67 TEST(WebIntentsUtilTest, MimeTypesMatchWildCards) { | |
68 EXPECT_TRUE(TypesMatch("*", "*")); | |
69 EXPECT_TRUE(TypesMatch("*", "*/*")); | |
70 EXPECT_TRUE(TypesMatch("*/*", "*")); | |
71 EXPECT_TRUE(TypesMatch("*/*", "*/*")); | |
72 EXPECT_TRUE(TypesMatch("*", "image/png")); | |
73 EXPECT_TRUE(TypesMatch("image/png", "*")); | |
74 EXPECT_TRUE(TypesMatch("*/*", "image/png")); | |
75 EXPECT_TRUE(TypesMatch("image/png", "*/*")); | |
76 | |
77 EXPECT_FALSE(TypesMatch(" */*", "image/png")); | |
78 EXPECT_FALSE(TypesMatch("*/* ", "image/png")); | |
79 EXPECT_FALSE(TypesMatch("**", "image/png")); | |
80 } | |
81 | |
82 TEST(WebIntentsUtilTest, MimeTypesMatchParameters) { | |
83 EXPECT_TRUE(TypesMatch("*", "video/*;single=true")); | |
84 EXPECT_TRUE(TypesMatch("*/*", "video/mpg;single=true")); | |
85 EXPECT_TRUE(TypesMatch("video/*", "video/mpg;single=true")); | |
86 EXPECT_TRUE(TypesMatch("video/mpg", "video/mpg;single=true")); | |
87 EXPECT_TRUE(TypesMatch("video/mpg;single=true", "video/mpg;single=true")); | |
88 EXPECT_TRUE(TypesMatch("video/mpg;a=b;single=true", | |
89 "video/mpg;single=true;a=b")); | |
90 EXPECT_FALSE(TypesMatch("video/mpg;a=b;single=true", | |
91 "video/mpg;single=false;a=b")); | |
92 EXPECT_FALSE(TypesMatch("video/mpg;single=true", "video/mpg;single=false")); | |
93 } | |
94 | |
95 } // namepsace web_intents | |
OLD | NEW |