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/extensions/api/browsing_data/browsing_data_api.h" | 5 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // We're not taking ownership of the details object, but storing a copy of | 68 // We're not taking ownership of the details object, but storing a copy of |
69 // it locally. | 69 // it locally. |
70 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( | 70 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
71 *content::Details<BrowsingDataRemover::NotificationDetails>( | 71 *content::Details<BrowsingDataRemover::NotificationDetails>( |
72 details).ptr())); | 72 details).ptr())); |
73 } | 73 } |
74 | 74 |
75 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 75 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
76 const std::string& key, | 76 const std::string& key, |
77 int expected_mask) { | 77 int expected_mask) { |
| 78 scoped_refptr<RemoveBrowsingDataFunction> function = |
| 79 new RemoveBrowsingDataFunction(); |
78 SCOPED_TRACE(key); | 80 SCOPED_TRACE(key); |
79 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( | 81 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
80 new RemoveBrowsingDataFunction(), | 82 function.get(), |
81 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", | 83 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", |
82 browser())); | 84 browser())); |
83 EXPECT_EQ(expected_mask, GetRemovalMask()); | 85 EXPECT_EQ(expected_mask, GetRemovalMask()); |
84 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 86 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
85 } | 87 } |
86 | 88 |
87 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( | 89 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
88 const std::string& protectedStr, | 90 const std::string& protectedStr, |
89 int expected_mask) { | 91 int expected_mask) { |
| 92 scoped_refptr<RemoveBrowsingDataFunction> function = |
| 93 new RemoveBrowsingDataFunction(); |
90 SCOPED_TRACE(protectedStr); | 94 SCOPED_TRACE(protectedStr); |
91 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( | 95 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
92 new RemoveBrowsingDataFunction(), | 96 function.get(), |
93 "[{\"originType\": " + protectedStr + "}, {\"cookies\": true}]", | 97 "[{\"originType\": " + protectedStr + "}, {\"cookies\": true}]", |
94 browser())); | 98 browser())); |
95 EXPECT_EQ(expected_mask, GetOriginSetMask()); | 99 EXPECT_EQ(expected_mask, GetOriginSetMask()); |
96 } | 100 } |
97 | 101 |
98 private: | 102 private: |
99 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 103 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
100 content::NotificationRegistrar registrar_; | 104 content::NotificationRegistrar registrar_; |
101 }; | 105 }; |
102 | 106 |
103 } // namespace | 107 } // namespace |
104 | 108 |
105 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { | 109 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { |
106 BrowsingDataRemover::set_removing(true); | 110 BrowsingDataRemover::set_removing(true); |
| 111 scoped_refptr<RemoveBrowsingDataFunction> function = |
| 112 new RemoveBrowsingDataFunction(); |
107 EXPECT_TRUE(MatchPattern( | 113 EXPECT_TRUE(MatchPattern( |
108 RunFunctionAndReturnError( | 114 RunFunctionAndReturnError(function, |
109 new RemoveBrowsingDataFunction(), | 115 kRemoveEverythingArguments, |
110 kRemoveEverythingArguments, | 116 browser()), |
111 browser()), | |
112 extension_browsing_data_api_constants::kOneAtATimeError)); | 117 extension_browsing_data_api_constants::kOneAtATimeError)); |
113 BrowsingDataRemover::set_removing(false); | 118 BrowsingDataRemover::set_removing(false); |
114 | 119 |
115 EXPECT_EQ(base::Time(), GetBeginTime()); | 120 EXPECT_EQ(base::Time(), GetBeginTime()); |
116 EXPECT_EQ(-1, GetRemovalMask()); | 121 EXPECT_EQ(-1, GetRemovalMask()); |
117 } | 122 } |
118 | 123 |
119 // Use-after-free, see http://crbug.com/116522 | 124 // Use-after-free, see http://crbug.com/116522 |
120 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, | 125 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, |
121 DISABLED_RemoveBrowsingDataAll) { | 126 DISABLED_RemoveBrowsingDataAll) { |
122 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( | 127 scoped_refptr<RemoveBrowsingDataFunction> function = |
123 new RemoveBrowsingDataFunction(), | 128 new RemoveBrowsingDataFunction(); |
124 kRemoveEverythingArguments, | 129 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult(function.get(), |
125 browser())); | 130 kRemoveEverythingArguments, |
| 131 browser())); |
126 | 132 |
127 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); | 133 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); |
128 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | | 134 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | |
129 BrowsingDataRemover::REMOVE_CACHE | | 135 BrowsingDataRemover::REMOVE_CACHE | |
130 BrowsingDataRemover::REMOVE_DOWNLOADS | | 136 BrowsingDataRemover::REMOVE_DOWNLOADS | |
131 BrowsingDataRemover::REMOVE_FORM_DATA | | 137 BrowsingDataRemover::REMOVE_FORM_DATA | |
132 BrowsingDataRemover::REMOVE_HISTORY | | 138 BrowsingDataRemover::REMOVE_HISTORY | |
133 BrowsingDataRemover::REMOVE_PASSWORDS) & | 139 BrowsingDataRemover::REMOVE_PASSWORDS) & |
134 // We can't remove plugin data inside a test profile. | 140 // We can't remove plugin data inside a test profile. |
135 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); | 141 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 188 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
183 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); | 189 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); |
184 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 190 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
185 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); | 191 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); |
186 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 192 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
187 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); | 193 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); |
188 // We can't remove plugin data inside a test profile. | 194 // We can't remove plugin data inside a test profile. |
189 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 195 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
190 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); | 196 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); |
191 } | 197 } |
OLD | NEW |