Chromium Code Reviews| 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 "base/file_util.h" | |
| 6 #include "base/scoped_temp_dir.h" | |
| 7 #include "base/string16.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/webdata/web_database.h" | |
| 10 #include "chrome/browser/webdata/web_intents_table.h" | |
| 11 #include "chrome/common/chrome_paths.h" | |
| 12 #include "googleurl/src/gurl.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 using base::Time; | |
| 16 | |
| 17 class WebIntentsTableTest : public testing::Test { | |
| 18 public: | |
| 19 WebIntentsTableTest() {} | |
|
James Hawkins
2011/07/26 21:48:41
Can remove this constructor.
groby-ooo-7-16
2011/07/26 23:12:34
Done.
| |
| 20 | |
| 21 protected: | |
| 22 virtual void SetUp() { | |
| 23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 24 file_ = temp_dir_.path().AppendASCII("TestWebDatabase.db"); | |
| 25 file_util::Delete(file_, false); | |
|
Paweł Hajdan Jr.
2011/07/26 21:46:25
You don't need it now.
groby-ooo-7-16
2011/07/26 23:12:34
Done.
| |
| 26 } | |
| 27 | |
| 28 virtual void TearDown() { | |
| 29 file_util::Delete(file_, false); | |
|
Paweł Hajdan Jr.
2011/07/26 21:46:25
You don't need it now either (please remove TearDo
groby-ooo-7-16
2011/07/26 23:12:34
Done.
| |
| 30 } | |
| 31 | |
| 32 FilePath file_; | |
| 33 ScopedTempDir temp_dir_; | |
| 34 }; | |
| 35 | |
| 36 // Test we can add, retrieve, and remove intents from the database. | |
| 37 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { | |
| 38 WebDatabase db; | |
| 39 | |
| 40 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | |
| 41 GURL url("http://google.com/"); | |
| 42 string16 action = ASCIIToUTF16("http://webintents.org/intents/share"); | |
| 43 string16 type = ASCIIToUTF16("image/*"); | |
| 44 std::vector<WebIntentData> intents; | |
| 45 | |
| 46 // By default, no intents exist. | |
| 47 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); | |
| 48 EXPECT_EQ(0U, intents.size()); | |
| 49 | |
| 50 // Now adding one. | |
| 51 EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type, url)); | |
| 52 | |
| 53 // Make sure that intent can now be fetched | |
| 54 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); | |
| 55 ASSERT_EQ(1U, intents.size()); | |
| 56 | |
| 57 EXPECT_EQ(url.spec(), intents[0].service_url.spec()); | |
| 58 EXPECT_EQ(action, intents[0].action); | |
| 59 EXPECT_EQ(type, intents[0].type); | |
| 60 | |
| 61 // Remove the intent. | |
| 62 EXPECT_TRUE(db.GetWebIntentsTable()->RemoveWebIntent(action, type, url)); | |
| 63 | |
| 64 // Intent should now be gone. | |
| 65 intents.clear(); | |
| 66 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); | |
| 67 EXPECT_EQ(0U, intents.size()); | |
| 68 } | |
| 69 | |
| 70 // Test we support multiple intents for the same MIME type | |
| 71 TEST_F(WebIntentsTableTest, SetMultipleIntents) { | |
| 72 WebDatabase db; | |
| 73 | |
| 74 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | |
| 75 GURL url("http://google.com/"); | |
| 76 string16 action = ASCIIToUTF16("http://webintents.org/intents/share"); | |
| 77 string16 type = ASCIIToUTF16("image/*"); | |
| 78 string16 type2 = ASCIIToUTF16("video/*"); | |
| 79 std::vector<WebIntentData> intents; | |
| 80 | |
| 81 EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type, url)); | |
| 82 EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type2, url)); | |
| 83 | |
| 84 // Recover stored intents from DB | |
| 85 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); | |
| 86 ASSERT_EQ(2U, intents.size()); | |
| 87 | |
| 88 EXPECT_EQ(url, intents[0].service_url); | |
| 89 EXPECT_EQ(action, intents[0].action); | |
| 90 EXPECT_EQ(type, intents[0].type); | |
| 91 | |
| 92 EXPECT_EQ(url, intents[1].service_url); | |
| 93 EXPECT_EQ(action, intents[1].action); | |
| 94 EXPECT_EQ(type2, intents[1].type); | |
| 95 } | |
| OLD | NEW |