| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 8 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
| 9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 13 | 10 |
| 14 namespace { | 11 namespace { |
| 15 | 12 |
| 16 class TestCompletionCallback { | |
| 17 public: | |
| 18 TestCompletionCallback() : has_result_(false) {} | |
| 19 | |
| 20 bool has_result() const { return has_result_; } | |
| 21 | |
| 22 const std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo>& result() { | |
| 23 return result_; | |
| 24 } | |
| 25 | |
| 26 void callback( | |
| 27 const std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo>& info) { | |
| 28 has_result_ = true; | |
| 29 result_ = info; | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 bool has_result_; | |
| 34 std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result_; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); | |
| 37 }; | |
| 38 | |
| 39 // Functionality incomplete, needs further refactoring, http://crbug.com/60532. | |
| 40 TEST(CannedBrowsingDataIndexedDBHelperTest, DISABLED_AddIndexedDB) { | |
| 41 TestingProfile profile; | |
| 42 | |
| 43 const GURL origin1("http://host1:1/"); | |
| 44 const GURL origin2("http://host2:1/"); | |
| 45 const string16 description(ASCIIToUTF16("description")); | |
| 46 const FilePath::CharType file1[] = | |
| 47 FILE_PATH_LITERAL("http_host1_1.indexeddb"); | |
| 48 const FilePath::CharType file2[] = | |
| 49 FILE_PATH_LITERAL("http_host2_1.indexeddb"); | |
| 50 | |
| 51 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( | |
| 52 new CannedBrowsingDataIndexedDBHelper(&profile)); | |
| 53 helper->AddIndexedDB(origin1, description); | |
| 54 helper->AddIndexedDB(origin2, description); | |
| 55 | |
| 56 TestCompletionCallback callback; | |
| 57 helper->StartFetching( | |
| 58 NewCallback(&callback, &TestCompletionCallback::callback)); | |
| 59 ASSERT_TRUE(callback.has_result()); | |
| 60 | |
| 61 std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result = | |
| 62 callback.result(); | |
| 63 | |
| 64 ASSERT_EQ(2U, result.size()); | |
| 65 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); | |
| 66 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); | |
| 67 } | |
| 68 | |
| 69 // Functionality incomplete, needs further refactoring, http://crbug.com/60532. | |
| 70 TEST(CannedBrowsingDataIndexedDBHelperTest, DISABLED_Unique) { | |
| 71 TestingProfile profile; | |
| 72 | |
| 73 const GURL origin("http://host1:1/"); | |
| 74 const string16 description(ASCIIToUTF16("description")); | |
| 75 const FilePath::CharType file[] = | |
| 76 FILE_PATH_LITERAL("http_host1_1.indexeddb"); | |
| 77 | |
| 78 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( | |
| 79 new CannedBrowsingDataIndexedDBHelper(&profile)); | |
| 80 helper->AddIndexedDB(origin, description); | |
| 81 helper->AddIndexedDB(origin, description); | |
| 82 | |
| 83 TestCompletionCallback callback; | |
| 84 helper->StartFetching( | |
| 85 NewCallback(&callback, &TestCompletionCallback::callback)); | |
| 86 ASSERT_TRUE(callback.has_result()); | |
| 87 | |
| 88 std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result = | |
| 89 callback.result(); | |
| 90 | |
| 91 ASSERT_EQ(1U, result.size()); | |
| 92 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); | |
| 93 } | |
| 94 | |
| 95 TEST(CannedBrowsingDataIndexedDBHelperTest, Empty) { | 13 TEST(CannedBrowsingDataIndexedDBHelperTest, Empty) { |
| 96 TestingProfile profile; | 14 TestingProfile profile; |
| 97 | 15 |
| 98 const GURL origin("http://host1:1/"); | 16 const GURL origin("http://host1:1/"); |
| 99 const string16 description(ASCIIToUTF16("description")); | 17 const string16 description(ASCIIToUTF16("description")); |
| 100 | 18 |
| 101 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( | 19 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( |
| 102 new CannedBrowsingDataIndexedDBHelper(&profile)); | 20 new CannedBrowsingDataIndexedDBHelper(&profile)); |
| 103 | 21 |
| 104 ASSERT_TRUE(helper->empty()); | 22 ASSERT_TRUE(helper->empty()); |
| 105 helper->AddIndexedDB(origin, description); | 23 helper->AddIndexedDB(origin, description); |
| 106 ASSERT_FALSE(helper->empty()); | 24 ASSERT_FALSE(helper->empty()); |
| 107 helper->Reset(); | 25 helper->Reset(); |
| 108 ASSERT_TRUE(helper->empty()); | 26 ASSERT_TRUE(helper->empty()); |
| 109 } | 27 } |
| 110 | 28 |
| 111 } // namespace | 29 } // namespace |
| OLD | NEW |