Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/extensions/api/browsing_data/browsing_data_test.cc

Issue 10522002: `chrome.browsingData` extension API can now remove data from protected origins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bernhard 2. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browsing_data_helper.h"
14 #include "chrome/browser/browsing_data_remover.h" 15 #include "chrome/browser/browsing_data_remover.h"
15 #include "chrome/browser/extensions/extension_function_test_utils.h" 16 #include "chrome/browser/extensions/extension_function_test_utils.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
20 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
21 22
22 using extension_function_test_utils::RunFunctionAndReturnError; 23 using extension_function_test_utils::RunFunctionAndReturnError;
23 using extension_function_test_utils::RunFunctionAndReturnResult; 24 using extension_function_test_utils::RunFunctionAndReturnResult;
(...skipping 12 matching lines...) Expand all
36 public content::NotificationObserver { 37 public content::NotificationObserver {
37 public: 38 public:
38 base::Time GetBeginTime() { 39 base::Time GetBeginTime() {
39 return called_with_details_->removal_begin; 40 return called_with_details_->removal_begin;
40 } 41 }
41 42
42 int GetRemovalMask() { 43 int GetRemovalMask() {
43 return called_with_details_->removal_mask; 44 return called_with_details_->removal_mask;
44 } 45 }
45 46
47 int GetOriginSetMask() {
48 return called_with_details_->origin_set_mask;
49 }
50
46 protected: 51 protected:
47 virtual void SetUpOnMainThread() { 52 virtual void SetUpOnMainThread() {
48 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); 53 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
49 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, 54 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
50 content::Source<Profile>(browser()->profile())); 55 content::Source<Profile>(browser()->profile()));
51 } 56 }
52 57
53 virtual void TearDownOnMainThread() { 58 virtual void TearDownOnMainThread() {
54 registrar_.RemoveAll(); 59 registrar_.RemoveAll();
55 } 60 }
56 61
57 // content::NotificationObserver implementation. 62 // content::NotificationObserver implementation.
58 virtual void Observe(int type, 63 virtual void Observe(int type,
59 const content::NotificationSource& source, 64 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE { 65 const content::NotificationDetails& details) OVERRIDE {
61 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); 66 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
62 67
63 // 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
64 // it locally. 69 // it locally.
65 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( 70 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
66 *content::Details<BrowsingDataRemover::NotificationDetails>( 71 *content::Details<BrowsingDataRemover::NotificationDetails>(
67 details).ptr())); 72 details).ptr()));
68 } 73 }
69 74
70 void RunRemoveBrowsingDataFunctionAndCompareMask(const std::string& key, 75 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
71 int expected_mask) { 76 const std::string& key,
77 int expected_mask) {
72 SCOPED_TRACE(key); 78 SCOPED_TRACE(key);
73 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), 79 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(),
74 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", browser())); 80 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", browser()));
75 EXPECT_EQ(expected_mask, GetRemovalMask()); 81 EXPECT_EQ(expected_mask, GetRemovalMask());
76 } 82 }
77 83
84 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
85 const std::string& protectedStr,
86 int expected_mask) {
87 SCOPED_TRACE(protectedStr);
88 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(),
89 "[{\"origin_types\": " + protectedStr + "}, {\"cookies\": true}]",
90 browser()));
91 EXPECT_EQ(expected_mask, GetOriginSetMask());
92 }
93
78 private: 94 private:
79 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; 95 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
80 content::NotificationRegistrar registrar_; 96 content::NotificationRegistrar registrar_;
81 }; 97 };
82 98
83 } // namespace 99 } // namespace
84 100
85 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { 101 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) {
86 BrowsingDataRemover::set_removing(true); 102 BrowsingDataRemover::set_removing(true);
87 EXPECT_TRUE(MatchPattern( 103 EXPECT_TRUE(MatchPattern(
(...skipping 18 matching lines...) Expand all
106 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | 122 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA |
107 BrowsingDataRemover::REMOVE_CACHE | 123 BrowsingDataRemover::REMOVE_CACHE |
108 BrowsingDataRemover::REMOVE_DOWNLOADS | 124 BrowsingDataRemover::REMOVE_DOWNLOADS |
109 BrowsingDataRemover::REMOVE_FORM_DATA | 125 BrowsingDataRemover::REMOVE_FORM_DATA |
110 BrowsingDataRemover::REMOVE_HISTORY | 126 BrowsingDataRemover::REMOVE_HISTORY |
111 BrowsingDataRemover::REMOVE_PASSWORDS) & 127 BrowsingDataRemover::REMOVE_PASSWORDS) &
112 // We can't remove plugin data inside a test profile. 128 // We can't remove plugin data inside a test profile.
113 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); 129 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
114 } 130 }
115 131
116 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataMask) { 132 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataOriginSetMask) {
117 RunRemoveBrowsingDataFunctionAndCompareMask( 133 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask("{}", 0);
134 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
135 "{\"unprotected_web\": true}", BrowsingDataHelper::UNPROTECTED_WEB);
136 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
137 "{\"protected_web\": true}", BrowsingDataHelper::PROTECTED_WEB);
138 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
139 "{\"unprotected_web\": true, \"protected_web\": true}",
140 BrowsingDataHelper::UNPROTECTED_WEB | BrowsingDataHelper::PROTECTED_WEB);
141 }
142
143 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataRemovalMask) {
144 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
118 "appcache", BrowsingDataRemover::REMOVE_APPCACHE); 145 "appcache", BrowsingDataRemover::REMOVE_APPCACHE);
119 RunRemoveBrowsingDataFunctionAndCompareMask( 146 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
120 "cache", BrowsingDataRemover::REMOVE_CACHE); 147 "cache", BrowsingDataRemover::REMOVE_CACHE);
121 RunRemoveBrowsingDataFunctionAndCompareMask( 148 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
122 "cookies", BrowsingDataRemover::REMOVE_COOKIES); 149 "cookies", BrowsingDataRemover::REMOVE_COOKIES);
123 RunRemoveBrowsingDataFunctionAndCompareMask( 150 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
124 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS); 151 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS);
125 RunRemoveBrowsingDataFunctionAndCompareMask( 152 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
126 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS); 153 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
127 RunRemoveBrowsingDataFunctionAndCompareMask( 154 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
128 "formData", BrowsingDataRemover::REMOVE_FORM_DATA); 155 "formData", BrowsingDataRemover::REMOVE_FORM_DATA);
129 RunRemoveBrowsingDataFunctionAndCompareMask( 156 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
130 "history", BrowsingDataRemover::REMOVE_HISTORY); 157 "history", BrowsingDataRemover::REMOVE_HISTORY);
131 RunRemoveBrowsingDataFunctionAndCompareMask( 158 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
132 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB); 159 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB);
133 RunRemoveBrowsingDataFunctionAndCompareMask( 160 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
134 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); 161 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
135 RunRemoveBrowsingDataFunctionAndCompareMask( 162 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
136 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); 163 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS);
137 RunRemoveBrowsingDataFunctionAndCompareMask( 164 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
138 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); 165 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS);
139 // We can't remove plugin data inside a test profile. 166 // We can't remove plugin data inside a test profile.
140 RunRemoveBrowsingDataFunctionAndCompareMask( 167 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
141 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); 168 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL);
142 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698