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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_clear_test.cc
diff --git a/chrome/browser/extensions/extension_clear_test.cc b/chrome/browser/extensions/extension_clear_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..17ec1a2112b11d561f3f3fe95aae6aa1b002bf10
--- /dev/null
+++ b/chrome/browser/extensions/extension_clear_test.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_clear_api.h"
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "base/values.h"
+#include "chrome/browser/browsing_data_remover.h"
+#include "chrome/browser/extensions/extension_function_test_utils.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/notification_service.h"
+
+using namespace extension_function_test_utils;
+
+namespace {
+
+const char kClearEverythingArguments[] = "[\"everything\", {"
+ "\"appcache\": true, \"cache\": true, \"cookies\": true, "
+ "\"downloads\": true, \"fileSystems\": true, \"formData\": true, "
+ "\"history\": true, \"indexedDB\": true, \"localStorage\": true, "
+ "\"lsoData\": true, \"passwords\": true, \"webSQL\": true"
+ "}]";
+
+class ExtensionClearTest : public InProcessBrowserTest,
+ public content::NotificationObserver {
+ public:
+ base::Time GetBeginTime() {
+ return called_with_time_;
+ }
+
+ int GetRemovalMask() {
+ return called_with_mask_;
+ }
+
+ protected:
+ virtual void SetUpOnMainThread() {
+ called_with_mask_ = -1;
+ called_with_time_ = base::Time::UnixEpoch();
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
+ content::Source<Profile>(
+ browser()->profile()->GetOriginalProfile()));
+ }
+
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE {
+ DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
+
+ LOG(ERROR) << "In `observe`.";
+
+ // We're not taking ownership of the details object, but simply storing
+ // copies of its contents.
+ BrowsingDataRemoverNotificationDetail* detail_pair(
+ content::Details<BrowsingDataRemoverNotificationDetail>(details).ptr());
+ called_with_time_ = detail_pair->first;
+ called_with_mask_ = detail_pair->second;
+
+ registrar_.RemoveAll();
+ }
+
+ private:
+ base::Time called_with_time_;
+ int called_with_mask_;
+ content::NotificationRegistrar registrar_;
+};
+
+} // namespace
+
+IN_PROC_BROWSER_TEST_F(ExtensionClearTest, OneAtATime) {
+ BrowsingDataRemover::set_removing(true);
+ EXPECT_TRUE(MatchPattern(
+ RunFunctionAndReturnError(
+ new ClearBrowsingDataFunction(),
+ kClearEverythingArguments,
+ browser()),
+ extension_clear_api_constants::kOneAtATimeError));
+ BrowsingDataRemover::set_removing(false);
+
+ EXPECT_EQ(GetBeginTime(), base::Time::UnixEpoch());
+ EXPECT_EQ(GetRemovalMask(), -1);
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionClearTest, ClearBrowsingDataEverything) {
+ RunFunctionWithoutResult(new ClearBrowsingDataFunction(),
+ kClearEverythingArguments, browser());
+
+ EXPECT_NE(GetBeginTime(), base::Time::UnixEpoch());
+ EXPECT_EQ(GetRemovalMask(), (BrowsingDataRemover::REMOVE_SITE_DATA |
+ BrowsingDataRemover::REMOVE_CACHE |
+ BrowsingDataRemover::REMOVE_DOWNLOADS |
+ BrowsingDataRemover::REMOVE_FORM_DATA |
+ BrowsingDataRemover::REMOVE_HISTORY |
+ BrowsingDataRemover::REMOVE_PASSWORDS) &
+ // We can't remove LSO data inside a test profile.
+ ~BrowsingDataRemover::REMOVE_LSO_DATA);
+}

Powered by Google App Engine
This is Rietveld 408576698