OLD | NEW |
1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/test/thread_test_helper.h" | 20 #include "base/test/thread_test_helper.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/threading/thread_restrictions.h" |
22 #include "chrome/browser/browsing_data/browsing_data_helper_browsertest.h" | 23 #include "chrome/browser/browsing_data/browsing_data_helper_browsertest.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
26 #include "content/public/browser/dom_storage_context.h" | 27 #include "content/public/browser/dom_storage_context.h" |
27 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 | 30 |
30 using content::BrowserContext; | 31 using content::BrowserContext; |
31 using content::BrowserThread; | 32 using content::BrowserThread; |
(...skipping 15 matching lines...) Expand all Loading... |
47 const base::FilePath::CharType kTestFileInvalid[] = | 48 const base::FilePath::CharType kTestFileInvalid[] = |
48 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo"); | 49 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo"); |
49 | 50 |
50 // This is only here to test that extension state is not listed by the helper. | 51 // This is only here to test that extension state is not listed by the helper. |
51 const base::FilePath::CharType kTestFileExtension[] = FILE_PATH_LITERAL( | 52 const base::FilePath::CharType kTestFileExtension[] = FILE_PATH_LITERAL( |
52 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0.localstorage"); | 53 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0.localstorage"); |
53 | 54 |
54 class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest { | 55 class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest { |
55 protected: | 56 protected: |
56 void CreateLocalStorageFilesForTest() { | 57 void CreateLocalStorageFilesForTest() { |
| 58 base::ThreadRestrictions::ScopedAllowIO allow_io; |
57 // Note: This helper depends on details of how the dom_storage library | 59 // Note: This helper depends on details of how the dom_storage library |
58 // stores data in the host file system. | 60 // stores data in the host file system. |
59 base::FilePath storage_path = GetLocalStoragePathForTestingProfile(); | 61 base::FilePath storage_path = GetLocalStoragePathForTestingProfile(); |
60 base::CreateDirectory(storage_path); | 62 base::CreateDirectory(storage_path); |
61 const base::FilePath::CharType* kFilesToCreate[] = { | 63 const base::FilePath::CharType* kFilesToCreate[] = { |
62 kTestFile0, kTestFile1, kTestFileInvalid, kTestFileExtension | 64 kTestFile0, kTestFile1, kTestFileInvalid, kTestFileExtension |
63 }; | 65 }; |
64 for (size_t i = 0; i < arraysize(kFilesToCreate); ++i) { | 66 for (size_t i = 0; i < arraysize(kFilesToCreate); ++i) { |
65 base::FilePath file_path = storage_path.Append(kFilesToCreate[i]); | 67 base::FilePath file_path = storage_path.Append(kFilesToCreate[i]); |
66 base::WriteFile(file_path, nullptr, 0); | 68 base::WriteFile(file_path, nullptr, 0); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 123 } |
122 | 124 |
123 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, DeleteSingleFile) { | 125 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, DeleteSingleFile) { |
124 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( | 126 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( |
125 new BrowsingDataLocalStorageHelper(browser()->profile())); | 127 new BrowsingDataLocalStorageHelper(browser()->profile())); |
126 CreateLocalStorageFilesForTest(); | 128 CreateLocalStorageFilesForTest(); |
127 local_storage_helper->DeleteOrigin(GURL(kOriginOfTestFile0)); | 129 local_storage_helper->DeleteOrigin(GURL(kOriginOfTestFile0)); |
128 content::RunAllBlockingPoolTasksUntilIdle(); | 130 content::RunAllBlockingPoolTasksUntilIdle(); |
129 | 131 |
130 // Ensure the file has been deleted. | 132 // Ensure the file has been deleted. |
| 133 base::ThreadRestrictions::ScopedAllowIO allow_io; |
131 base::FileEnumerator file_enumerator( | 134 base::FileEnumerator file_enumerator( |
132 GetLocalStoragePathForTestingProfile(), | 135 GetLocalStoragePathForTestingProfile(), |
133 false, | 136 false, |
134 base::FileEnumerator::FILES); | 137 base::FileEnumerator::FILES); |
135 int num_files = 0; | 138 int num_files = 0; |
136 for (base::FilePath file_path = file_enumerator.Next(); | 139 for (base::FilePath file_path = file_enumerator.Next(); |
137 !file_path.empty(); | 140 !file_path.empty(); |
138 file_path = file_enumerator.Next()) { | 141 file_path = file_enumerator.Next()) { |
139 ASSERT_FALSE(base::FilePath(kTestFile0) == file_path.BaseName()); | 142 ASSERT_FALSE(base::FilePath(kTestFile0) == file_path.BaseName()); |
140 ++num_files; | 143 ++num_files; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 base::Bind(&TestCompletionCallback::callback, | 184 base::Bind(&TestCompletionCallback::callback, |
182 base::Unretained(&callback))); | 185 base::Unretained(&callback))); |
183 | 186 |
184 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | 187 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = |
185 callback.result(); | 188 callback.result(); |
186 | 189 |
187 ASSERT_EQ(1u, result.size()); | 190 ASSERT_EQ(1u, result.size()); |
188 EXPECT_EQ(origin, result.begin()->origin_url); | 191 EXPECT_EQ(origin, result.begin()->origin_url); |
189 } | 192 } |
190 } // namespace | 193 } // namespace |
OLD | NEW |