OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <algorithm> |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/string16.h" |
| 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/webdata/web_database.h" |
| 12 #include "chrome/browser/webdata/web_intents_table.h" |
| 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 using base::Time; |
| 18 |
| 19 namespace { |
| 20 |
| 21 GURL test_url("http://google.com/"); |
| 22 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share"); |
| 23 string16 mime_image = ASCIIToUTF16("image/*"); |
| 24 string16 mime_video = ASCIIToUTF16("video/*"); |
| 25 |
| 26 class WebIntentsTableTest : public testing::Test { |
| 27 protected: |
| 28 virtual void SetUp() { |
| 29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 30 ASSERT_EQ(sql::INIT_OK, |
| 31 db_.Init(temp_dir_.path().AppendASCII("TestWebDatabase.db"))); |
| 32 } |
| 33 |
| 34 WebIntentsTable* IntentsTable() { |
| 35 return db_.GetWebIntentsTable(); |
| 36 } |
| 37 |
| 38 WebDatabase db_; |
| 39 ScopedTempDir temp_dir_; |
| 40 }; |
| 41 |
| 42 // Test we can add, retrieve, and remove intents from the database. |
| 43 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { |
| 44 std::vector<WebIntentData> intents; |
| 45 |
| 46 // By default, no intents exist. |
| 47 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
| 48 EXPECT_EQ(0U, intents.size()); |
| 49 |
| 50 // Now adding one. |
| 51 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url)); |
| 52 |
| 53 // Make sure that intent can now be fetched |
| 54 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
| 55 ASSERT_EQ(1U, intents.size()); |
| 56 |
| 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 |
| 61 // Remove the intent. |
| 62 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(test_action, mime_image, |
| 63 test_url)); |
| 64 |
| 65 // Intent should now be gone. |
| 66 intents.clear(); |
| 67 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
| 68 EXPECT_EQ(0U, intents.size()); |
| 69 } |
| 70 |
| 71 // Test we support multiple intents for the same MIME type |
| 72 TEST_F(WebIntentsTableTest, SetMultipleIntents) { |
| 73 std::vector<WebIntentData> intents; |
| 74 |
| 75 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url)); |
| 76 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_video, test_url)); |
| 77 |
| 78 // Recover stored intents from DB. |
| 79 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); |
| 80 ASSERT_EQ(2U, intents.size()); |
| 81 |
| 82 // WebIntentsTable does not guarantee order, so ensure order here. |
| 83 if (intents[0].type == mime_video) |
| 84 std::swap(intents[0], intents[1]); |
| 85 |
| 86 EXPECT_EQ(test_url, intents[0].service_url); |
| 87 EXPECT_EQ(test_action, intents[0].action); |
| 88 EXPECT_EQ(mime_image, intents[0].type); |
| 89 |
| 90 EXPECT_EQ(test_url, intents[1].service_url); |
| 91 EXPECT_EQ(test_action, intents[1].action); |
| 92 EXPECT_EQ(mime_video, intents[1].type); |
| 93 } |
| 94 } // namespace |
OLD | NEW |