| 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 <string> | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "googleurl/src/gurl.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "webkit/glue/web_intent_service_data.h" | |
| 11 | |
| 12 using webkit_glue::WebIntentServiceData; | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 void Expect( | |
| 17 const std::string& action, | |
| 18 const std::string& type, | |
| 19 const std::string& scheme, | |
| 20 const std::string& url, | |
| 21 const std::string& title, | |
| 22 const WebIntentServiceData::Disposition disposition, | |
| 23 const WebIntentServiceData* intent) { | |
| 24 | |
| 25 EXPECT_EQ(GURL(url), intent->service_url); | |
| 26 EXPECT_EQ(ASCIIToUTF16(action), intent->action); | |
| 27 EXPECT_EQ(ASCIIToUTF16(type), intent->type); | |
| 28 EXPECT_EQ(ASCIIToUTF16(scheme), intent->scheme); | |
| 29 EXPECT_EQ(ASCIIToUTF16(title), intent->title); | |
| 30 EXPECT_EQ(disposition, intent->disposition); | |
| 31 } | |
| 32 | |
| 33 TEST(WebIntentServiceDataTest, Defaults) { | |
| 34 WebIntentServiceData intent; | |
| 35 EXPECT_EQ(string16(), intent.action); | |
| 36 EXPECT_EQ(string16(), intent.type); | |
| 37 EXPECT_EQ(string16(), intent.scheme); | |
| 38 EXPECT_EQ(string16(), intent.title); | |
| 39 EXPECT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, intent.disposition); | |
| 40 } | |
| 41 | |
| 42 TEST(WebIntentServiceDataTest, ActionServicesEqual) { | |
| 43 | |
| 44 WebIntentServiceData intent( | |
| 45 ASCIIToUTF16("http://webintents.org/share"), | |
| 46 ASCIIToUTF16("image/png"), | |
| 47 string16(), | |
| 48 GURL("http://abc.com/xyx.html"), | |
| 49 ASCIIToUTF16("Image Sharing Service")); | |
| 50 | |
| 51 Expect( | |
| 52 "http://webintents.org/share", | |
| 53 "image/png", | |
| 54 std::string(), | |
| 55 "http://abc.com/xyx.html", | |
| 56 "Image Sharing Service", | |
| 57 WebIntentServiceData::DISPOSITION_WINDOW, | |
| 58 &intent); | |
| 59 } | |
| 60 | |
| 61 TEST(WebIntentServiceDataTest, SchemeServicesEqual) { | |
| 62 | |
| 63 WebIntentServiceData intent( | |
| 64 string16(), | |
| 65 string16(), | |
| 66 ASCIIToUTF16("mailto"), | |
| 67 GURL("http://abc.com/xyx.html"), | |
| 68 ASCIIToUTF16("Image Sharing Service")); | |
| 69 | |
| 70 Expect( | |
| 71 "", | |
| 72 "", | |
| 73 "mailto", | |
| 74 "http://abc.com/xyx.html", | |
| 75 "Image Sharing Service", | |
| 76 WebIntentServiceData::DISPOSITION_WINDOW, | |
| 77 &intent); | |
| 78 } | |
| 79 | |
| 80 TEST(WebIntentServiceDataTest, SetDisposition) { | |
| 81 | |
| 82 // Test using the default disposition (window). | |
| 83 WebIntentServiceData intent; | |
| 84 EXPECT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, intent.disposition); | |
| 85 | |
| 86 // Set the disposition to "inline", another supported disposition. | |
| 87 intent.setDisposition(ASCIIToUTF16("inline")); | |
| 88 EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, intent.disposition); | |
| 89 | |
| 90 // "native" is a special internal disposition we use for | |
| 91 // "built-in" services. We don't allow the "native" disposition to be | |
| 92 // set via web-content (which is how this SetDisposition gets called). | |
| 93 // So after trying to set the value to "native" the disposition should | |
| 94 // remain unchanged. | |
| 95 intent.setDisposition(ASCIIToUTF16("native")); | |
| 96 EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, intent.disposition); | |
| 97 | |
| 98 // Unrecognized values are ignored. When trying to set the value to "poodles" | |
| 99 // the disposition should remain unchanged. | |
| 100 intent.setDisposition(ASCIIToUTF16("poodles")); | |
| 101 EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, intent.disposition); | |
| 102 | |
| 103 // Set the value back to "window" to confirm we can set back to | |
| 104 // the default disposition value, and to confirm setting still | |
| 105 // works after our special casing of the "native" and unrecognized values. | |
| 106 intent.setDisposition(ASCIIToUTF16("window")); | |
| 107 EXPECT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, intent.disposition); | |
| 108 } | |
| 109 | |
| 110 } // namespace | |
| OLD | NEW |