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

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

Issue 3178001: Delete callbacks after use in canned browsing data helpers. (Closed)
Patch Set: Created 10 years, 4 months 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
OLDNEW
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 {
11 class TestCompletionCallback 11 class TestCompletionCallback {
12 : public CallbackRunner<Tuple1<const std::vector<
13 BrowsingDataLocalStorageHelper::LocalStorageInfo>& > > {
14 public: 12 public:
15 TestCompletionCallback() 13 TestCompletionCallback()
16 : have_result_(false) { 14 : have_result_(false) {
17 } 15 }
18 16
19 bool have_result() const { return have_result_; } 17 bool have_result() const { return have_result_; }
20 18
21 const std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo>& result() 19 const std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo>& result()
22 { 20 {
23 return result_; 21 return result_;
24 } 22 }
25 23
26 virtual void RunWithParams( 24 void callback(const std::vector<
27 const Tuple1<const std::vector< 25 BrowsingDataLocalStorageHelper::LocalStorageInfo>& info) {
28 BrowsingDataLocalStorageHelper::LocalStorageInfo>& >& params) {
29 have_result_ = true; 26 have_result_ = true;
30 result_ = params.a; 27 result_ = info;
31 } 28 }
32 29
33 private: 30 private:
34 bool have_result_; 31 bool have_result_;
35 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result_; 32 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result_;
36 33
37 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); 34 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback);
38 }; 35 };
39 } // namespace 36 } // namespace
40 37
41 TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) { 38 TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) {
42 TestingProfile profile; 39 TestingProfile profile;
43 40
44 const GURL origin1("http://host1:1/"); 41 const GURL origin1("http://host1:1/");
45 const GURL origin2("http://host2:1/"); 42 const GURL origin2("http://host2:1/");
46 const FilePath::CharType file1[] = 43 const FilePath::CharType file1[] =
47 FILE_PATH_LITERAL("http_host1_1.localstorage"); 44 FILE_PATH_LITERAL("http_host1_1.localstorage");
48 const FilePath::CharType file2[] = 45 const FilePath::CharType file2[] =
49 FILE_PATH_LITERAL("http_host2_1.localstorage"); 46 FILE_PATH_LITERAL("http_host2_1.localstorage");
50 47
51 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = 48 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper =
52 new CannedBrowsingDataLocalStorageHelper(&profile); 49 new CannedBrowsingDataLocalStorageHelper(&profile);
53 helper->AddLocalStorage(origin1); 50 helper->AddLocalStorage(origin1);
54 helper->AddLocalStorage(origin2); 51 helper->AddLocalStorage(origin2);
55 52
56 TestCompletionCallback callback; 53 TestCompletionCallback callback;
57 helper->StartFetching(&callback); 54 helper->StartFetching(
55 NewCallback(&callback, &TestCompletionCallback::callback));
58 ASSERT_TRUE(callback.have_result()); 56 ASSERT_TRUE(callback.have_result());
59 57
60 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = 58 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
61 callback.result(); 59 callback.result();
62 60
63 ASSERT_EQ(2u, result.size()); 61 ASSERT_EQ(2u, result.size());
64 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); 62 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value());
65 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); 63 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value());
66 } 64 }
67 65
68 TEST(CannedBrowsingDataLocalStorageTest, Unique) { 66 TEST(CannedBrowsingDataLocalStorageTest, Unique) {
69 TestingProfile profile; 67 TestingProfile profile;
70 68
71 const GURL origin("http://host1:1/"); 69 const GURL origin("http://host1:1/");
72 const FilePath::CharType file[] = 70 const FilePath::CharType file[] =
73 FILE_PATH_LITERAL("http_host1_1.localstorage"); 71 FILE_PATH_LITERAL("http_host1_1.localstorage");
74 72
75 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = 73 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper =
76 new CannedBrowsingDataLocalStorageHelper(&profile); 74 new CannedBrowsingDataLocalStorageHelper(&profile);
77 helper->AddLocalStorage(origin); 75 helper->AddLocalStorage(origin);
78 helper->AddLocalStorage(origin); 76 helper->AddLocalStorage(origin);
79 77
80 TestCompletionCallback callback; 78 TestCompletionCallback callback;
81 helper->StartFetching(&callback); 79 helper->StartFetching(
80 NewCallback(&callback, &TestCompletionCallback::callback));
82 ASSERT_TRUE(callback.have_result()); 81 ASSERT_TRUE(callback.have_result());
83 82
84 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = 83 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
85 callback.result(); 84 callback.result();
86 85
87 ASSERT_EQ(1u, result.size()); 86 ASSERT_EQ(1u, result.size());
88 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); 87 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value());
89 } 88 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_local_storage_helper.cc ('k') | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698