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

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: Tiny docs tweak. 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());
82 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
83 }
84
85 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
86 const std::string& protectedStr,
87 int expected_mask) {
88 SCOPED_TRACE(protectedStr);
89 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(),
90 "[{\"originType\": " + protectedStr + "}, {\"cookies\": true}]",
91 browser()));
92 EXPECT_EQ(expected_mask, GetOriginSetMask());
76 } 93 }
77 94
78 private: 95 private:
79 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; 96 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
80 content::NotificationRegistrar registrar_; 97 content::NotificationRegistrar registrar_;
81 }; 98 };
82 99
83 } // namespace 100 } // namespace
84 101
85 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { 102 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) {
(...skipping 20 matching lines...) Expand all
106 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | 123 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA |
107 BrowsingDataRemover::REMOVE_CACHE | 124 BrowsingDataRemover::REMOVE_CACHE |
108 BrowsingDataRemover::REMOVE_DOWNLOADS | 125 BrowsingDataRemover::REMOVE_DOWNLOADS |
109 BrowsingDataRemover::REMOVE_FORM_DATA | 126 BrowsingDataRemover::REMOVE_FORM_DATA |
110 BrowsingDataRemover::REMOVE_HISTORY | 127 BrowsingDataRemover::REMOVE_HISTORY |
111 BrowsingDataRemover::REMOVE_PASSWORDS) & 128 BrowsingDataRemover::REMOVE_PASSWORDS) &
112 // We can't remove plugin data inside a test profile. 129 // We can't remove plugin data inside a test profile.
113 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); 130 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
114 } 131 }
115 132
116 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataMask) { 133 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataOriginSetMask) {
117 RunRemoveBrowsingDataFunctionAndCompareMask( 134 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask("{}", 0);
135
136 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
137 "{\"unprotectedWeb\": true}", BrowsingDataHelper::UNPROTECTED_WEB);
138 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
139 "{\"protectedWeb\": true}", BrowsingDataHelper::PROTECTED_WEB);
140 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
141 "{\"extension\": true}", BrowsingDataHelper::EXTENSION);
142
143 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
144 "{\"unprotectedWeb\": true, \"protectedWeb\": true}",
145 BrowsingDataHelper::UNPROTECTED_WEB | BrowsingDataHelper::PROTECTED_WEB);
146 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
147 "{\"unprotectedWeb\": true, \"extension\": true}",
148 BrowsingDataHelper::UNPROTECTED_WEB | BrowsingDataHelper::EXTENSION);
149 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
150 "{\"protectedWeb\": true, \"extension\": true}",
151 BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION);
152
153 RunRemoveBrowsingDataFunctionAndCompareOriginSetMask(
154 ("{\"unprotectedWeb\": true, \"protectedWeb\": true, "
155 "\"extension\": true}"),
156 BrowsingDataHelper::UNPROTECTED_WEB | BrowsingDataHelper::PROTECTED_WEB |
157 BrowsingDataHelper::EXTENSION);
158 }
159
160 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, BrowsingDataRemovalMask) {
161 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
118 "appcache", BrowsingDataRemover::REMOVE_APPCACHE); 162 "appcache", BrowsingDataRemover::REMOVE_APPCACHE);
119 RunRemoveBrowsingDataFunctionAndCompareMask( 163 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
120 "cache", BrowsingDataRemover::REMOVE_CACHE); 164 "cache", BrowsingDataRemover::REMOVE_CACHE);
121 RunRemoveBrowsingDataFunctionAndCompareMask( 165 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
122 "cookies", BrowsingDataRemover::REMOVE_COOKIES); 166 "cookies", BrowsingDataRemover::REMOVE_COOKIES);
123 RunRemoveBrowsingDataFunctionAndCompareMask( 167 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
124 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS); 168 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS);
125 RunRemoveBrowsingDataFunctionAndCompareMask( 169 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
126 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS); 170 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
127 RunRemoveBrowsingDataFunctionAndCompareMask( 171 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
128 "formData", BrowsingDataRemover::REMOVE_FORM_DATA); 172 "formData", BrowsingDataRemover::REMOVE_FORM_DATA);
129 RunRemoveBrowsingDataFunctionAndCompareMask( 173 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
130 "history", BrowsingDataRemover::REMOVE_HISTORY); 174 "history", BrowsingDataRemover::REMOVE_HISTORY);
131 RunRemoveBrowsingDataFunctionAndCompareMask( 175 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
132 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB); 176 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB);
133 RunRemoveBrowsingDataFunctionAndCompareMask( 177 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
134 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); 178 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
135 RunRemoveBrowsingDataFunctionAndCompareMask( 179 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
136 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); 180 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS);
137 RunRemoveBrowsingDataFunctionAndCompareMask( 181 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
138 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); 182 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS);
139 // We can't remove plugin data inside a test profile. 183 // We can't remove plugin data inside a test profile.
140 RunRemoveBrowsingDataFunctionAndCompareMask( 184 RunRemoveBrowsingDataFunctionAndCompareRemovalMask(
141 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); 185 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL);
142 } 186 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/browsing_data/browsing_data_api.cc ('k') | chrome/common/extensions/api/browsing_data.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698