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/path_service.h" | |
7 #include "base/string16.h" | |
8 #include "base/string_number_conversions.h" | |
9 #include "base/utf_string_conversions.h" | |
10 #include "base/time.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 class WebIntentsTableTest : public testing::Test { | |
20 public: | |
21 WebIntentsTableTest() {} | |
22 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.
| |
23 | |
24 protected: | |
25 virtual void SetUp() { | |
26 PathService::Get(chrome::DIR_TEST_DATA, &file_); | |
27 const std::string test_db = "TestWebDatabase" + | |
28 base::Int64ToString(Time::Now().ToTimeT()) + | |
29 ".db"; | |
30 file_ = file_.AppendASCII(test_db); | |
31 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.
| |
32 } | |
33 | |
34 virtual void TearDown() { | |
35 file_util::Delete(file_, false); | |
36 } | |
37 | |
38 FilePath file_; | |
39 | |
40 private: | |
41 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.
| |
42 }; | |
43 | |
James Hawkins
2011/07/26 20:21:53
Remove extra blank line.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
| |
44 | |
45 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.
| |
46 WebDatabase db; | |
47 | |
48 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | |
49 GURL url("http://google.com/"); | |
50 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.
| |
51 string16 type=ASCIIToUTF16("image/*"); | |
52 std::vector<WebIntent> intents; | |
53 | |
54 // By default, no intents exist. | |
55 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, intents)); | |
56 EXPECT_EQ(0U, intents.size()); | |
57 | |
58 // Now adding one. | |
59 EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type, url)); | |
60 | |
61 // Make sure that intent can now be fetched | |
62 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, intents)); | |
63 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.
| |
64 | |
65 EXPECT_EQ(url.spec(), intents[0].service_url.spec()); | |
66 EXPECT_EQ(action, intents[0].action); | |
67 EXPECT_EQ(type, intents[0].type); | |
68 | |
69 // Remove the intent. | |
70 EXPECT_TRUE(db.GetWebIntentsTable()->RemoveWebIntent(action, type, url)); | |
71 | |
72 // Intent should now be gone. | |
73 intents.clear(); | |
74 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, intents)); | |
75 EXPECT_EQ(0U, intents.size()); | |
76 } | |
77 | |
78 TEST_F(WebIntentsTableTest, SetMultipleIntents) { | |
79 WebDatabase db; | |
80 | |
81 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | |
82 GURL url("http://google.com/"); | |
83 string16 action=ASCIIToUTF16("http://webintents.org/intents/share"); | |
84 string16 type=ASCIIToUTF16("image/*"); | |
85 string16 type2=ASCIIToUTF16("video/*"); | |
86 std::vector<WebIntent> intents; | |
87 | |
88 EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type, url)); | |
89 EXPECT_TRUE(db.GetWebIntentsTable()->SetWebIntent(action, type2, url)); | |
90 | |
91 // Recover stored intents from DB | |
92 EXPECT_TRUE(db.GetWebIntentsTable()->GetWebIntents(action, intents)); | |
93 EXPECT_EQ(2U, intents.size()); | |
94 | |
95 EXPECT_EQ(url, intents[0].service_url); | |
96 EXPECT_EQ(action, intents[0].action); | |
97 EXPECT_EQ(type, intents[0].type); | |
98 | |
99 EXPECT_EQ(url, intents[1].service_url); | |
100 EXPECT_EQ(action, intents[1].action); | |
101 EXPECT_EQ(type2, intents[1].type); | |
102 } | |
OLD | NEW |