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 "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_helper.h" |
15 #include "chrome/browser/browsing_data_remover.h" | 15 #include "chrome/browser/browsing_data_remover.h" |
16 #include "chrome/browser/extensions/extension_function_test_utils.h" | 16 #include "chrome/browser/extensions/extension_function_test_utils.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 | 22 |
23 using extension_function_test_utils::RunFunctionAndReturnError; | 23 using extension_function_test_utils::RunFunctionAndReturnError; |
24 using extension_function_test_utils::RunFunctionAndReturnResult; | 24 using extension_function_test_utils::RunFunctionAndReturnSingleResult; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char kRemoveEverythingArguments[] = "[{\"since\": 1000}, {" | 28 const char kRemoveEverythingArguments[] = "[{\"since\": 1000}, {" |
29 "\"appcache\": true, \"cache\": true, \"cookies\": true, " | 29 "\"appcache\": true, \"cache\": true, \"cookies\": true, " |
30 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " | 30 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, " |
31 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " | 31 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, " |
32 "\"serverBoundCerts\": true, \"passwords\": true, \"pluginData\": true, " | 32 "\"serverBoundCerts\": true, \"passwords\": true, \"pluginData\": true, " |
33 "\"webSQL\": true" | 33 "\"webSQL\": true" |
34 "}]"; | 34 "}]"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // it locally. | 69 // it locally. |
70 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( | 70 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
71 *content::Details<BrowsingDataRemover::NotificationDetails>( | 71 *content::Details<BrowsingDataRemover::NotificationDetails>( |
72 details).ptr())); | 72 details).ptr())); |
73 } | 73 } |
74 | 74 |
75 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 75 void RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
76 const std::string& key, | 76 const std::string& key, |
77 int expected_mask) { | 77 int expected_mask) { |
78 SCOPED_TRACE(key); | 78 SCOPED_TRACE(key); |
79 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), | 79 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
80 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", browser())); | 80 new RemoveBrowsingDataFunction(), |
| 81 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", |
| 82 browser())); |
81 EXPECT_EQ(expected_mask, GetRemovalMask()); | 83 EXPECT_EQ(expected_mask, GetRemovalMask()); |
82 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 84 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
83 } | 85 } |
84 | 86 |
85 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( | 87 void RunRemoveBrowsingDataFunctionAndCompareOriginSetMask( |
86 const std::string& protectedStr, | 88 const std::string& protectedStr, |
87 int expected_mask) { | 89 int expected_mask) { |
88 SCOPED_TRACE(protectedStr); | 90 SCOPED_TRACE(protectedStr); |
89 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), | 91 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
| 92 new RemoveBrowsingDataFunction(), |
90 "[{\"originType\": " + protectedStr + "}, {\"cookies\": true}]", | 93 "[{\"originType\": " + protectedStr + "}, {\"cookies\": true}]", |
91 browser())); | 94 browser())); |
92 EXPECT_EQ(expected_mask, GetOriginSetMask()); | 95 EXPECT_EQ(expected_mask, GetOriginSetMask()); |
93 } | 96 } |
94 | 97 |
95 private: | 98 private: |
96 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 99 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
97 content::NotificationRegistrar registrar_; | 100 content::NotificationRegistrar registrar_; |
98 }; | 101 }; |
99 | 102 |
100 } // namespace | 103 } // namespace |
101 | 104 |
102 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { | 105 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) { |
103 BrowsingDataRemover::set_removing(true); | 106 BrowsingDataRemover::set_removing(true); |
104 EXPECT_TRUE(MatchPattern( | 107 EXPECT_TRUE(MatchPattern( |
105 RunFunctionAndReturnError( | 108 RunFunctionAndReturnError( |
106 new RemoveBrowsingDataFunction(), | 109 new RemoveBrowsingDataFunction(), |
107 kRemoveEverythingArguments, | 110 kRemoveEverythingArguments, |
108 browser()), | 111 browser()), |
109 extension_browsing_data_api_constants::kOneAtATimeError)); | 112 extension_browsing_data_api_constants::kOneAtATimeError)); |
110 BrowsingDataRemover::set_removing(false); | 113 BrowsingDataRemover::set_removing(false); |
111 | 114 |
112 EXPECT_EQ(base::Time(), GetBeginTime()); | 115 EXPECT_EQ(base::Time(), GetBeginTime()); |
113 EXPECT_EQ(-1, GetRemovalMask()); | 116 EXPECT_EQ(-1, GetRemovalMask()); |
114 } | 117 } |
115 | 118 |
116 // Use-after-free, see http://crbug.com/116522 | 119 // Use-after-free, see http://crbug.com/116522 |
117 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, | 120 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, |
118 DISABLED_RemoveBrowsingDataAll) { | 121 DISABLED_RemoveBrowsingDataAll) { |
119 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(), | 122 EXPECT_EQ(NULL, RunFunctionAndReturnSingleResult( |
120 kRemoveEverythingArguments, browser())); | 123 new RemoveBrowsingDataFunction(), |
| 124 kRemoveEverythingArguments, |
| 125 browser())); |
121 | 126 |
122 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); | 127 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime()); |
123 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | | 128 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA | |
124 BrowsingDataRemover::REMOVE_CACHE | | 129 BrowsingDataRemover::REMOVE_CACHE | |
125 BrowsingDataRemover::REMOVE_DOWNLOADS | | 130 BrowsingDataRemover::REMOVE_DOWNLOADS | |
126 BrowsingDataRemover::REMOVE_FORM_DATA | | 131 BrowsingDataRemover::REMOVE_FORM_DATA | |
127 BrowsingDataRemover::REMOVE_HISTORY | | 132 BrowsingDataRemover::REMOVE_HISTORY | |
128 BrowsingDataRemover::REMOVE_PASSWORDS) & | 133 BrowsingDataRemover::REMOVE_PASSWORDS) & |
129 // We can't remove plugin data inside a test profile. | 134 // We can't remove plugin data inside a test profile. |
130 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); | 135 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 182 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
178 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); | 183 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE); |
179 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 184 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
180 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); | 185 "serverBoundCerts", BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS); |
181 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 186 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
182 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); | 187 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS); |
183 // We can't remove plugin data inside a test profile. | 188 // We can't remove plugin data inside a test profile. |
184 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( | 189 RunRemoveBrowsingDataFunctionAndCompareRemovalMask( |
185 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); | 190 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL); |
186 } | 191 } |
OLD | NEW |