Chromium Code Reviews| 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 <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 "\"appcache\": true, \"cache\": true, \"cookies\": true, " | 39 "\"appcache\": true, \"cache\": true, \"cookies\": true, " |
| 40 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " | 40 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " |
| 41 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " | 41 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " |
| 42 "\"serverBoundCertificates\": true, \"passwords\": true, " | 42 "\"serverBoundCertificates\": true, \"passwords\": true, " |
| 43 "\"pluginData\": true, \"serviceWorkers\": true, \"cacheStorage\": true, " | 43 "\"pluginData\": true, \"serviceWorkers\": true, \"cacheStorage\": true, " |
| 44 "\"webSQL\": true" | 44 "\"webSQL\": true" |
| 45 "}]"; | 45 "}]"; |
| 46 | 46 |
| 47 class ExtensionBrowsingDataTest : public InProcessBrowserTest { | 47 class ExtensionBrowsingDataTest : public InProcessBrowserTest { |
| 48 public: | 48 public: |
| 49 base::Time GetBeginTime() { | 49 const base::Time& GetBeginTime() { |
| 50 return called_with_details_->removal_begin; | 50 return remover_->GetLastUsedBeginTime(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 int GetRemovalMask() { | 53 int GetRemovalMask() { |
| 54 return called_with_details_->removal_mask; | 54 return remover_->GetLastUsedRemovalMask(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 int GetOriginTypeMask() { | 57 int GetOriginTypeMask() { |
| 58 return called_with_details_->origin_type_mask; | 58 return remover_->GetLastUsedOriginTypeMask(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 void SetUpOnMainThread() override { | 62 void SetUpOnMainThread() override { |
| 63 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 63 remover_ = |
| 64 callback_subscription_ = | 64 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
| 65 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | |
| 66 base::Bind(&ExtensionBrowsingDataTest::NotifyWithDetails, | |
| 67 base::Unretained(this))); | |
| 68 } | |
| 69 | |
| 70 // Callback for browsing data removal events. | |
| 71 void NotifyWithDetails( | |
| 72 const BrowsingDataRemover::NotificationDetails& details) { | |
| 73 // We're not taking ownership of the details object, but storing a copy of | |
| 74 // it locally. | |
| 75 called_with_details_.reset( | |
| 76 new BrowsingDataRemover::NotificationDetails(details)); | |
| 77 } | 65 } |
| 78 | 66 |
| 79 int GetAsMask(const base::DictionaryValue* dict, std::string path, | 67 int GetAsMask(const base::DictionaryValue* dict, std::string path, |
| 80 int mask_value) { | 68 int mask_value) { |
| 81 bool result; | 69 bool result; |
| 82 EXPECT_TRUE(dict->GetBoolean(path, &result)) << "for " << path; | 70 EXPECT_TRUE(dict->GetBoolean(path, &result)) << "for " << path; |
| 83 return result ? mask_value : 0; | 71 return result ? mask_value : 0; |
| 84 } | 72 } |
| 85 | 73 |
| 86 void RunBrowsingDataRemoveFunctionAndCompareRemovalMask( | 74 void RunBrowsingDataRemoveFunctionAndCompareRemovalMask( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 function.get(), args, browser())) << " for " << args; | 237 function.get(), args, browser())) << " for " << args; |
| 250 } else { | 238 } else { |
| 251 EXPECT_TRUE(base::MatchPattern( | 239 EXPECT_TRUE(base::MatchPattern( |
| 252 RunFunctionAndReturnError(function.get(), args, browser()), | 240 RunFunctionAndReturnError(function.get(), args, browser()), |
| 253 extension_browsing_data_api_constants::kDeleteProhibitedError)) | 241 extension_browsing_data_api_constants::kDeleteProhibitedError)) |
| 254 << " for " << args; | 242 << " for " << args; |
| 255 } | 243 } |
| 256 } | 244 } |
| 257 | 245 |
| 258 private: | 246 private: |
| 259 std::unique_ptr<BrowsingDataRemover::NotificationDetails> | 247 // Cached pointer to BrowsingDataRemover for access to testing methods. |
| 260 called_with_details_; | 248 BrowsingDataRemover* remover_; |
| 261 | |
| 262 BrowsingDataRemover::CallbackSubscription callback_subscription_; | |
| 263 }; | 249 }; |
| 264 | 250 |
| 265 } // namespace | 251 } // namespace |
| 266 | 252 |
| 267 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { | 253 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { |
| 268 BrowsingDataRemover* browsing_data_remover = | 254 BrowsingDataRemover* browsing_data_remover = |
| 269 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 255 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
| 270 browsing_data_remover->SetRemoving(true); | 256 browsing_data_remover->SetRemoving(true); |
| 271 scoped_refptr<BrowsingDataRemoveFunction> function = | 257 scoped_refptr<BrowsingDataRemoveFunction> function = |
| 272 new BrowsingDataRemoveFunction(); | 258 new BrowsingDataRemoveFunction(); |
| 273 EXPECT_TRUE(base::MatchPattern( | 259 EXPECT_TRUE(base::MatchPattern( |
| 274 RunFunctionAndReturnError(function.get(), kRemoveEverythingArguments, | 260 RunFunctionAndReturnError(function.get(), kRemoveEverythingArguments, |
| 275 browser()), | 261 browser()), |
| 276 extension_browsing_data_api_constants::kOneAtATimeError)); | 262 extension_browsing_data_api_constants::kOneAtATimeError)); |
| 277 browsing_data_remover->SetRemoving(false); | 263 browsing_data_remover->SetRemoving(false); |
| 278 | 264 |
| 279 EXPECT_EQ(base::Time(), GetBeginTime()); | 265 EXPECT_EQ(base::Time(), GetBeginTime()); |
| 280 EXPECT_EQ(-1, GetRemovalMask()); | 266 EXPECT_EQ(0, GetRemovalMask()); |
|
Mike West
2016/07/28 12:02:22
Why did this change?
msramek
2016/07/28 12:20:49
Previously, "no notification received yet" was rep
| |
| 281 } | 267 } |
| 282 | 268 |
| 283 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemovalProhibited) { | 269 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemovalProhibited) { |
| 284 PrefService* prefs = browser()->profile()->GetPrefs(); | 270 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 285 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); | 271 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); |
| 286 | 272 |
| 287 CheckRemovalPermitted("{\"appcache\": true}", true); | 273 CheckRemovalPermitted("{\"appcache\": true}", true); |
| 288 CheckRemovalPermitted("{\"cache\": true}", true); | 274 CheckRemovalPermitted("{\"cache\": true}", true); |
| 289 CheckRemovalPermitted("{\"cookies\": true}", true); | 275 CheckRemovalPermitted("{\"cookies\": true}", true); |
| 290 CheckRemovalPermitted("{\"downloads\": true}", false); | 276 CheckRemovalPermitted("{\"downloads\": true}", false); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 | 522 |
| 537 SetPrefsAndVerifySettings( | 523 SetPrefsAndVerifySettings( |
| 538 BrowsingDataRemover::REMOVE_COOKIES | | 524 BrowsingDataRemover::REMOVE_COOKIES | |
| 539 BrowsingDataRemover::REMOVE_HISTORY | | 525 BrowsingDataRemover::REMOVE_HISTORY | |
| 540 BrowsingDataRemover::REMOVE_DOWNLOADS, | 526 BrowsingDataRemover::REMOVE_DOWNLOADS, |
| 541 UNPROTECTED_WEB, | 527 UNPROTECTED_WEB, |
| 542 site_data_no_plugins | | 528 site_data_no_plugins | |
| 543 BrowsingDataRemover::REMOVE_HISTORY | | 529 BrowsingDataRemover::REMOVE_HISTORY | |
| 544 BrowsingDataRemover::REMOVE_DOWNLOADS); | 530 BrowsingDataRemover::REMOVE_DOWNLOADS); |
| 545 } | 531 } |
| OLD | NEW |