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

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

Issue 8008012: chrome.clear: Increasing granularity of public API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing after 2 months (ugh). Extension test. Fiddling. Created 9 years 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) 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[] = "[\"everything\", {"
27 "\"appcache\": true, \"cache\": true, \"cookies\": true, "
28 "\"downloads\": true, \"fileSystems\": true, \"formData\": true, "
29 "\"history\": true, \"indexedDB\": true, \"localStorage\": true, "
30 "\"lsoData\": 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_time_;
38 }
39
40 int GetRemovalMask() {
41 return called_with_mask_;
42 }
43
44 protected:
45 virtual void SetUpOnMainThread() {
46 called_with_mask_ = -1;
47 called_with_time_ = base::Time::UnixEpoch();
48 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
49 content::Source<Profile>(
50 browser()->profile()->GetOriginalProfile()));
51 }
52
53 // content::NotificationObserver implementation.
54 virtual void Observe(int type,
55 const content::NotificationSource& source,
56 const content::NotificationDetails& details) OVERRIDE {
57 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
58
59 LOG(ERROR) << "In `observe`.";
60
61 // We're not taking ownership of the details object, but simply storing
62 // copies of its contents.
63 BrowsingDataRemoverNotificationDetail* detail_pair(
64 content::Details<BrowsingDataRemoverNotificationDetail>(details).ptr());
65 called_with_time_ = detail_pair->first;
66 called_with_mask_ = detail_pair->second;
67
68 registrar_.RemoveAll();
69 }
70
71 private:
72 base::Time called_with_time_;
73 int called_with_mask_;
74 content::NotificationRegistrar registrar_;
75 };
76
77 } // namespace
78
79 IN_PROC_BROWSER_TEST_F(ExtensionClearTest, OneAtATime) {
80 BrowsingDataRemover::set_removing(true);
81 EXPECT_TRUE(MatchPattern(
82 RunFunctionAndReturnError(
83 new ClearBrowsingDataFunction(),
84 kClearEverythingArguments,
85 browser()),
86 extension_clear_api_constants::kOneAtATimeError));
87 BrowsingDataRemover::set_removing(false);
88
89 EXPECT_EQ(GetBeginTime(), base::Time::UnixEpoch());
90 EXPECT_EQ(GetRemovalMask(), -1);
91 }
92
93 IN_PROC_BROWSER_TEST_F(ExtensionClearTest, ClearBrowsingDataEverything) {
94 RunFunctionWithoutResult(new ClearBrowsingDataFunction(),
95 kClearEverythingArguments, browser());
96
97 EXPECT_NE(GetBeginTime(), base::Time::UnixEpoch());
98 EXPECT_EQ(GetRemovalMask(), (BrowsingDataRemover::REMOVE_SITE_DATA |
99 BrowsingDataRemover::REMOVE_CACHE |
100 BrowsingDataRemover::REMOVE_DOWNLOADS |
101 BrowsingDataRemover::REMOVE_FORM_DATA |
102 BrowsingDataRemover::REMOVE_HISTORY |
103 BrowsingDataRemover::REMOVE_PASSWORDS) &
104 // We can't remove LSO data inside a test profile.
105 ~BrowsingDataRemover::REMOVE_LSO_DATA);
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698