| 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 "chrome/browser/browsing_data_local_storage_helper.h" | 5 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 6 | 6 |
| 7 #include "chrome/test/testing_profile.h" | 7 #include "chrome/test/testing_profile.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) { | 38 TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) { |
| 39 TestingProfile profile; | 39 TestingProfile profile; |
| 40 | 40 |
| 41 const GURL origin1("http://host1:1/"); | 41 const GURL origin1("http://host1:1/"); |
| 42 const GURL origin2("http://host2:1/"); | 42 const GURL origin2("http://host2:1/"); |
| 43 const FilePath::CharType file1[] = | 43 const FilePath::CharType file1[] = |
| 44 FILE_PATH_LITERAL("http_host1_1.localstorage"); | 44 FILE_PATH_LITERAL("http_host1_1.localstorage"); |
| 45 const FilePath::CharType file2[] = | 45 const FilePath::CharType file2[] = |
| 46 FILE_PATH_LITERAL("http_host2_1.localstorage"); | 46 FILE_PATH_LITERAL("http_host2_1.localstorage"); |
| 47 | 47 |
| 48 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = | 48 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( |
| 49 new CannedBrowsingDataLocalStorageHelper(&profile); | 49 new CannedBrowsingDataLocalStorageHelper(&profile)); |
| 50 helper->AddLocalStorage(origin1); | 50 helper->AddLocalStorage(origin1); |
| 51 helper->AddLocalStorage(origin2); | 51 helper->AddLocalStorage(origin2); |
| 52 | 52 |
| 53 TestCompletionCallback callback; | 53 TestCompletionCallback callback; |
| 54 helper->StartFetching( | 54 helper->StartFetching( |
| 55 NewCallback(&callback, &TestCompletionCallback::callback)); | 55 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 56 ASSERT_TRUE(callback.have_result()); | 56 ASSERT_TRUE(callback.have_result()); |
| 57 | 57 |
| 58 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | 58 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = |
| 59 callback.result(); | 59 callback.result(); |
| 60 | 60 |
| 61 ASSERT_EQ(2u, result.size()); | 61 ASSERT_EQ(2u, result.size()); |
| 62 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); | 62 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); |
| 63 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); | 63 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST(CannedBrowsingDataLocalStorageTest, Unique) { | 66 TEST(CannedBrowsingDataLocalStorageTest, Unique) { |
| 67 TestingProfile profile; | 67 TestingProfile profile; |
| 68 | 68 |
| 69 const GURL origin("http://host1:1/"); | 69 const GURL origin("http://host1:1/"); |
| 70 const FilePath::CharType file[] = | 70 const FilePath::CharType file[] = |
| 71 FILE_PATH_LITERAL("http_host1_1.localstorage"); | 71 FILE_PATH_LITERAL("http_host1_1.localstorage"); |
| 72 | 72 |
| 73 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = | 73 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( |
| 74 new CannedBrowsingDataLocalStorageHelper(&profile); | 74 new CannedBrowsingDataLocalStorageHelper(&profile)); |
| 75 helper->AddLocalStorage(origin); | 75 helper->AddLocalStorage(origin); |
| 76 helper->AddLocalStorage(origin); | 76 helper->AddLocalStorage(origin); |
| 77 | 77 |
| 78 TestCompletionCallback callback; | 78 TestCompletionCallback callback; |
| 79 helper->StartFetching( | 79 helper->StartFetching( |
| 80 NewCallback(&callback, &TestCompletionCallback::callback)); | 80 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 81 ASSERT_TRUE(callback.have_result()); | 81 ASSERT_TRUE(callback.have_result()); |
| 82 | 82 |
| 83 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | 83 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = |
| 84 callback.result(); | 84 callback.result(); |
| 85 | 85 |
| 86 ASSERT_EQ(1u, result.size()); | 86 ASSERT_EQ(1u, result.size()); |
| 87 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); | 87 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST(CannedBrowsingDataLocalStorageTest, Empty) { | 90 TEST(CannedBrowsingDataLocalStorageTest, Empty) { |
| 91 TestingProfile profile; | 91 TestingProfile profile; |
| 92 | 92 |
| 93 const GURL origin("http://host1:1/"); | 93 const GURL origin("http://host1:1/"); |
| 94 | 94 |
| 95 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = | 95 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( |
| 96 new CannedBrowsingDataLocalStorageHelper(&profile); | 96 new CannedBrowsingDataLocalStorageHelper(&profile)); |
| 97 | 97 |
| 98 ASSERT_TRUE(helper->empty()); | 98 ASSERT_TRUE(helper->empty()); |
| 99 helper->AddLocalStorage(origin); | 99 helper->AddLocalStorage(origin); |
| 100 ASSERT_FALSE(helper->empty()); | 100 ASSERT_FALSE(helper->empty()); |
| 101 helper->Reset(); | 101 helper->Reset(); |
| 102 ASSERT_TRUE(helper->empty()); | 102 ASSERT_TRUE(helper->empty()); |
| 103 } | 103 } |
| OLD | NEW |