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

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

Issue 7930002: Rename WebIntentData for backend storage to WebIntentServiceData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix class/struct decl Created 9 years, 3 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
« no previous file with comments | « chrome/browser/webdata/web_intents_table.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/intents/web_intent_data.h" 11 #include "chrome/browser/intents/web_intent_service_data.h"
12 #include "chrome/browser/webdata/web_database.h" 12 #include "chrome/browser/webdata/web_database.h"
13 #include "chrome/browser/webdata/web_intents_table.h" 13 #include "chrome/browser/webdata/web_intents_table.h"
14 #include "chrome/common/chrome_paths.h" 14 #include "chrome/common/chrome_paths.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace { 18 namespace {
19 19
20 GURL test_url("http://google.com/"); 20 GURL test_url("http://google.com/");
21 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share"); 21 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share");
22 string16 test_action_2 = ASCIIToUTF16("http://webintents.org/intents/view"); 22 string16 test_action_2 = ASCIIToUTF16("http://webintents.org/intents/view");
23 string16 test_title = ASCIIToUTF16("Test WebIntent"); 23 string16 test_title = ASCIIToUTF16("Test WebIntent");
24 string16 test_title_2 = ASCIIToUTF16("Test WebIntent #2"); 24 string16 test_title_2 = ASCIIToUTF16("Test WebIntent #2");
25 string16 mime_image = ASCIIToUTF16("image/*"); 25 string16 mime_image = ASCIIToUTF16("image/*");
26 string16 mime_video = ASCIIToUTF16("video/*"); 26 string16 mime_video = ASCIIToUTF16("video/*");
27 27
28 WebIntentData MakeIntent(const GURL& url, const string16& action, 28 WebIntentServiceData MakeIntent(const GURL& url, const string16& action,
29 const string16& type, const string16& title) { 29 const string16& type, const string16& title) {
30 WebIntentData intent; 30 WebIntentServiceData service;
31 intent.service_url = url; 31 service.service_url = url;
32 intent.action = action; 32 service.action = action;
33 intent.type = type; 33 service.type = type;
34 intent.title = title; 34 service.title = title;
35 intent.disposition = WebIntentData::DISPOSITION_INLINE; 35 service.disposition = WebIntentServiceData::DISPOSITION_INLINE;
36 return intent; 36 return service;
37 } 37 }
38 38
39 class WebIntentsTableTest : public testing::Test { 39 class WebIntentsTableTest : public testing::Test {
40 protected: 40 protected:
41 virtual void SetUp() { 41 virtual void SetUp() {
42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
43 ASSERT_EQ(sql::INIT_OK, 43 ASSERT_EQ(sql::INIT_OK,
44 db_.Init(temp_dir_.path().AppendASCII("TestWebDatabase.db"))); 44 db_.Init(temp_dir_.path().AppendASCII("TestWebDatabase.db")));
45 } 45 }
46 46
47 WebIntentsTable* IntentsTable() { 47 WebIntentsTable* IntentsTable() {
48 return db_.GetWebIntentsTable(); 48 return db_.GetWebIntentsTable();
49 } 49 }
50 50
51 WebDatabase db_; 51 WebDatabase db_;
52 ScopedTempDir temp_dir_; 52 ScopedTempDir temp_dir_;
53 }; 53 };
54 54
55 // Test we can add, retrieve, and remove intents from the database. 55 // Test we can add, retrieve, and remove intents from the database.
56 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) { 56 TEST_F(WebIntentsTableTest, SetGetDeleteIntent) {
57 std::vector<WebIntentData> intents; 57 std::vector<WebIntentServiceData> intents;
58 58
59 // By default, no intents exist. 59 // By default, no intents exist.
60 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); 60 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
61 EXPECT_EQ(0U, intents.size()); 61 EXPECT_EQ(0U, intents.size());
62 62
63 // Now adding one. 63 // Now adding one.
64 WebIntentData intent = MakeIntent(test_url, test_action, mime_image, 64 WebIntentServiceData intent = MakeIntent(test_url, test_action, mime_image,
65 test_title); 65 test_title);
66 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 66 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
67 67
68 // Make sure that intent can now be fetched 68 // Make sure that intent can now be fetched
69 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); 69 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
70 ASSERT_EQ(1U, intents.size()); 70 ASSERT_EQ(1U, intents.size());
71 EXPECT_EQ(intent, intents[0]); 71 EXPECT_EQ(intent, intents[0]);
72 72
73 // Remove the intent. 73 // Remove the intent.
74 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(intent)); 74 EXPECT_TRUE(IntentsTable()->RemoveWebIntent(intent));
75 75
76 // Intent should now be gone. 76 // Intent should now be gone.
77 intents.clear(); 77 intents.clear();
78 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); 78 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
79 EXPECT_EQ(0U, intents.size()); 79 EXPECT_EQ(0U, intents.size());
80 } 80 }
81 81
82 // Test we support multiple intents for the same MIME type 82 // Test we support multiple intents for the same MIME type
83 TEST_F(WebIntentsTableTest, SetMultipleIntents) { 83 TEST_F(WebIntentsTableTest, SetMultipleIntents) {
84 std::vector<WebIntentData> intents; 84 std::vector<WebIntentServiceData> intents;
85 85
86 WebIntentData intent = MakeIntent(test_url, test_action, mime_image, 86 WebIntentServiceData intent = MakeIntent(test_url, test_action, mime_image,
87 test_title); 87 test_title);
88 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 88 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
89 89
90 intent.type = mime_video; 90 intent.type = mime_video;
91 intent.title = test_title_2; 91 intent.title = test_title_2;
92 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 92 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
93 93
94 // Recover stored intents from DB. 94 // Recover stored intents from DB.
95 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents)); 95 EXPECT_TRUE(IntentsTable()->GetWebIntents(test_action, &intents));
96 ASSERT_EQ(2U, intents.size()); 96 ASSERT_EQ(2U, intents.size());
97 97
98 // WebIntentsTable does not guarantee order, so ensure order here. 98 // WebIntentsTable does not guarantee order, so ensure order here.
99 if (intents[0].type == mime_video) 99 if (intents[0].type == mime_video)
100 std::swap(intents[0], intents[1]); 100 std::swap(intents[0], intents[1]);
101 101
102 EXPECT_EQ(intent, intents[1]); 102 EXPECT_EQ(intent, intents[1]);
103 103
104 intent.type = mime_image; 104 intent.type = mime_image;
105 intent.title = test_title; 105 intent.title = test_title;
106 EXPECT_EQ(intent, intents[0]); 106 EXPECT_EQ(intent, intents[0]);
107 } 107 }
108 108
109 // Test we support getting all intents independent of action. 109 // Test we support getting all intents independent of action.
110 TEST_F(WebIntentsTableTest, GetAllIntents) { 110 TEST_F(WebIntentsTableTest, GetAllIntents) {
111 std::vector<WebIntentData> intents; 111 std::vector<WebIntentServiceData> intents;
112 112
113 WebIntentData intent = MakeIntent(test_url, test_action, mime_image, 113 WebIntentServiceData intent = MakeIntent(test_url, test_action, mime_image,
114 test_title); 114 test_title);
115 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 115 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
116 116
117 intent.action = test_action_2; 117 intent.action = test_action_2;
118 intent.title = test_title_2; 118 intent.title = test_title_2;
119 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 119 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
120 120
121 // Recover stored intents from DB. 121 // Recover stored intents from DB.
122 EXPECT_TRUE(IntentsTable()->GetAllWebIntents(&intents)); 122 EXPECT_TRUE(IntentsTable()->GetAllWebIntents(&intents));
123 ASSERT_EQ(2U, intents.size()); 123 ASSERT_EQ(2U, intents.size());
124 124
125 // WebIntentsTable does not guarantee order, so ensure order here. 125 // WebIntentsTable does not guarantee order, so ensure order here.
126 if (intents[0].type == test_action_2) 126 if (intents[0].type == test_action_2)
127 std::swap(intents[0], intents[1]); 127 std::swap(intents[0], intents[1]);
128 128
129 EXPECT_EQ(intent, intents[1]); 129 EXPECT_EQ(intent, intents[1]);
130 130
131 intent.action = test_action; 131 intent.action = test_action;
132 intent.title = test_title; 132 intent.title = test_title;
133 EXPECT_EQ(intent, intents[0]); 133 EXPECT_EQ(intent, intents[0]);
134 } 134 }
135 135
136 TEST_F(WebIntentsTableTest, DispositionToStringMapping) { 136 TEST_F(WebIntentsTableTest, DispositionToStringMapping) {
137 WebIntentData intent = MakeIntent(test_url, test_action, mime_image, 137 WebIntentServiceData intent = MakeIntent(test_url, test_action, mime_image,
138 test_title); 138 test_title);
139 intent.disposition = WebIntentData::DISPOSITION_WINDOW; 139 intent.disposition = WebIntentServiceData::DISPOSITION_WINDOW;
140 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 140 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
141 141
142 intent = MakeIntent(test_url, test_action, mime_video, 142 intent = MakeIntent(test_url, test_action, mime_video,
143 test_title); 143 test_title);
144 intent.disposition = WebIntentData::DISPOSITION_INLINE; 144 intent.disposition = WebIntentServiceData::DISPOSITION_INLINE;
145 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); 145 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
146 146
147 std::vector<WebIntentData> intents; 147 std::vector<WebIntentServiceData> intents;
148 EXPECT_TRUE(IntentsTable()->GetAllWebIntents(&intents)); 148 EXPECT_TRUE(IntentsTable()->GetAllWebIntents(&intents));
149 ASSERT_EQ(2U, intents.size()); 149 ASSERT_EQ(2U, intents.size());
150 150
151 if (intents[0].disposition == WebIntentData::DISPOSITION_WINDOW) 151 if (intents[0].disposition == WebIntentServiceData::DISPOSITION_WINDOW)
152 std::swap(intents[0], intents[1]); 152 std::swap(intents[0], intents[1]);
153 153
154 EXPECT_EQ(WebIntentData::DISPOSITION_INLINE, intents[0].disposition); 154 EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, intents[0].disposition);
155 EXPECT_EQ(WebIntentData::DISPOSITION_WINDOW, intents[1].disposition); 155 EXPECT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, intents[1].disposition);
156 } 156 }
157 } // namespace 157 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_intents_table.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698