| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <string> |
| 7 #include <vector> |
| 6 | 8 |
| 7 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 8 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 9 #include "base/string16.h" | 11 #include "base/string16.h" |
| 10 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/intents/default_web_intent_service.h" |
| 11 #include "chrome/browser/webdata/web_database.h" | 14 #include "chrome/browser/webdata/web_database.h" |
| 12 #include "chrome/browser/webdata/web_intents_table.h" | 15 #include "chrome/browser/webdata/web_intents_table.h" |
| 13 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 14 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webkit/glue/web_intent_service_data.h" | 19 #include "webkit/glue/web_intent_service_data.h" |
| 17 | 20 |
| 18 using webkit_glue::WebIntentServiceData; | 21 using webkit_glue::WebIntentServiceData; |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 UTF8ToUTF16(test_url_fake.spec()), &intents)); | 178 UTF8ToUTF16(test_url_fake.spec()), &intents)); |
| 176 EXPECT_EQ(0U, intents.size()); | 179 EXPECT_EQ(0U, intents.size()); |
| 177 | 180 |
| 178 intent.action = test_action_2; | 181 intent.action = test_action_2; |
| 179 ASSERT_TRUE(IntentsTable()->SetWebIntentService(intent)); | 182 ASSERT_TRUE(IntentsTable()->SetWebIntentService(intent)); |
| 180 EXPECT_TRUE(IntentsTable()->GetWebIntentServicesForURL( | 183 EXPECT_TRUE(IntentsTable()->GetWebIntentServicesForURL( |
| 181 UTF8ToUTF16(test_url.spec()), &intents)); | 184 UTF8ToUTF16(test_url.spec()), &intents)); |
| 182 ASSERT_EQ(2U, intents.size()); | 185 ASSERT_EQ(2U, intents.size()); |
| 183 } | 186 } |
| 184 | 187 |
| 188 TEST_F(WebIntentsTableTest, DefaultServices) { |
| 189 DefaultWebIntentService default_service; |
| 190 default_service.action = test_action; |
| 191 default_service.type = mime_image; |
| 192 default_service.url_pattern.Parse(test_url.spec()); |
| 193 default_service.user_date = 1; |
| 194 default_service.suppression = 4; |
| 195 default_service.service_url = "service_url"; |
| 196 ASSERT_TRUE(IntentsTable()->SetDefaultService(default_service)); |
| 197 |
| 198 default_service.action = test_action_2; |
| 199 ASSERT_TRUE(IntentsTable()->SetDefaultService(default_service)); |
| 200 |
| 201 std::vector<DefaultWebIntentService> defaults; |
| 202 ASSERT_TRUE(IntentsTable()->GetDefaultServices(ASCIIToUTF16("no_action"), |
| 203 &defaults)); |
| 204 EXPECT_EQ(0U, defaults.size()); |
| 205 |
| 206 ASSERT_TRUE(IntentsTable()->GetDefaultServices(test_action, &defaults)); |
| 207 ASSERT_EQ(1U, defaults.size()); |
| 208 |
| 209 EXPECT_EQ(test_action, defaults[0].action); |
| 210 EXPECT_EQ(mime_image, defaults[0].type); |
| 211 URLPattern test_pattern(URLPattern::SCHEME_HTTP, test_url.spec()); |
| 212 EXPECT_EQ(test_pattern, defaults[0].url_pattern); |
| 213 EXPECT_EQ(1, defaults[0].user_date); |
| 214 EXPECT_EQ(4, defaults[0].suppression); |
| 215 EXPECT_EQ("service_url", defaults[0].service_url); |
| 216 |
| 217 defaults.clear(); |
| 218 ASSERT_TRUE(IntentsTable()->GetAllDefaultServices(&defaults)); |
| 219 ASSERT_EQ(2U, defaults.size()); |
| 220 |
| 221 default_service.action = test_action; |
| 222 IntentsTable()->RemoveDefaultService(default_service); |
| 223 |
| 224 defaults.clear(); |
| 225 ASSERT_TRUE(IntentsTable()->GetDefaultServices(test_action, &defaults)); |
| 226 ASSERT_EQ(0U, defaults.size()); |
| 227 |
| 228 defaults.clear(); |
| 229 ASSERT_TRUE(IntentsTable()->GetDefaultServices(test_action_2, &defaults)); |
| 230 ASSERT_EQ(1U, defaults.size()); |
| 231 |
| 232 defaults.clear(); |
| 233 ASSERT_TRUE(IntentsTable()->GetAllDefaultServices(&defaults)); |
| 234 ASSERT_EQ(1U, defaults.size()); |
| 235 } |
| 236 |
| 185 } // namespace | 237 } // namespace |
| OLD | NEW |