Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: chrome/browser/browsing_data_local_storage_helper_browsertest.cc

Issue 8393036: base::Bind: Convert BrowsingDataLocalStorageHelper::StartFetching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h"
csilv 2011/10/26 17:40:56 add bind_helpers.h
James Hawkins 2011/10/26 22:59:40 Done.
8 #include "base/callback.h" 9 #include "base/callback.h"
9 #include "base/file_path.h" 10 #include "base/file_path.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/test/thread_test_helper.h" 13 #include "base/test/thread_test_helper.h"
13 #include "chrome/browser/browsing_data_helper_browsertest.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/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
17 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/browser/in_process_webkit/webkit_context.h" 20 #include "content/browser/in_process_webkit/webkit_context.h"
20 #include "content/browser/in_process_webkit/webkit_thread.h" 21 #include "content/browser/in_process_webkit/webkit_thread.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace { 24 namespace {
24 typedef 25 typedef
25 BrowsingDataHelperCallback<BrowsingDataLocalStorageHelper::LocalStorageInfo> 26 BrowsingDataHelperCallback<BrowsingDataLocalStorageHelper::LocalStorageInfo>
26 TestCompletionCallback; 27 TestCompletionCallback;
27 28
28 const FilePath::CharType kTestFile0[] = 29 const FilePath::CharType kTestFile0[] =
29 FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage"); 30 FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage");
30 31
31 const FilePath::CharType kTestFile1[] = 32 const FilePath::CharType kTestFile1[] =
32 FILE_PATH_LITERAL("http_www.google.com_0.localstorage"); 33 FILE_PATH_LITERAL("http_www.google.com_0.localstorage");
33 34
34 const FilePath::CharType kTestFileInvalid[] = 35 const FilePath::CharType kTestFileInvalid[] =
35 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo"); 36 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo");
36 37
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 private: 101 private:
101 BrowsingDataLocalStorageHelper* local_storage_helper_; 102 BrowsingDataLocalStorageHelper* local_storage_helper_;
102 }; 103 };
103 104
104 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CallbackCompletes) { 105 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CallbackCompletes) {
105 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 106 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
106 new BrowsingDataLocalStorageHelper(browser()->profile())); 107 new BrowsingDataLocalStorageHelper(browser()->profile()));
107 CreateLocalStorageFilesForTest(); 108 CreateLocalStorageFilesForTest();
108 StopTestOnCallback stop_test_on_callback(local_storage_helper); 109 StopTestOnCallback stop_test_on_callback(local_storage_helper);
109 local_storage_helper->StartFetching( 110 local_storage_helper->StartFetching(
110 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback)); 111 base::Bind(&StopTestOnCallback::Callback,
112 base::Unretained(&stop_test_on_callback)));
111 // Blocks until StopTestOnCallback::Callback is notified. 113 // Blocks until StopTestOnCallback::Callback is notified.
112 ui_test_utils::RunMessageLoop(); 114 ui_test_utils::RunMessageLoop();
113 } 115 }
114 116
115 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, DeleteSingleFile) { 117 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, DeleteSingleFile) {
116 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 118 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
117 new BrowsingDataLocalStorageHelper(browser()->profile())); 119 new BrowsingDataLocalStorageHelper(browser()->profile()));
118 CreateLocalStorageFilesForTest(); 120 CreateLocalStorageFilesForTest();
119 local_storage_helper->DeleteLocalStorageFile( 121 local_storage_helper->DeleteLocalStorageFile(
120 GetLocalStoragePathForTestingProfile().Append(FilePath(kTestFile0))); 122 GetLocalStoragePathForTestingProfile().Append(FilePath(kTestFile0)));
(...skipping 25 matching lines...) Expand all
146 const FilePath::CharType file2[] = 148 const FilePath::CharType file2[] =
147 FILE_PATH_LITERAL("http_host2_1.localstorage"); 149 FILE_PATH_LITERAL("http_host2_1.localstorage");
148 150
149 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( 151 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper(
150 new CannedBrowsingDataLocalStorageHelper(browser()->profile())); 152 new CannedBrowsingDataLocalStorageHelper(browser()->profile()));
151 helper->AddLocalStorage(origin1); 153 helper->AddLocalStorage(origin1);
152 helper->AddLocalStorage(origin2); 154 helper->AddLocalStorage(origin2);
153 155
154 TestCompletionCallback callback; 156 TestCompletionCallback callback;
155 helper->StartFetching( 157 helper->StartFetching(
156 NewCallback(&callback, &TestCompletionCallback::callback)); 158 base::Bind(&TestCompletionCallback::callback,
159 base::Unretained(&callback)));
157 160
158 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = 161 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
159 callback.result(); 162 callback.result();
160 163
161 ASSERT_EQ(2u, result.size()); 164 ASSERT_EQ(2u, result.size());
162 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator info = 165 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator info =
163 result.begin(); 166 result.begin();
164 EXPECT_EQ(FilePath(file1).value(), info->file_path.BaseName().value()); 167 EXPECT_EQ(FilePath(file1).value(), info->file_path.BaseName().value());
165 info++; 168 info++;
166 EXPECT_EQ(FilePath(file2).value(), info->file_path.BaseName().value()); 169 EXPECT_EQ(FilePath(file2).value(), info->file_path.BaseName().value());
167 } 170 }
168 171
169 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) { 172 IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) {
170 const GURL origin("http://host1:1/"); 173 const GURL origin("http://host1:1/");
171 const FilePath::CharType file[] = 174 const FilePath::CharType file[] =
172 FILE_PATH_LITERAL("http_host1_1.localstorage"); 175 FILE_PATH_LITERAL("http_host1_1.localstorage");
173 176
174 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( 177 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper(
175 new CannedBrowsingDataLocalStorageHelper(browser()->profile())); 178 new CannedBrowsingDataLocalStorageHelper(browser()->profile()));
176 helper->AddLocalStorage(origin); 179 helper->AddLocalStorage(origin);
177 helper->AddLocalStorage(origin); 180 helper->AddLocalStorage(origin);
178 181
179 TestCompletionCallback callback; 182 TestCompletionCallback callback;
180 helper->StartFetching( 183 helper->StartFetching(
181 NewCallback(&callback, &TestCompletionCallback::callback)); 184 base::Bind(&TestCompletionCallback::callback,
185 base::Unretained(&callback)));
182 186
183 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = 187 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
184 callback.result(); 188 callback.result();
185 189
186 ASSERT_EQ(1u, result.size()); 190 ASSERT_EQ(1u, result.size());
187 EXPECT_EQ(FilePath(file).value(), 191 EXPECT_EQ(FilePath(file).value(),
188 result.begin()->file_path.BaseName().value()); 192 result.begin()->file_path.BaseName().value());
189 } 193 }
190 } // namespace 194 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_local_storage_helper.cc ('k') | chrome/browser/cookies_tree_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698