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..168c9ac514acf532dbe4596ba39816f38f601090 |
--- /dev/null |
+++ b/chrome/browser/webdata/web_intents_table_unittest.cc |
@@ -0,0 +1,102 @@ |
+// 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/path_service.h" |
+#include "base/string16.h" |
+#include "base/string_number_conversions.h" |
+#include "base/utf_string_conversions.h" |
+#include "base/time.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() {} |
+ virtual ~WebIntentsTableTest() {} |
James Hawkins
2011/07/26 20:21:53
Can likely leave off the destructor.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+ |
+ protected: |
+ virtual void SetUp() { |
+ PathService::Get(chrome::DIR_TEST_DATA, &file_); |
+ const std::string test_db = "TestWebDatabase" + |
+ base::Int64ToString(Time::Now().ToTimeT()) + |
+ ".db"; |
+ file_ = file_.AppendASCII(test_db); |
+ file_util::Delete(file_, false); |
Paweł Hajdan Jr.
2011/07/26 20:33:48
I think ScopedTempDir would be better. It handles
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+ } |
+ |
+ virtual void TearDown() { |
+ file_util::Delete(file_, false); |
+ } |
+ |
+ FilePath file_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WebIntentsTableTest); |
Paweł Hajdan Jr.
2011/07/26 20:33:48
nit: No need for this for a test fixture.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+}; |
+ |
James Hawkins
2011/07/26 20:21:53
Remove extra blank line.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+ |
+TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { |
James Hawkins
2011/07/26 20:21:53
Document the test case.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+ WebDatabase db; |
+ |
+ ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
+ GURL url("http://google.com/"); |
+ string16 action=ASCIIToUTF16("http://webintents.org/intents/share"); |
James Hawkins
2011/07/26 20:21:53
Spaces around '=', here and elsewhere.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+ string16 type=ASCIIToUTF16("image/*"); |
+ std::vector<WebIntent> 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)); |
+ EXPECT_EQ(1U, intents.size()); |
James Hawkins
2011/07/26 20:21:53
When checking size of a vector you're going to acc
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
+ |
+ 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_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<WebIntent> 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)); |
+ EXPECT_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); |
+} |