OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/webdata/web_database.h" | 11 #include "chrome/browser/webdata/web_database.h" |
12 #include "chrome/browser/webdata/web_intents_table.h" | 12 #include "chrome/browser/webdata/web_intents_table.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using base::Time; | |
18 | |
19 namespace { | 17 namespace { |
20 | 18 |
21 GURL test_url("http://google.com/"); | 19 GURL test_url("http://google.com/"); |
22 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share"); | 20 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share"); |
23 string16 mime_image = ASCIIToUTF16("image/*"); | 21 string16 mime_image = ASCIIToUTF16("image/*"); |
24 string16 mime_video = ASCIIToUTF16("video/*"); | 22 string16 mime_video = ASCIIToUTF16("video/*"); |
25 | 23 |
26 class WebIntentsTableTest : public testing::Test { | 24 class WebIntentsTableTest : public testing::Test { |
27 protected: | 25 protected: |
28 virtual void SetUp() { | 26 virtual void SetUp() { |
(...skipping 12 matching lines...) Expand all Loading... |
41 | 39 |
42 // Test we can add, retrieve, and remove intents from the database. | 40 // Test we can add, retrieve, and remove intents from the database. |
43 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { | 41 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { |
44 std::vector<WebIntentData> intents; | 42 std::vector<WebIntentData> intents; |
45 | 43 |
46 // By default, no intents exist. | 44 // By default, no intents exist. |
47 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); | 45 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
48 EXPECT_EQ(0U, intents.size()); | 46 EXPECT_EQ(0U, intents.size()); |
49 | 47 |
50 // Now adding one. | 48 // Now adding one. |
51 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url)); | 49 WebIntentData intent; |
| 50 intent.service_url = test_url; |
| 51 intent.action = test_action; |
| 52 intent.type = mime_image; |
| 53 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); |
52 | 54 |
53 // Make sure that intent can now be fetched | 55 // Make sure that intent can now be fetched |
54 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); | 56 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
55 ASSERT_EQ(1U, intents.size()); | 57 ASSERT_EQ(1U, intents.size()); |
56 | 58 EXPECT_EQ(intent, intents[0]); |
57 EXPECT_EQ(test_url.spec(), intents[0].service_url.spec()); | |
58 EXPECT_EQ(test_action, intents[0].action); | |
59 EXPECT_EQ(mime_image, intents[0].type); | |
60 | 59 |
61 // Remove the intent. | 60 // Remove the intent. |
62 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(test_action, mime_image, | 61 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(intent)); |
63 test_url)); | |
64 | 62 |
65 // Intent should now be gone. | 63 // Intent should now be gone. |
66 intents.clear(); | 64 intents.clear(); |
67 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); | 65 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
68 EXPECT_EQ(0U, intents.size()); | 66 EXPECT_EQ(0U, intents.size()); |
69 } | 67 } |
70 | 68 |
71 // Test we support multiple intents for the same MIME type | 69 // Test we support multiple intents for the same MIME type |
72 TEST_F(WebIntentsTableTest, SetMultipleIntents) { | 70 TEST_F(WebIntentsTableTest, SetMultipleIntents) { |
73 std::vector<WebIntentData> intents; | 71 std::vector<WebIntentData> intents; |
74 | 72 |
75 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url)); | 73 WebIntentData intent; |
76 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_video, test_url)); | 74 intent.service_url = test_url; |
| 75 intent.action = test_action; |
| 76 intent.type = mime_image; |
| 77 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); |
| 78 |
| 79 intent.type = mime_video; |
| 80 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); |
77 | 81 |
78 // Recover stored intents from DB. | 82 // Recover stored intents from DB. |
79 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); | 83 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
80 ASSERT_EQ(2U, intents.size()); | 84 ASSERT_EQ(2U, intents.size()); |
81 | 85 |
82 // WebIntentsTable does not guarantee order, so ensure order here. | 86 // WebIntentsTable does not guarantee order, so ensure order here. |
83 if (intents[0].type == mime_video) | 87 if (intents[0].type == mime_video) |
84 std::swap(intents[0], intents[1]); | 88 std::swap(intents[0], intents[1]); |
85 | 89 |
86 EXPECT_EQ(test_url, intents[0].service_url); | 90 EXPECT_EQ(intent, intents[1]); |
87 EXPECT_EQ(test_action, intents[0].action); | |
88 EXPECT_EQ(mime_image, intents[0].type); | |
89 | 91 |
90 EXPECT_EQ(test_url, intents[1].service_url); | 92 intent.type = mime_image; |
91 EXPECT_EQ(test_action, intents[1].action); | 93 EXPECT_EQ(intent, intents[0]); |
92 EXPECT_EQ(mime_video, intents[1].type); | |
93 } | 94 } |
94 } // namespace | 95 } // namespace |
OLD | NEW |