OLD | NEW |
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/webdata/web_database.h" | 11 #include "chrome/browser/webdata/web_database.h" |
12 #include "chrome/browser/webdata/web_intents_table.h" | 12 #include "chrome/browser/webdata/web_intents_table.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 GURL test_url("http://google.com/"); | 19 GURL test_url("http://google.com/"); |
20 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share"); | 20 string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share"); |
| 21 string16 test_action_2 = ASCIIToUTF16("http://webintents.org/intents/view"); |
21 string16 mime_image = ASCIIToUTF16("image/*"); | 22 string16 mime_image = ASCIIToUTF16("image/*"); |
22 string16 mime_video = ASCIIToUTF16("video/*"); | 23 string16 mime_video = ASCIIToUTF16("video/*"); |
23 | 24 |
24 class WebIntentsTableTest : public testing::Test { | 25 class WebIntentsTableTest : public testing::Test { |
25 protected: | 26 protected: |
26 virtual void SetUp() { | 27 virtual void SetUp() { |
27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
28 ASSERT_EQ(sql::INIT_OK, | 29 ASSERT_EQ(sql::INIT_OK, |
29 db_.Init(temp_dir_.path().AppendASCII("TestWebDatabase.db"))); | 30 db_.Init(temp_dir_.path().AppendASCII("TestWebDatabase.db"))); |
30 } | 31 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 86 |
86 // WebIntentsTable does not guarantee order, so ensure order here. | 87 // WebIntentsTable does not guarantee order, so ensure order here. |
87 if (intents[0].type == mime_video) | 88 if (intents[0].type == mime_video) |
88 std::swap(intents[0], intents[1]); | 89 std::swap(intents[0], intents[1]); |
89 | 90 |
90 EXPECT_EQ(intent, intents[1]); | 91 EXPECT_EQ(intent, intents[1]); |
91 | 92 |
92 intent.type = mime_image; | 93 intent.type = mime_image; |
93 EXPECT_EQ(intent, intents[0]); | 94 EXPECT_EQ(intent, intents[0]); |
94 } | 95 } |
| 96 |
| 97 // Test we support getting all intents independent of action. |
| 98 TEST_F(WebIntentsTableTest, GetAllIntents) { |
| 99 std::vector<WebIntentData> intents; |
| 100 |
| 101 WebIntentData intent; |
| 102 intent.service_url = test_url; |
| 103 intent.action = test_action; |
| 104 intent.type = mime_image; |
| 105 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); |
| 106 |
| 107 intent.action = test_action_2; |
| 108 EXPECT_TRUE(IntentsTable()->SetWebIntent(intent)); |
| 109 |
| 110 // Recover stored intents from DB. |
| 111 EXPECT_TRUE(IntentsTable()->GetAllWebIntents(&intents)); |
| 112 ASSERT_EQ(2U, intents.size()); |
| 113 |
| 114 // WebIntentsTable does not guarantee order, so ensure order here. |
| 115 if (intents[0].type == test_action_2) |
| 116 std::swap(intents[0], intents[1]); |
| 117 |
| 118 EXPECT_EQ(intent, intents[1]); |
| 119 |
| 120 intent.action = test_action; |
| 121 EXPECT_EQ(intent, intents[0]); |
| 122 } |
95 } // namespace | 123 } // namespace |
OLD | NEW |