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

Side by Side Diff: chrome/browser/extensions/extension_browsing_data_test.cc

Issue 9424036: Move `browsingData` extension API out of experimental. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebuilt docs. Created 8 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_browsing_data_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 kRemoveEverythingArguments[] = "[{\"since\": 1000}, {"
27 "\"appcache\": true, \"cache\": true, \"cookies\": true, "
28 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, "
29 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, "
30 "\"originBoundCerts\": true, \"passwords\": true, \"pluginData\": true, "
31 "\"webSQL\": true"
32 "}]";
33
34 class ExtensionBrowsingDataTest : public InProcessBrowserTest,
35 public content::NotificationObserver {
36 public:
37 base::Time GetBeginTime() {
38 return called_with_details_->removal_begin;
39 }
40
41 int GetRemovalMask() {
42 return called_with_details_->removal_mask;
43 }
44
45 protected:
46 virtual void SetUpOnMainThread() {
47 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
48 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
49 content::Source<Profile>(browser()->profile()));
50 }
51
52 virtual void TearDownOnMainThread() {
53 registrar_.RemoveAll();
54 }
55
56 // content::NotificationObserver implementation.
57 virtual void Observe(int type,
58 const content::NotificationSource& source,
59 const content::NotificationDetails& details) OVERRIDE {
60 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
61
62 // We're not taking ownership of the details object, but storing a copy of
63 // it locally.
64 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
65 *content::Details<BrowsingDataRemover::NotificationDetails>(
66 details).ptr()));
67 }
68
69 void RunRemoveBrowsingDataFunctionAndCompareMask(const std::string& key,
70 int expected_mask) {
71 SCOPED_TRACE(key);
72 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(),
73 std::string("[{\"since\": 1}, {\"") + key + "\": true}]", browser()));
74 EXPECT_EQ(expected_mask, GetRemovalMask());
75 }
76
77 private:
78 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
79 content::NotificationRegistrar registrar_;
80 };
81
82 } // namespace
83
84 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, OneAtATime) {
85 BrowsingDataRemover::set_removing(true);
86 EXPECT_TRUE(MatchPattern(
87 RunFunctionAndReturnError(
88 new RemoveBrowsingDataFunction(),
89 kRemoveEverythingArguments,
90 browser()),
91 extension_browsing_data_api_constants::kOneAtATimeError));
92 BrowsingDataRemover::set_removing(false);
93
94 EXPECT_EQ(base::Time(), GetBeginTime());
95 EXPECT_EQ(-1, GetRemovalMask());
96 }
97
98 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataAll) {
99 EXPECT_EQ(NULL, RunFunctionAndReturnResult(new RemoveBrowsingDataFunction(),
100 kRemoveEverythingArguments, browser()));
101
102 EXPECT_EQ(base::Time::FromDoubleT(1.0), GetBeginTime());
103 EXPECT_EQ((BrowsingDataRemover::REMOVE_SITE_DATA |
104 BrowsingDataRemover::REMOVE_CACHE |
105 BrowsingDataRemover::REMOVE_DOWNLOADS |
106 BrowsingDataRemover::REMOVE_FORM_DATA |
107 BrowsingDataRemover::REMOVE_HISTORY |
108 BrowsingDataRemover::REMOVE_PASSWORDS) &
109 // We can't remove plugin data inside a test profile.
110 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
111 }
112
113 IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataMask) {
114 RunRemoveBrowsingDataFunctionAndCompareMask(
115 "appcache", BrowsingDataRemover::REMOVE_APPCACHE);
116 RunRemoveBrowsingDataFunctionAndCompareMask(
117 "cache", BrowsingDataRemover::REMOVE_CACHE);
118 RunRemoveBrowsingDataFunctionAndCompareMask(
119 "cookies", BrowsingDataRemover::REMOVE_COOKIES);
120 RunRemoveBrowsingDataFunctionAndCompareMask(
121 "downloads", BrowsingDataRemover::REMOVE_DOWNLOADS);
122 RunRemoveBrowsingDataFunctionAndCompareMask(
123 "fileSystems", BrowsingDataRemover::REMOVE_FILE_SYSTEMS);
124 RunRemoveBrowsingDataFunctionAndCompareMask(
125 "formData", BrowsingDataRemover::REMOVE_FORM_DATA);
126 RunRemoveBrowsingDataFunctionAndCompareMask(
127 "history", BrowsingDataRemover::REMOVE_HISTORY);
128 RunRemoveBrowsingDataFunctionAndCompareMask(
129 "indexedDB", BrowsingDataRemover::REMOVE_INDEXEDDB);
130 RunRemoveBrowsingDataFunctionAndCompareMask(
131 "localStorage", BrowsingDataRemover::REMOVE_LOCAL_STORAGE);
132 RunRemoveBrowsingDataFunctionAndCompareMask(
133 "originBoundCerts", BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS);
134 RunRemoveBrowsingDataFunctionAndCompareMask(
135 "passwords", BrowsingDataRemover::REMOVE_PASSWORDS);
136 // We can't remove plugin data inside a test profile.
137 RunRemoveBrowsingDataFunctionAndCompareMask(
138 "webSQL", BrowsingDataRemover::REMOVE_WEBSQL);
139 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsing_data_api.cc ('k') | chrome/browser/extensions/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698