Chromium Code Reviews| Index: chrome/browser/webdata/web_intents_table_unittest.cc |
| diff --git a/chrome/browser/webdata/web_intents_table_unittest.cc b/chrome/browser/webdata/web_intents_table_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6433b72ba41f25118f46ea58a9be3f4c07cc83a |
| --- /dev/null |
| +++ b/chrome/browser/webdata/web_intents_table_unittest.cc |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/file_util.h" |
| +#include "base/scoped_temp_dir.h" |
| +#include "base/string16.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/webdata/web_database.h" |
| +#include "chrome/browser/webdata/web_intents_table.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using base::Time; |
| + |
| +class WebIntentsTableTest : public testing::Test { |
| + public: |
| + WebIntentsTableTest() {} |
|
James Hawkins
2011/07/26 21:48:41
Can remove this constructor.
groby-ooo-7-16
2011/07/26 23:12:34
Done.
|
| + |
| + protected: |
| + virtual void SetUp() { |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + file_ = temp_dir_.path().AppendASCII("TestWebDatabase.db"); |
| + 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.
|
| + } |
| + |
| + virtual void TearDown() { |
| + 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.
|
| + } |
| + |
| + FilePath file_; |
| + ScopedTempDir temp_dir_; |
| +}; |
| + |
| +// Test we can add, retrieve, and remove intents from the database. |
| +TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { |
| + WebDatabase db; |
| + |
| + ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| + GURL url("http://google.com/"); |
| + string16 action = ASCIIToUTF16("http://webintents.org/intents/share"); |
| + string16 type = ASCIIToUTF16("image/*"); |
| + std::vector<WebIntentData> intents; |
| + |
| + // By default, no intents exist. |
| + EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); |
| + EXPECT_EQ(0U, intents.size()); |
| + |
| + // Now adding one. |
| + EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type, url)); |
| + |
| + // Make sure that intent can now be fetched |
| + EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); |
| + ASSERT_EQ(1U, intents.size()); |
| + |
| + EXPECT_EQ(url.spec(), intents[0].service_url.spec()); |
| + EXPECT_EQ(action, intents[0].action); |
| + EXPECT_EQ(type, intents[0].type); |
| + |
| + // Remove the intent. |
| + EXPECT_TRUE(db.GetWebIntentsTable()->RemoveWebIntent(action, type, url)); |
| + |
| + // Intent should now be gone. |
| + intents.clear(); |
| + EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); |
| + EXPECT_EQ(0U, intents.size()); |
| +} |
| + |
| +// Test we support multiple intents for the same MIME type |
| +TEST_F(WebIntentsTableTest, SetMultipleIntents) { |
| + WebDatabase db; |
| + |
| + ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| + GURL url("http://google.com/"); |
| + string16 action = ASCIIToUTF16("http://webintents.org/intents/share"); |
| + string16 type = ASCIIToUTF16("image/*"); |
| + string16 type2 = ASCIIToUTF16("video/*"); |
| + std::vector<WebIntentData> intents; |
| + |
| + EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type, url)); |
| + EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type2, url)); |
| + |
| + // Recover stored intents from DB |
| + EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, &intents)); |
| + ASSERT_EQ(2U, intents.size()); |
| + |
| + EXPECT_EQ(url, intents[0].service_url); |
| + EXPECT_EQ(action, intents[0].action); |
| + EXPECT_EQ(type, intents[0].type); |
| + |
| + EXPECT_EQ(url, intents[1].service_url); |
| + EXPECT_EQ(action, intents[1].action); |
| + EXPECT_EQ(type2, intents[1].type); |
| +} |