OLD | NEW |
---|---|
1 // Copyright (c) 2009 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" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "chrome/browser/in_process_webkit/webkit_context.h" | 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
13 #include "chrome/browser/in_process_webkit/webkit_thread.h" | 13 #include "chrome/browser/in_process_webkit/webkit_thread.h" |
14 #include "chrome/browser/browsing_data_helper_browsertest.h" | |
14 #include "chrome/browser/browsing_data_local_storage_helper.h" | 15 #include "chrome/browser/browsing_data_local_storage_helper.h" |
15 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
16 #include "chrome/test/testing_profile.h" | 17 #include "chrome/test/testing_profile.h" |
17 #include "chrome/test/thread_test_helper.h" | 18 #include "chrome/test/thread_test_helper.h" |
18 #include "chrome/test/ui_test_utils.h" | 19 #include "chrome/test/ui_test_utils.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 static const FilePath::CharType kTestFile0[] = | 22 namespace { |
23 typedef | |
24 BrowsingDataHelperCallback<BrowsingDataLocalStorageHelper::LocalStorageInfo> | |
Bernhard Bauer
2011/02/10 12:51:09
Nit: Maybe |using BrowsingDataLocalStorageHelper::
| |
25 TestCompletionCallback; | |
26 | |
27 const FilePath::CharType kTestFile0[] = | |
22 FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage"); | 28 FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage"); |
23 | 29 |
24 static const FilePath::CharType kTestFile1[] = | 30 const FilePath::CharType kTestFile1[] = |
25 FILE_PATH_LITERAL("http_www.google.com_0.localstorage"); | 31 FILE_PATH_LITERAL("http_www.google.com_0.localstorage"); |
26 | 32 |
27 static const FilePath::CharType kTestFileInvalid[] = | 33 const FilePath::CharType kTestFileInvalid[] = |
28 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo"); | 34 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo"); |
29 | 35 |
30 // This is only here to test that extension state is not listed by the helper. | 36 // This is only here to test that extension state is not listed by the helper. |
31 static const FilePath::CharType kTestFileExtension[] = FILE_PATH_LITERAL( | 37 const FilePath::CharType kTestFileExtension[] = FILE_PATH_LITERAL( |
32 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0.localstorage"); | 38 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0.localstorage"); |
33 | 39 |
34 | |
35 class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest { | 40 class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest { |
36 protected: | 41 protected: |
37 void CreateLocalStorageFilesForTest() { | 42 void CreateLocalStorageFilesForTest() { |
38 FilePath storage_path = GetLocalStoragePathForTestingProfile(); | 43 FilePath storage_path = GetLocalStoragePathForTestingProfile(); |
39 file_util::CreateDirectory(storage_path); | 44 file_util::CreateDirectory(storage_path); |
40 const FilePath::CharType* kFilesToCreate[] = { | 45 const FilePath::CharType* kFilesToCreate[] = { |
41 kTestFile0, kTestFile1, kTestFileInvalid, kTestFileExtension | 46 kTestFile0, kTestFile1, kTestFileInvalid, kTestFileExtension |
42 }; | 47 }; |
43 for (size_t i = 0; i < arraysize(kFilesToCreate); ++i) { | 48 for (size_t i = 0; i < arraysize(kFilesToCreate); ++i) { |
44 FilePath file_path = storage_path.Append(kFilesToCreate[i]); | 49 FilePath file_path = storage_path.Append(kFilesToCreate[i]); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 file_util::FileEnumerator::FILES); | 126 file_util::FileEnumerator::FILES); |
122 int num_files = 0; | 127 int num_files = 0; |
123 for (FilePath file_path = file_enumerator.Next(); | 128 for (FilePath file_path = file_enumerator.Next(); |
124 !file_path.empty(); | 129 !file_path.empty(); |
125 file_path = file_enumerator.Next()) { | 130 file_path = file_enumerator.Next()) { |
126 ASSERT_FALSE(FilePath(kTestFile0) == file_path.BaseName()); | 131 ASSERT_FALSE(FilePath(kTestFile0) == file_path.BaseName()); |
127 ++num_files; | 132 ++num_files; |
128 } | 133 } |
129 ASSERT_EQ(3, num_files); | 134 ASSERT_EQ(3, num_files); |
130 } | 135 } |
136 | |
137 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, | |
138 CannedAddLocalStorage) { | |
139 const GURL origin1("http://host1:1/"); | |
140 const GURL origin2("http://host2:1/"); | |
141 const FilePath::CharType file1[] = | |
142 FILE_PATH_LITERAL("http_host1_1.localstorage"); | |
143 const FilePath::CharType file2[] = | |
144 FILE_PATH_LITERAL("http_host2_1.localstorage"); | |
145 | |
146 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | |
147 new CannedBrowsingDataLocalStorageHelper(&testing_profile_)); | |
148 helper->AddLocalStorage(origin1); | |
149 helper->AddLocalStorage(origin2); | |
150 | |
151 TestCompletionCallback callback; | |
152 helper->StartFetching( | |
153 NewCallback(&callback, &TestCompletionCallback::callback)); | |
154 | |
155 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | |
156 callback.result(); | |
157 | |
158 ASSERT_EQ(2u, result.size()); | |
159 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); | |
160 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); | |
161 } | |
162 | |
163 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) { | |
164 const GURL origin("http://host1:1/"); | |
165 const FilePath::CharType file[] = | |
166 FILE_PATH_LITERAL("http_host1_1.localstorage"); | |
167 | |
168 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | |
169 new CannedBrowsingDataLocalStorageHelper(&testing_profile_)); | |
170 helper->AddLocalStorage(origin); | |
171 helper->AddLocalStorage(origin); | |
172 | |
173 TestCompletionCallback callback; | |
174 helper->StartFetching( | |
175 NewCallback(&callback, &TestCompletionCallback::callback)); | |
176 | |
177 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | |
178 callback.result(); | |
179 | |
180 ASSERT_EQ(1u, result.size()); | |
181 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); | |
182 } | |
183 } // namespace | |
OLD | NEW |