Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: chrome/browser/webdata/web_intents_table_unittest.cc

Issue 7461089: First implementation of web intents table. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More review fixes, small test refactor. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 class WebIntentsTableTest : public testing::Test {
20 public:
21 WebIntentsTableTest() : db_(NULL) {}
James Hawkins 2011/07/26 23:35:06 Move these methods to the protected section.
groby-ooo-7-16 2011/07/27 00:09:25 Done.
22
23 WebIntentsTable* IntentsTable() {
24 CHECK(db_ != NULL);
Paweł Hajdan Jr. 2011/07/26 23:30:53 Could you remove this CHECK? It's going to crash a
James Hawkins 2011/07/26 23:35:06 Don't use CHECK (or DCHECK) in testing code. Use
groby-ooo-7-16 2011/07/27 00:09:25 Done.
groby-ooo-7-16 2011/07/27 00:09:25 Done.
25 return db_->GetWebIntentsTable();
26 }
27
28 protected:
29 virtual void SetUp() {
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
31 db_ = new WebDatabase();
32 ASSERT_TRUE(db_ != NULL);
Paweł Hajdan Jr. 2011/07/26 23:30:53 nit: Not needed.
James Hawkins 2011/07/26 23:35:06 ASSERT_NE(...)
groby-ooo-7-16 2011/07/27 00:09:25 Done.
groby-ooo-7-16 2011/07/27 00:09:25 Done.
33 ASSERT_EQ(sql::INIT_OK,
James Hawkins 2011/07/26 23:35:06 Params should line up in the same column if wrappi
groby-ooo-7-16 2011/07/27 00:09:25 Done.
34 db_->Init(temp_dir_.path().AppendASCII("TestWebDatabase.db")));
35 }
36
37 virtual void TearDown() {
James Hawkins 2011/07/26 23:35:06 Use a scoped_ptr for |db_| and get rid of TearDown
groby-ooo-7-16 2011/07/27 00:09:25 Done.
38 delete db_;
Paweł Hajdan Jr. 2011/07/26 23:30:53 Either use scoped_ptr or just do WebDatabase db_;
groby-ooo-7-16 2011/07/27 00:09:25 Done.
39 }
40
41 ScopedTempDir temp_dir_;
42 WebDatabase* db_;
43 };
44
45 namespace {
James Hawkins 2011/07/26 23:35:06 Wrap the entire test implementation (including the
groby-ooo-7-16 2011/07/27 00:09:25 Done.
46 static GURL test_url("http://google.com/");
James Hawkins 2011/07/26 23:35:06 Don't use static inside an unnamed namespace.
groby-ooo-7-16 2011/07/27 00:09:25 Done.
47 static string16 test_action = ASCIIToUTF16("http://webintents.org/intents/shar e");
James Hawkins 2011/07/26 23:35:06 nit: 80 cols
groby-ooo-7-16 2011/07/27 00:09:25 Done.
48 static string16 mime_image = ASCIIToUTF16("image/*");
49 static string16 mime_video = ASCIIToUTF16("video/*");
50 }
51
52 // Test we can add, retrieve, and remove intents from the database.
53 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) {
54 std::vector<WebIntentData> intents;
55
56 // By default, no intents exist.
57 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
58 EXPECT_EQ(0U, intents.size());
59
60 // Now adding one.
61 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url));
62
63 // Make sure that intent can now be fetched
64 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
65 ASSERT_EQ(1U, intents.size());
66
67 EXPECT_EQ(test_url.spec(), intents[0].service_url.spec());
68 EXPECT_EQ(test_action, intents[0].action);
69 EXPECT_EQ(mime_image, intents[0].type);
70
71 // Remove the intent.
72 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(test_action, mime_image,
73 test_url));
74
75 // Intent should now be gone.
76 intents.clear();
77 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
78 EXPECT_EQ(0U, intents.size());
79 }
80
81 // Test we support multiple intents for the same MIME type
82 TEST_F(WebIntentsTableTest, SetMultipleIntents) {
83 std::vector<WebIntentData> intents;
84
85 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url));
86 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_video, test_url));
87
88 // Recover stored intents from DB
James Hawkins 2011/07/26 23:35:06 Period at end of sentence, here and elsewhere.
groby-ooo-7-16 2011/07/27 00:09:25 Done.
89 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
90 ASSERT_EQ(2U, intents.size());
91
92 // WebIntentsTable does not guarantee order, so ensure order here.
93 if (intents[0].type == mime_video)
94 std::swap(intents[0],intents[1]);
James Hawkins 2011/07/26 23:35:06 Space after comma.
groby-ooo-7-16 2011/07/27 00:09:25 Done.
95
96 EXPECT_EQ(test_url, intents[0].service_url);
97 EXPECT_EQ(test_action, intents[0].action);
98 EXPECT_EQ(mime_image, intents[0].type);
99
100 EXPECT_EQ(test_url, intents[1].service_url);
101 EXPECT_EQ(test_action, intents[1].action);
102 EXPECT_EQ(mime_video, intents[1].type);
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698