OLD | NEW |
1 // Copyright (c) 2010 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 "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 { | |
12 public: | |
13 TestCompletionCallback() | |
14 : have_result_(false) { | |
15 } | |
16 | |
17 bool have_result() const { return have_result_; } | |
18 | |
19 const std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo>& result() | |
20 { | |
21 return result_; | |
22 } | |
23 | |
24 void callback(const std::vector< | |
25 BrowsingDataLocalStorageHelper::LocalStorageInfo>& info) { | |
26 have_result_ = true; | |
27 result_ = info; | |
28 } | |
29 | |
30 private: | |
31 bool have_result_; | |
32 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result_; | |
33 | |
34 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); | |
35 }; | |
36 } // namespace | |
37 | |
38 TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) { | |
39 TestingProfile profile; | |
40 | |
41 const GURL origin1("http://host1:1/"); | |
42 const GURL origin2("http://host2:1/"); | |
43 const FilePath::CharType file1[] = | |
44 FILE_PATH_LITERAL("http_host1_1.localstorage"); | |
45 const FilePath::CharType file2[] = | |
46 FILE_PATH_LITERAL("http_host2_1.localstorage"); | |
47 | |
48 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | |
49 new CannedBrowsingDataLocalStorageHelper(&profile)); | |
50 helper->AddLocalStorage(origin1); | |
51 helper->AddLocalStorage(origin2); | |
52 | |
53 TestCompletionCallback callback; | |
54 helper->StartFetching( | |
55 NewCallback(&callback, &TestCompletionCallback::callback)); | |
56 ASSERT_TRUE(callback.have_result()); | |
57 | |
58 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | |
59 callback.result(); | |
60 | |
61 ASSERT_EQ(2u, result.size()); | |
62 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); | |
63 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); | |
64 } | |
65 | |
66 TEST(CannedBrowsingDataLocalStorageTest, Unique) { | |
67 TestingProfile profile; | |
68 | |
69 const GURL origin("http://host1:1/"); | |
70 const FilePath::CharType file[] = | |
71 FILE_PATH_LITERAL("http_host1_1.localstorage"); | |
72 | |
73 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | |
74 new CannedBrowsingDataLocalStorageHelper(&profile)); | |
75 helper->AddLocalStorage(origin); | |
76 helper->AddLocalStorage(origin); | |
77 | |
78 TestCompletionCallback callback; | |
79 helper->StartFetching( | |
80 NewCallback(&callback, &TestCompletionCallback::callback)); | |
81 ASSERT_TRUE(callback.have_result()); | |
82 | |
83 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = | |
84 callback.result(); | |
85 | |
86 ASSERT_EQ(1u, result.size()); | |
87 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); | |
88 } | |
89 | |
90 TEST(CannedBrowsingDataLocalStorageTest, Empty) { | 11 TEST(CannedBrowsingDataLocalStorageTest, Empty) { |
91 TestingProfile profile; | 12 TestingProfile profile; |
92 | 13 |
93 const GURL origin("http://host1:1/"); | 14 const GURL origin("http://host1:1/"); |
94 | 15 |
95 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( | 16 scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper( |
96 new CannedBrowsingDataLocalStorageHelper(&profile)); | 17 new CannedBrowsingDataLocalStorageHelper(&profile)); |
97 | 18 |
98 ASSERT_TRUE(helper->empty()); | 19 ASSERT_TRUE(helper->empty()); |
99 helper->AddLocalStorage(origin); | 20 helper->AddLocalStorage(origin); |
100 ASSERT_FALSE(helper->empty()); | 21 ASSERT_FALSE(helper->empty()); |
101 helper->Reset(); | 22 helper->Reset(); |
102 ASSERT_TRUE(helper->empty()); | 23 ASSERT_TRUE(helper->empty()); |
103 } | 24 } |
| 25 } // namespace |
OLD | NEW |