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

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. Created 9 years, 5 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 namespace {
20
21 class WebIntentsTableTest : public testing::Test {
22 protected:
23 virtual void SetUp() {
24 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
25 ASSERT_EQ(sql::INIT_OK,
26 db_.Init(temp_dir_.path().AppendASCII("TestWebDatabase.db")));
27 }
28
29 WebIntentsTable* IntentsTable() {
30 return db_.GetWebIntentsTable();
31 }
32
33 WebDatabase db_;
34 ScopedTempDir temp_dir_;
35 };
36
37 GURL test_url("http://google.com/");
38 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share");
James Hawkins 2011/07/27 00:19:53 nit: Move the vars above the class.
groby-ooo-7-16 2011/07/27 03:42:21 Done.
39 string16 mime_image = ASCIIToUTF16("image/*");
40 string16 mime_video = ASCIIToUTF16("video/*");
41
42 // Test we can add, retrieve, and remove intents from the database.
43 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) {
44 std::vector<WebIntentData> intents;
45
46 // By default, no intents exist.
47 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
48 EXPECT_EQ(0U, intents.size());
49
50 // Now adding one.
51 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url));
52
53 // Make sure that intent can now be fetched
54 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
55 ASSERT_EQ(1U, intents.size());
56
57 EXPECT_EQ(test_url.spec(), intents[0].service_url.spec());
58 EXPECT_EQ(test_action, intents[0].action);
59 EXPECT_EQ(mime_image, intents[0].type);
60
61 // Remove the intent.
62 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(test_action, mime_image,
63 test_url));
64
65 // Intent should now be gone.
66 intents.clear();
67 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
68 EXPECT_EQ(0U, intents.size());
69 }
70
71 // Test we support multiple intents for the same MIME type
72 TEST_F(WebIntentsTableTest, SetMultipleIntents) {
73 std::vector<WebIntentData> intents;
74
75 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_image, test_url));
76 EXPECT_TRUE(IntentsTable()->SetWebIntent(test_action, mime_video, test_url));
77
78 // Recover stored intents from DB.
79 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
80 ASSERT_EQ(2U, intents.size());
81
82 // WebIntentsTable does not guarantee order, so ensure order here.
83 if (intents[0].type == mime_video)
84 std::swap(intents[0], intents[1]);
85
86 EXPECT_EQ(test_url, intents[0].service_url);
87 EXPECT_EQ(test_action, intents[0].action);
88 EXPECT_EQ(mime_image, intents[0].type);
89
90 EXPECT_EQ(test_url, intents[1].service_url);
91 EXPECT_EQ(test_action, intents[1].action);
92 EXPECT_EQ(mime_video, intents[1].type);
93 }
94 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698