| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // once it finishes fetching the local storage data. | 64 // once it finishes fetching the local storage data. |
| 65 class StopTestOnCallback { | 65 class StopTestOnCallback { |
| 66 public: | 66 public: |
| 67 explicit StopTestOnCallback( | 67 explicit StopTestOnCallback( |
| 68 BrowsingDataLocalStorageHelper* local_storage_helper) | 68 BrowsingDataLocalStorageHelper* local_storage_helper) |
| 69 : local_storage_helper_(local_storage_helper) { | 69 : local_storage_helper_(local_storage_helper) { |
| 70 DCHECK(local_storage_helper_); | 70 DCHECK(local_storage_helper_); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void Callback( | 73 void Callback( |
| 74 const std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo>& | 74 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& |
| 75 local_storage_info) { | 75 local_storage_info) { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 // There's no guarantee on the order, ensure these files are there. | 77 // There's no guarantee on the order, ensure these files are there. |
| 78 const char* const kTestHosts[] = {"www.chromium.org", "www.google.com"}; | 78 const char* const kTestHosts[] = {"www.chromium.org", "www.google.com"}; |
| 79 bool test_hosts_found[arraysize(kTestHosts)] = {false, false}; | 79 bool test_hosts_found[arraysize(kTestHosts)] = {false, false}; |
| 80 ASSERT_EQ(arraysize(kTestHosts), local_storage_info.size()); | 80 ASSERT_EQ(arraysize(kTestHosts), local_storage_info.size()); |
| 81 typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> |
| 82 LocalStorageInfoList; |
| 81 for (size_t i = 0; i < arraysize(kTestHosts); ++i) { | 83 for (size_t i = 0; i < arraysize(kTestHosts); ++i) { |
| 82 for (size_t j = 0; j < local_storage_info.size(); ++j) { | 84 for (LocalStorageInfoList::const_iterator info = |
| 83 BrowsingDataLocalStorageHelper::LocalStorageInfo info = | 85 local_storage_info.begin(); info != local_storage_info.end(); |
| 84 local_storage_info.at(j); | 86 ++info) { |
| 85 ASSERT_EQ("http", info.protocol); | 87 ASSERT_EQ("http", info->protocol); |
| 86 if (info.host == kTestHosts[i]) { | 88 if (info->host == kTestHosts[i]) { |
| 87 ASSERT_FALSE(test_hosts_found[i]); | 89 ASSERT_FALSE(test_hosts_found[i]); |
| 88 test_hosts_found[i] = true; | 90 test_hosts_found[i] = true; |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 } | 93 } |
| 92 for (size_t i = 0; i < arraysize(kTestHosts); ++i) { | 94 for (size_t i = 0; i < arraysize(kTestHosts); ++i) { |
| 93 ASSERT_TRUE(test_hosts_found[i]) << kTestHosts[i]; | 95 ASSERT_TRUE(test_hosts_found[i]) << kTestHosts[i]; |
| 94 } | 96 } |
| 95 MessageLoop::current()->Quit(); | 97 MessageLoop::current()->Quit(); |
| 96 } | 98 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 148 |
| 147 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | 149 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( |
| 148 new CannedBrowsingDataLocalStorageHelper(browser()->profile())); | 150 new CannedBrowsingDataLocalStorageHelper(browser()->profile())); |
| 149 helper->AddLocalStorage(origin1); | 151 helper->AddLocalStorage(origin1); |
| 150 helper->AddLocalStorage(origin2); | 152 helper->AddLocalStorage(origin2); |
| 151 | 153 |
| 152 TestCompletionCallback callback; | 154 TestCompletionCallback callback; |
| 153 helper->StartFetching( | 155 helper->StartFetching( |
| 154 NewCallback(&callback, &TestCompletionCallback::callback)); | 156 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 155 | 157 |
| 156 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | 158 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = |
| 157 callback.result(); | 159 callback.result(); |
| 158 | 160 |
| 159 ASSERT_EQ(2u, result.size()); | 161 ASSERT_EQ(2u, result.size()); |
| 160 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); | 162 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator info = |
| 161 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); | 163 result.begin(); |
| 164 EXPECT_EQ(FilePath(file1).value(), info->file_path.BaseName().value()); |
| 165 info++; |
| 166 EXPECT_EQ(FilePath(file2).value(), info->file_path.BaseName().value()); |
| 162 } | 167 } |
| 163 | 168 |
| 164 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) { | 169 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) { |
| 165 const GURL origin("http://host1:1/"); | 170 const GURL origin("http://host1:1/"); |
| 166 const FilePath::CharType file[] = | 171 const FilePath::CharType file[] = |
| 167 FILE_PATH_LITERAL("http_host1_1.localstorage"); | 172 FILE_PATH_LITERAL("http_host1_1.localstorage"); |
| 168 | 173 |
| 169 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | 174 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( |
| 170 new CannedBrowsingDataLocalStorageHelper(browser()->profile())); | 175 new CannedBrowsingDataLocalStorageHelper(browser()->profile())); |
| 171 helper->AddLocalStorage(origin); | 176 helper->AddLocalStorage(origin); |
| 172 helper->AddLocalStorage(origin); | 177 helper->AddLocalStorage(origin); |
| 173 | 178 |
| 174 TestCompletionCallback callback; | 179 TestCompletionCallback callback; |
| 175 helper->StartFetching( | 180 helper->StartFetching( |
| 176 NewCallback(&callback, &TestCompletionCallback::callback)); | 181 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 177 | 182 |
| 178 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | 183 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = |
| 179 callback.result(); | 184 callback.result(); |
| 180 | 185 |
| 181 ASSERT_EQ(1u, result.size()); | 186 ASSERT_EQ(1u, result.size()); |
| 182 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); | 187 EXPECT_EQ(FilePath(file).value(), |
| 188 result.begin()->file_path.BaseName().value()); |
| 183 } | 189 } |
| 184 } // namespace | 190 } // namespace |
| OLD | NEW |