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

Unified Diff: chrome/browser/browsing_data_cookie_helper_browsertest.cc

Issue 7355025: Creat BrowsingDataCookieHelper and CannedBrowsingDataCookieHelper for logging cookies at UI thread. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/browsing_data_cookie_helper_browsertest.cc
===================================================================
--- chrome/browser/browsing_data_cookie_helper_browsertest.cc (revision 0)
+++ chrome/browser/browsing_data_cookie_helper_browsertest.cc (revision 0)
@@ -0,0 +1,150 @@
+// 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 "base/bind.h"
+#include "chrome/browser/browsing_data_cookie_helper.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/testing_profile.h"
+#include "chrome/test/ui_test_utils.h"
+#include "content/browser/browser_thread.h"
+
+namespace {
+
+class BrowsingDataCookieHelperTest : public InProcessBrowserTest {
+ public:
+ void CreatCookiesForTest() {
erikwright (departed) 2011/07/19 14:40:33 Creat -> Create
ycxiao1 2011/07/19 22:12:48 Done.
+ testing_profile_.CreateRequestContext();
+ scoped_refptr<net::CookieMonster> cookie_monster =
+ testing_profile_.GetCookieMonster();
+ cookie_monster->SetCookieWithOptions(
+ GURL("http://www.google.com"), "A=1", net::CookieOptions());
+ cookie_monster->SetCookieWithOptions(
+ GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions());
+ }
+
+ protected:
+ TestingProfile testing_profile_;
+};
+
+// Called back by BrowsingDataCookieHelper on the UI thread once the cookie
+// information has been retrieved.
+class StopTestOnCallback {
+ public:
+ explicit StopTestOnCallback(BrowsingDataCookieHelper* cookie_helper)
+ : cookie_helper_(cookie_helper) {
+ DCHECK(cookie_helper_);
+ }
+
+ void FetchCallback(const net::CookieList& cookies) {
erikwright (departed) 2011/07/19 14:40:33 Is there any reason why these callback methods can
ycxiao1 2011/07/19 22:12:48 Done.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ ASSERT_EQ(2UL, cookies.size());
+ cookie_list_ = cookies;
+ net::CookieList::const_iterator it = cookies.begin();
erikwright (departed) 2011/07/19 14:40:33 Is there any guarantee that the cookies will be de
ycxiao1 2011/07/19 22:12:48 The CookieMonster::GetAllCookies will sort the coo
+
+ ASSERT_TRUE(it != cookies.end());
+ EXPECT_EQ("www.google.com", it->Domain());
+ EXPECT_EQ("A", it->Name());
+
+ ASSERT_TRUE(++it != cookies.end());
+ EXPECT_EQ("www.gmail.google.com", it->Domain());
+ EXPECT_EQ("B", it->Name());
+
+ ASSERT_TRUE(++it == cookies.end());
+ MessageLoop::current()->Quit();
+ }
+
+ void DeleteCallback(const net::CookieList& cookies) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ ASSERT_EQ(1UL, cookies.size());
+ net::CookieList::const_iterator it = cookies.begin();
+
+ ASSERT_TRUE(it != cookies.end());
+ EXPECT_EQ("www.gmail.google.com", it->Domain());
+ EXPECT_EQ("B", it->Name());
+
+ ASSERT_TRUE(++it == cookies.end());
+ MessageLoop::current()->Quit();
+ }
+
+ void CannedUniqueCallback(const net::CookieList& cookies) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ ASSERT_EQ(1UL, cookies.size());
+ net::CookieList::const_iterator it = cookies.begin();
+
+ ASSERT_TRUE(it != cookies.end());
+ EXPECT_EQ("http://www.google.com/", it->Source());
+ EXPECT_EQ("A", it->Name());
+
+ ASSERT_TRUE(++it == cookies.end());
+ }
+
+ net::CookieList cookie_list_;
+
+ private:
+ BrowsingDataCookieHelper* cookie_helper_;
+};
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, FetchData) {
+ CreatCookiesForTest();
+ scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
+ new BrowsingDataCookieHelper(&testing_profile_));
+ StopTestOnCallback stop_test_on_callback(cookie_helper);
+
+ cookie_helper->StartFetching(
+ base::Bind(&StopTestOnCallback::FetchCallback,
+ base::Unretained(&stop_test_on_callback)));
+
+ // Blocks until StopTestOnCallback::Callback is notified.
+ ui_test_utils::RunMessageLoop();
+}
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
+ CreatCookiesForTest();
+ scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
+ new BrowsingDataCookieHelper(&testing_profile_));
+ StopTestOnCallback stop_test_on_callback(cookie_helper);
+
+ cookie_helper->StartFetching(
+ base::Bind(&StopTestOnCallback::FetchCallback,
+ base::Unretained(&stop_test_on_callback)));
+
+ // Blocks until StopTestOnCallback::Callback is notified.
+ ui_test_utils::RunMessageLoop();
+
+ net::CookieMonster::CanonicalCookie cookie =
+ stop_test_on_callback.cookie_list_[0];
+ cookie_helper->DeleteCookie(cookie);
+
+ cookie_helper->StartFetching(
+ base::Bind(&StopTestOnCallback::DeleteCallback,
+ base::Unretained(&stop_test_on_callback)));
+ ui_test_utils::RunMessageLoop();
+}
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, CannedUnique) {
+ const GURL origin("http://www.google.com");
+ net::CookieList cookie;
+
+ scoped_refptr<CannedBrowsingDataCookieHelper> helper(
+ new CannedBrowsingDataCookieHelper(&testing_profile_));
+ StopTestOnCallback callback(helper);
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddChangeCookie(origin, "A=1", net::CookieOptions());
+ helper->AddChangeCookie(origin, "A=1", net::CookieOptions());
+ helper->StartFetching(
+ base::Bind(&StopTestOnCallback::CannedUniqueCallback,
+ base::Unretained(&callback)));
+ cookie = helper->cookie_list();
erikwright (departed) 2011/07/19 14:40:33 If I understand correctly, you are using this acce
ycxiao1 2011/07/19 22:12:48 Done.
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+
+ helper->AddReadCookie(origin, cookie);
+ helper->AddReadCookie(origin, cookie);
+ helper->StartFetching(
+ base::Bind(&StopTestOnCallback::CannedUniqueCallback,
+ base::Unretained(&callback)));
+}
+
+} // namespace
Property changes on: chrome/browser/browsing_data_cookie_helper_browsertest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698