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 <memory> |
5 #include <string> | 6 #include <string> |
6 | 7 |
7 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 14 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
15 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 15 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
17 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" | 17 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" |
18 #include "chrome/browser/extensions/extension_function_test_utils.h" | 18 #include "chrome/browser/extensions/extension_function_test_utils.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask()); | 129 EXPECT_EQ(UNPROTECTED_WEB, GetOriginTypeMask()); |
130 } | 130 } |
131 | 131 |
132 void SetSinceAndVerify(BrowsingDataRemover::TimePeriod since_pref) { | 132 void SetSinceAndVerify(BrowsingDataRemover::TimePeriod since_pref) { |
133 PrefService* prefs = browser()->profile()->GetPrefs(); | 133 PrefService* prefs = browser()->profile()->GetPrefs(); |
134 prefs->SetInteger(prefs::kDeleteTimePeriod, since_pref); | 134 prefs->SetInteger(prefs::kDeleteTimePeriod, since_pref); |
135 | 135 |
136 scoped_refptr<BrowsingDataSettingsFunction> function = | 136 scoped_refptr<BrowsingDataSettingsFunction> function = |
137 new BrowsingDataSettingsFunction(); | 137 new BrowsingDataSettingsFunction(); |
138 SCOPED_TRACE("settings"); | 138 SCOPED_TRACE("settings"); |
139 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( | 139 std::unique_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( |
140 function.get(), std::string("[]"), browser())); | 140 function.get(), std::string("[]"), browser())); |
141 | 141 |
142 base::DictionaryValue* result; | 142 base::DictionaryValue* result; |
143 EXPECT_TRUE(result_value->GetAsDictionary(&result)); | 143 EXPECT_TRUE(result_value->GetAsDictionary(&result)); |
144 base::DictionaryValue* options; | 144 base::DictionaryValue* options; |
145 EXPECT_TRUE(result->GetDictionary("options", &options)); | 145 EXPECT_TRUE(result->GetDictionary("options", &options)); |
146 double since; | 146 double since; |
147 EXPECT_TRUE(options->GetDouble("since", &since)); | 147 EXPECT_TRUE(options->GetDouble("since", &since)); |
148 | 148 |
149 double expected_since = 0; | 149 double expected_since = 0; |
(...skipping 28 matching lines...) Expand all Loading... |
178 !!(data_type_flags & | 178 !!(data_type_flags & |
179 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY)); | 179 BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY)); |
180 prefs->SetBoolean(prefs::kDeletePasswords, | 180 prefs->SetBoolean(prefs::kDeletePasswords, |
181 !!(data_type_flags & BrowsingDataRemover::REMOVE_PASSWORDS)); | 181 !!(data_type_flags & BrowsingDataRemover::REMOVE_PASSWORDS)); |
182 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, | 182 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, |
183 !!(data_type_flags & BrowsingDataRemover::REMOVE_PLUGIN_DATA)); | 183 !!(data_type_flags & BrowsingDataRemover::REMOVE_PLUGIN_DATA)); |
184 | 184 |
185 scoped_refptr<BrowsingDataSettingsFunction> function = | 185 scoped_refptr<BrowsingDataSettingsFunction> function = |
186 new BrowsingDataSettingsFunction(); | 186 new BrowsingDataSettingsFunction(); |
187 SCOPED_TRACE("settings"); | 187 SCOPED_TRACE("settings"); |
188 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( | 188 std::unique_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( |
189 function.get(), std::string("[]"), browser())); | 189 function.get(), std::string("[]"), browser())); |
190 | 190 |
191 base::DictionaryValue* result; | 191 base::DictionaryValue* result; |
192 EXPECT_TRUE(result_value->GetAsDictionary(&result)); | 192 EXPECT_TRUE(result_value->GetAsDictionary(&result)); |
193 | 193 |
194 base::DictionaryValue* options; | 194 base::DictionaryValue* options; |
195 EXPECT_TRUE(result->GetDictionary("options", &options)); | 195 EXPECT_TRUE(result->GetDictionary("options", &options)); |
196 base::DictionaryValue* origin_types; | 196 base::DictionaryValue* origin_types; |
197 EXPECT_TRUE(options->GetDictionary("originTypes", &origin_types)); | 197 EXPECT_TRUE(options->GetDictionary("originTypes", &origin_types)); |
198 int origin_type_mask = GetAsMask(origin_types, "unprotectedWeb", | 198 int origin_type_mask = GetAsMask(origin_types, "unprotectedWeb", |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 function.get(), args, browser())) << " for " << args; | 250 function.get(), args, browser())) << " for " << args; |
251 } else { | 251 } else { |
252 EXPECT_TRUE(base::MatchPattern( | 252 EXPECT_TRUE(base::MatchPattern( |
253 RunFunctionAndReturnError(function.get(), args, browser()), | 253 RunFunctionAndReturnError(function.get(), args, browser()), |
254 extension_browsing_data_api_constants::kDeleteProhibitedError)) | 254 extension_browsing_data_api_constants::kDeleteProhibitedError)) |
255 << " for " << args; | 255 << " for " << args; |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 private: | 259 private: |
260 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 260 std::unique_ptr<BrowsingDataRemover::NotificationDetails> |
| 261 called_with_details_; |
261 | 262 |
262 BrowsingDataRemover::CallbackSubscription callback_subscription_; | 263 BrowsingDataRemover::CallbackSubscription callback_subscription_; |
263 }; | 264 }; |
264 | 265 |
265 } // namespace | 266 } // namespace |
266 | 267 |
267 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { | 268 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { |
268 BrowsingDataRemover* browsing_data_remover = | 269 BrowsingDataRemover* browsing_data_remover = |
269 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 270 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
270 browsing_data_remover->SetRemoving(true); | 271 browsing_data_remover->SetRemoving(true); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, false); | 418 prefs->SetBoolean(prefs::kClearPluginLSODataEnabled, false); |
418 int expected_mask = BrowsingDataRemover::REMOVE_CACHE | | 419 int expected_mask = BrowsingDataRemover::REMOVE_CACHE | |
419 BrowsingDataRemover::REMOVE_DOWNLOADS | | 420 BrowsingDataRemover::REMOVE_DOWNLOADS | |
420 BrowsingDataRemover::REMOVE_HISTORY; | 421 BrowsingDataRemover::REMOVE_HISTORY; |
421 std::string json; | 422 std::string json; |
422 // Scoping for the traces. | 423 // Scoping for the traces. |
423 { | 424 { |
424 scoped_refptr<BrowsingDataSettingsFunction> settings_function = | 425 scoped_refptr<BrowsingDataSettingsFunction> settings_function = |
425 new BrowsingDataSettingsFunction(); | 426 new BrowsingDataSettingsFunction(); |
426 SCOPED_TRACE("settings_json"); | 427 SCOPED_TRACE("settings_json"); |
427 scoped_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( | 428 std::unique_ptr<base::Value> result_value(RunFunctionAndReturnSingleResult( |
428 settings_function.get(), std::string("[]"), browser())); | 429 settings_function.get(), std::string("[]"), browser())); |
429 | 430 |
430 base::DictionaryValue* result; | 431 base::DictionaryValue* result; |
431 EXPECT_TRUE(result_value->GetAsDictionary(&result)); | 432 EXPECT_TRUE(result_value->GetAsDictionary(&result)); |
432 base::DictionaryValue* data_to_remove; | 433 base::DictionaryValue* data_to_remove; |
433 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove)); | 434 EXPECT_TRUE(result->GetDictionary("dataToRemove", &data_to_remove)); |
434 | 435 |
435 JSONStringValueSerializer serializer(&json); | 436 JSONStringValueSerializer serializer(&json); |
436 EXPECT_TRUE(serializer.Serialize(*data_to_remove)); | 437 EXPECT_TRUE(serializer.Serialize(*data_to_remove)); |
437 } | 438 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 540 |
540 SetPrefsAndVerifySettings( | 541 SetPrefsAndVerifySettings( |
541 BrowsingDataRemover::REMOVE_COOKIES | | 542 BrowsingDataRemover::REMOVE_COOKIES | |
542 BrowsingDataRemover::REMOVE_HISTORY | | 543 BrowsingDataRemover::REMOVE_HISTORY | |
543 BrowsingDataRemover::REMOVE_DOWNLOADS, | 544 BrowsingDataRemover::REMOVE_DOWNLOADS, |
544 UNPROTECTED_WEB, | 545 UNPROTECTED_WEB, |
545 site_data_no_plugins | | 546 site_data_no_plugins | |
546 BrowsingDataRemover::REMOVE_HISTORY | | 547 BrowsingDataRemover::REMOVE_HISTORY | |
547 BrowsingDataRemover::REMOVE_DOWNLOADS); | 548 BrowsingDataRemover::REMOVE_DOWNLOADS); |
548 } | 549 } |
OLD | NEW |