OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_clear_api.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" |
| 13 #include "base/values.h" |
| 14 #include "chrome/browser/browsing_data_remover.h" |
| 15 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "content/public/browser/notification_service.h" |
| 21 |
| 22 using namespace extension_function_test_utils; |
| 23 |
| 24 namespace { |
| 25 |
| 26 const char kClearEverythingArguments[] = "[1000, {" |
| 27 "\"appcache\": true, \"cache\": true, \"cookies\": true, " |
| 28 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " |
| 29 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " |
| 30 "\"pluginData\": true, \"passwords\": true, \"webSQL\": true" |
| 31 "}]"; |
| 32 |
| 33 class ExtensionClearTest : public InProcessBrowserTest, |
| 34 public content::NotificationObserver { |
| 35 public: |
| 36 base::Time GetBeginTime() { |
| 37 return called_with_details_->removal_begin; |
| 38 } |
| 39 |
| 40 int GetRemovalMask() { |
| 41 return called_with_details_->removal_mask; |
| 42 } |
| 43 |
| 44 protected: |
| 45 virtual void SetUpOnMainThread() { |
| 46 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 47 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 48 content::Source<Profile>(browser()->profile())); |
| 49 } |
| 50 |
| 51 // content::NotificationObserver implementation. |
| 52 virtual void Observe(int type, |
| 53 const content::NotificationSource& source, |
| 54 const content::NotificationDetails& details) OVERRIDE { |
| 55 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); |
| 56 |
| 57 // We're not taking ownership of the details object, but storing a copy of |
| 58 // it locally. |
| 59 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
| 60 *content::Details<BrowsingDataRemover::NotificationDetails>( |
| 61 details).ptr())); |
| 62 |
| 63 registrar_.RemoveAll(); |
| 64 } |
| 65 |
| 66 private: |
| 67 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
| 68 content::NotificationRegistrar registrar_; |
| 69 }; |
| 70 |
| 71 } // namespace |
| 72 |
| 73 IN_PROC_BROWSER_TEST_F(ExtensionClearTest, OneAtATime) { |
| 74 BrowsingDataRemover::set_removing(true); |
| 75 EXPECT_TRUE(MatchPattern( |
| 76 RunFunctionAndReturnError( |
| 77 new ClearBrowsingDataFunction(), |
| 78 kClearEverythingArguments, |
| 79 browser()), |
| 80 extension_clear_api_constants::kOneAtATimeError)); |
| 81 BrowsingDataRemover::set_removing(false); |
| 82 |
| 83 EXPECT_EQ(base::Time(), GetBeginTime()); |
| 84 EXPECT_EQ(-1, GetRemovalMask()); |
| 85 } |
| 86 |
| 87 IN_PROC_BROWSER_TEST_F(ExtensionClearTest, ClearBrowsingDataEverything) { |
| 88 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new ClearBrowsingDataFunction(), |
| 89 kClearEverythingArguments, browser())); |
| 90 |
| 91 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); |
| 92 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | |
| 93 BrowsingDataRemover::REMOVE_CACHE | |
| 94 BrowsingDataRemover::REMOVE_DOWNLOADS | |
| 95 BrowsingDataRemover::REMOVE_FORM_DATA | |
| 96 BrowsingDataRemover::REMOVE_HISTORY | |
| 97 BrowsingDataRemover::REMOVE_PASSWORDS) & |
| 98 // We can't remove plugin data inside a test profile. |
| 99 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
| 100 } |
OLD | NEW |