| 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 "base/utf_string_conversions.h" |
| 6 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 7 #include "chrome/common/extensions/manifest_handler.h" |
| 8 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 9 #include "chrome/common/extensions/web_intents_handler.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "webkit/glue/web_intent_service_data.h" |
| 12 |
| 13 using extensions::Extension; |
| 14 using extensions::WebIntentsInfo; |
| 15 |
| 16 namespace errors = extension_manifest_errors; |
| 17 |
| 18 class WebIntentsManifestTest : public ExtensionManifestTest { |
| 19 virtual void SetUp() OVERRIDE { |
| 20 ExtensionManifestTest::SetUp(); |
| 21 extensions::ManifestHandler::Register(extension_manifest_keys::kIntents, |
| 22 new extensions::WebIntentsHandler); |
| 23 } |
| 24 }; |
| 25 |
| 26 TEST_F(WebIntentsManifestTest, WebIntents) { |
| 27 Testcase testcases[] = { |
| 28 Testcase("intent_invalid_1.json", errors::kInvalidIntents), |
| 29 Testcase("intent_invalid_2.json", errors::kInvalidIntent), |
| 30 Testcase("intent_invalid_3.json", errors::kInvalidIntentHref), |
| 31 Testcase("intent_invalid_4.json", errors::kInvalidIntentDisposition), |
| 32 Testcase("intent_invalid_5.json", errors::kInvalidIntentType), |
| 33 Testcase("intent_invalid_6.json", errors::kInvalidIntentTitle), |
| 34 Testcase("intent_invalid_packaged_app.json", errors::kCannotAccessPage), |
| 35 Testcase("intent_invalid_href_and_path.json", |
| 36 errors::kInvalidIntentHrefOldAndNewKey), |
| 37 Testcase("intent_invalid_multi_href.json", errors::kInvalidIntent) |
| 38 }; |
| 39 RunTestcases(testcases, arraysize(testcases), |
| 40 EXPECT_TYPE_ERROR); |
| 41 |
| 42 scoped_refptr<Extension> extension( |
| 43 LoadAndExpectSuccess("intent_valid.json")); |
| 44 ASSERT_TRUE(extension); |
| 45 |
| 46 ASSERT_EQ(1u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 47 EXPECT_EQ("image/png", |
| 48 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].type)); |
| 49 EXPECT_EQ("http://webintents.org/share", |
| 50 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].action)); |
| 51 EXPECT_EQ("chrome-extension", |
| 52 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.scheme()); |
| 53 EXPECT_EQ("/services/share", |
| 54 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.path()); |
| 55 EXPECT_EQ("Sample Sharing Intent", |
| 56 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].title)); |
| 57 EXPECT_EQ(webkit_glue::WebIntentServiceData::DISPOSITION_INLINE, |
| 58 WebIntentsInfo::GetIntentsServices(extension)[0].disposition); |
| 59 |
| 60 // Verify that optional fields are filled with defaults. |
| 61 extension = LoadAndExpectSuccess("intent_valid_minimal.json"); |
| 62 ASSERT_TRUE(extension); |
| 63 |
| 64 ASSERT_EQ(1u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 65 EXPECT_EQ("*", |
| 66 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].type)); |
| 67 EXPECT_EQ("http://webintents.org/share", |
| 68 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].action)); |
| 69 EXPECT_EQ("", |
| 70 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].title)); |
| 71 EXPECT_EQ(webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW, |
| 72 WebIntentsInfo::GetIntentsServices(extension)[0].disposition); |
| 73 |
| 74 // Make sure we support href instead of path. |
| 75 extension = LoadAndExpectSuccess("intent_valid_using_href.json"); |
| 76 ASSERT_TRUE(extension); |
| 77 |
| 78 ASSERT_EQ(1u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 79 EXPECT_EQ("/services/share", |
| 80 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.path()); |
| 81 } |
| 82 |
| 83 TEST_F(WebIntentsManifestTest, WebIntentsWithMultipleMimeTypes) { |
| 84 scoped_refptr<Extension> extension( |
| 85 LoadAndExpectSuccess("intent_valid_multitype.json")); |
| 86 ASSERT_TRUE(extension); |
| 87 |
| 88 ASSERT_EQ(2u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 89 |
| 90 // One registration with multiple types generates a separate service for |
| 91 // each MIME type. |
| 92 for (int i = 0; i < 2; ++i) { |
| 93 EXPECT_EQ("http://webintents.org/share", |
| 94 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[i].action)); |
| 95 EXPECT_EQ("chrome-extension", |
| 96 WebIntentsInfo::GetIntentsServices(extension)[i].service_url.scheme()); |
| 97 EXPECT_EQ("/services/share", |
| 98 WebIntentsInfo::GetIntentsServices(extension)[i].service_url.path()); |
| 99 EXPECT_EQ("Sample Sharing Intent", |
| 100 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[i].title)); |
| 101 EXPECT_EQ(webkit_glue::WebIntentServiceData::DISPOSITION_INLINE, |
| 102 WebIntentsInfo::GetIntentsServices(extension)[i].disposition); |
| 103 } |
| 104 EXPECT_EQ("image/jpeg", |
| 105 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].type)); |
| 106 EXPECT_EQ("image/bmp", |
| 107 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[1].type)); |
| 108 |
| 109 LoadAndExpectError("intent_invalid_type_element.json", |
| 110 extension_manifest_errors::kInvalidIntentTypeElement); |
| 111 } |
| 112 |
| 113 TEST_F(WebIntentsManifestTest, WebIntentsInHostedApps) { |
| 114 Testcase testcases[] = { |
| 115 Testcase("intent_invalid_hosted_app_1.json", |
| 116 errors::kInvalidIntentPageInHostedApp), |
| 117 Testcase("intent_invalid_hosted_app_2.json", |
| 118 errors::kInvalidIntentPageInHostedApp), |
| 119 Testcase("intent_invalid_hosted_app_3.json", |
| 120 errors::kInvalidIntentPageInHostedApp) |
| 121 }; |
| 122 RunTestcases(testcases, arraysize(testcases), |
| 123 EXPECT_TYPE_ERROR); |
| 124 |
| 125 scoped_refptr<Extension> extension( |
| 126 LoadAndExpectSuccess("intent_valid_hosted_app.json")); |
| 127 ASSERT_TRUE(extension); |
| 128 |
| 129 ASSERT_EQ(3u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 130 EXPECT_EQ("http://www.cfp.com/intents/edit.html", |
| 131 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.spec()); |
| 132 EXPECT_EQ("http://www.cloudfilepicker.com/", |
| 133 WebIntentsInfo::GetIntentsServices(extension)[1].service_url.spec()); |
| 134 EXPECT_EQ("http://www.cloudfilepicker.com/intents/share.html", |
| 135 WebIntentsInfo::GetIntentsServices(extension)[2].service_url.spec()); |
| 136 } |
| 137 |
| 138 TEST_F(WebIntentsManifestTest, WebIntentsMultiHref) { |
| 139 scoped_refptr<Extension> extension( |
| 140 LoadAndExpectSuccess("intent_valid_multi_href.json")); |
| 141 ASSERT_TRUE(extension); |
| 142 |
| 143 ASSERT_EQ(2u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 144 EXPECT_EQ("chrome-extension", |
| 145 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.scheme()); |
| 146 EXPECT_EQ("/services/sharelink.html", |
| 147 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.path()); |
| 148 EXPECT_EQ("text/uri-list", |
| 149 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[0].type)); |
| 150 EXPECT_EQ("chrome-extension", |
| 151 WebIntentsInfo::GetIntentsServices(extension)[1].service_url.scheme()); |
| 152 EXPECT_EQ("/services/shareimage.html", |
| 153 WebIntentsInfo::GetIntentsServices(extension)[1].service_url.path()); |
| 154 EXPECT_EQ("image/*", |
| 155 UTF16ToUTF8(WebIntentsInfo::GetIntentsServices(extension)[1].type)); |
| 156 } |
| 157 |
| 158 TEST_F(WebIntentsManifestTest, WebIntentsBlankHref) { |
| 159 LoadAndExpectError("intent_invalid_blank_action_extension.json", |
| 160 errors::kInvalidIntentHrefEmpty); |
| 161 |
| 162 scoped_refptr<Extension> extension( |
| 163 LoadAndExpectSuccess("intent_valid_blank_action_hosted.json")); |
| 164 ASSERT_TRUE(extension); |
| 165 |
| 166 ASSERT_EQ(1u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 167 EXPECT_EQ("http://www.cloudfilepicker.com/", |
| 168 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.spec()); |
| 169 |
| 170 extension = LoadAndExpectSuccess("intent_valid_blank_action_packaged.json"); |
| 171 ASSERT_TRUE(extension); |
| 172 |
| 173 ASSERT_EQ(1u, WebIntentsInfo::GetIntentsServices(extension).size()); |
| 174 EXPECT_EQ("chrome-extension", |
| 175 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.scheme()); |
| 176 EXPECT_EQ("/main.html", |
| 177 WebIntentsInfo::GetIntentsServices(extension)[0].service_url.path()); |
| 178 } |
| OLD | NEW |