summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 14:19:35 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 14:19:35 +0000
commitf27fce5ea23a46ce60e213927e1b903b88c596ff (patch)
treec0987d1ee064da2969633b46e50398de13304814 /chrome/browser
parent415a01c0101f4323f2288f20a842dac54d1ac242 (diff)
downloadchromium_src-f27fce5ea23a46ce60e213927e1b903b88c596ff.zip
chromium_src-f27fce5ea23a46ce60e213927e1b903b88c596ff.tar.gz
chromium_src-f27fce5ea23a46ce60e213927e1b903b88c596ff.tar.bz2
Revert 35703 - Move code duplicated in two tests up into the TestingProfile.
Move TestURLRequestContextGetter and friends from CookieTreeModelTest and CookiesWindowControllerTest into TestingProfile. In the TestingProfile, return a valid CookieMonster and URLRequstContextGetter. BUG=None TEST=Covered by unit tests Review URL: http://codereview.chromium.org/525072 TBR=rsesek@chromium.org Review URL: http://codereview.chromium.org/521056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35704 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/cookies_window_controller_unittest.mm73
-rw-r--r--chrome/browser/cookies_tree_model_unittest.cc41
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc4
3 files changed, 89 insertions, 29 deletions
diff --git a/chrome/browser/cocoa/cookies_window_controller_unittest.mm b/chrome/browser/cocoa/cookies_window_controller_unittest.mm
index 91be2d6..0071ff1 100644
--- a/chrome/browser/cocoa/cookies_window_controller_unittest.mm
+++ b/chrome/browser/cocoa/cookies_window_controller_unittest.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2009-2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -7,7 +7,6 @@
#include "app/tree_model.h"
#import "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
-#include "chrome/browser/cocoa/browser_test_helper.h"
#import "chrome/browser/cocoa/cookies_window_controller.h"
#include "chrome/browser/cocoa/cocoa_test_helper.h"
#include "chrome/browser/net/url_request_context_getter.h"
@@ -54,15 +53,50 @@
}
@end
+// Copied from src/chrome/cookies_tree_model_unittest.cc.
namespace {
+class TestURLRequestContext : public URLRequestContext {
+ public:
+ TestURLRequestContext() {
+ cookie_store_ = new net::CookieMonster();
+ }
+};
+
+class TestURLRequestContextGetter : public URLRequestContextGetter {
+ public:
+ virtual URLRequestContext* GetURLRequestContext() {
+ if (!context_)
+ context_ = new TestURLRequestContext();
+ return context_.get();
+ }
+ private:
+ scoped_refptr<URLRequestContext> context_;
+};
+
+class CookieTestingProfile : public TestingProfile {
+ public:
+ virtual URLRequestContextGetter* GetRequestContext() {
+ if (!url_request_context_getter_.get())
+ url_request_context_getter_ = new TestURLRequestContextGetter();
+ return url_request_context_getter_.get();
+ }
+ virtual ~CookieTestingProfile() {}
+
+ net::CookieMonster* GetCookieMonster() {
+ return GetRequestContext()->GetCookieStore()->GetCookieMonster();
+ }
+
+ private:
+ scoped_refptr<URLRequestContextGetter> url_request_context_getter_;
+};
+
class CookiesWindowControllerTest : public CocoaTest {
public:
virtual void SetUp() {
CocoaTest::SetUp();
- TestingProfile* profile = browser_helper_.profile();
controller_.reset(
- [[CookiesWindowController alloc] initWithProfile:profile]);
+ [[CookiesWindowController alloc] initWithProfile:&profile_]);
}
virtual void TearDown() {
@@ -79,8 +113,7 @@ class CookiesWindowControllerTest : public CocoaTest {
return [controller_ modelObserver]->FindCocoaNode(node, start);
}
- protected:
- BrowserTestHelper browser_helper_;
+ CookieTestingProfile profile_;
scoped_nsobject<CookiesWindowController> controller_;
};
@@ -131,9 +164,9 @@ TEST_F(CookiesWindowControllerTest, FindCocoaNodeRecursive) {
}
TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeCookie) {
- net::CookieMonster* cm = browser_helper_.profile()->GetCookieMonster();
+ net::CookieMonster* cm = profile_.GetCookieMonster();
cm->SetCookie(GURL("http://foo.com"), "A=B");
- CookiesTreeModel model(browser_helper_.profile());
+ CookiesTreeModel model(&profile_);
// Root --> foo.com --> Cookies --> A. Create node for 'A'.
TreeModelNode* node = model.GetRoot()->GetChild(0)->GetChild(0)->GetChild(0);
@@ -152,9 +185,9 @@ TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeCookie) {
}
TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeRecursive) {
- net::CookieMonster* cm = browser_helper_.profile()->GetCookieMonster();
+ net::CookieMonster* cm = profile_.GetCookieMonster();
cm->SetCookie(GURL("http://foo.com"), "A=B");
- CookiesTreeModel model(browser_helper_.profile());
+ CookiesTreeModel model(&profile_);
// Root --> foo.com --> Cookies --> A. Create node for 'foo.com'.
CookieTreeNode* node = model.GetRoot()->GetChild(0);
@@ -191,12 +224,11 @@ TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeRecursive) {
TEST_F(CookiesWindowControllerTest, TreeNodesAdded) {
const GURL url = GURL("http://foo.com");
- TestingProfile* profile = browser_helper_.profile();
- net::CookieMonster* cm = profile->GetCookieMonster();
+ net::CookieMonster* cm = profile_.GetCookieMonster();
cm->SetCookie(url, "A=B");
controller_.reset(
- [[CookiesWindowController alloc] initWithProfile:profile]);
+ [[CookiesWindowController alloc] initWithProfile:&profile_]);
// Root --> foo.com --> Cookies.
NSMutableArray* cocoa_children =
@@ -230,14 +262,13 @@ TEST_F(CookiesWindowControllerTest, TreeNodesAdded) {
TEST_F(CookiesWindowControllerTest, TreeNodesRemoved) {
const GURL url = GURL("http://foo.com");
- TestingProfile* profile = browser_helper_.profile();
- net::CookieMonster* cm = profile->GetCookieMonster();
+ net::CookieMonster* cm = profile_.GetCookieMonster();
cm->SetCookie(url, "A=B");
cm->SetCookie(url, "C=D");
cm->SetCookie(url, "E=F");
controller_.reset(
- [[CookiesWindowController alloc] initWithProfile:profile]);
+ [[CookiesWindowController alloc] initWithProfile:&profile_]);
// Root --> foo.com --> Cookies.
NSMutableArray* cocoa_children =
@@ -260,14 +291,13 @@ TEST_F(CookiesWindowControllerTest, TreeNodesRemoved) {
TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) {
const GURL url = GURL("http://foo.com");
- TestingProfile* profile = browser_helper_.profile();
- net::CookieMonster* cm = profile->GetCookieMonster();
+ net::CookieMonster* cm = profile_.GetCookieMonster();
cm->SetCookie(url, "A=B");
cm->SetCookie(url, "C=D");
cm->SetCookie(url, "E=F");
controller_.reset(
- [[CookiesWindowController alloc] initWithProfile:profile]);
+ [[CookiesWindowController alloc] initWithProfile:&profile_]);
// Root --> foo.com --> Cookies.
NSMutableArray* cocoa_children =
@@ -307,12 +337,11 @@ TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) {
TEST_F(CookiesWindowControllerTest, TreeNodeChanged) {
const GURL url = GURL("http://foo.com");
- TestingProfile* profile = browser_helper_.profile();
- net::CookieMonster* cm = profile->GetCookieMonster();
+ net::CookieMonster* cm = profile_.GetCookieMonster();
cm->SetCookie(url, "A=B");
controller_.reset(
- [[CookiesWindowController alloc] initWithProfile:profile]);
+ [[CookiesWindowController alloc] initWithProfile:&profile_]);
CookiesTreeModel* model = [controller_ treeModel];
// Root --> foo.com --> Cookies.
diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc
index 8ed45a5..317c003 100644
--- a/chrome/browser/cookies_tree_model_unittest.cc
+++ b/chrome/browser/cookies_tree_model_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009-2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -15,6 +15,41 @@
namespace {
+class TestURLRequestContext : public URLRequestContext {
+ public:
+ TestURLRequestContext() {
+ cookie_store_ = new net::CookieMonster();
+ }
+};
+
+class TestURLRequestContextGetter : public URLRequestContextGetter {
+ public:
+ virtual URLRequestContext* GetURLRequestContext() {
+ if (!context_)
+ context_ = new TestURLRequestContext();
+ return context_.get();
+ }
+ private:
+ scoped_refptr<URLRequestContext> context_;
+};
+
+class CookieTestingProfile : public TestingProfile {
+ public:
+ virtual URLRequestContextGetter* GetRequestContext() {
+ if (!url_request_context_getter_.get())
+ url_request_context_getter_ = new TestURLRequestContextGetter;
+ return url_request_context_getter_.get();
+ }
+ virtual ~CookieTestingProfile() {}
+
+ net::CookieMonster* GetCookieMonster() {
+ return GetRequestContext()->GetCookieStore()->GetCookieMonster();
+ }
+
+ private:
+ scoped_refptr<URLRequestContextGetter> url_request_context_getter_;
+};
+
class CookiesTreeModelTest : public testing::Test {
public:
CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) {
@@ -24,7 +59,7 @@ class CookiesTreeModelTest : public testing::Test {
}
virtual void SetUp() {
- profile_.reset(new TestingProfile());
+ profile_.reset(new CookieTestingProfile());
}
// Get the cookie names in the cookie list, as a comma seperated string.
@@ -81,7 +116,7 @@ class CookiesTreeModelTest : public testing::Test {
MessageLoop message_loop_;
ChromeThread io_thread_;
- scoped_ptr<TestingProfile> profile_;
+ scoped_ptr<CookieTestingProfile> profile_;
};
TEST_F(CookiesTreeModelTest, RemoveAll) {
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index e9129e8..82a8880 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -211,10 +211,6 @@ class ExtensionTestingProfile : public TestingProfile {
service_ = NULL;
}
- // Duplicate old functionality from TestingProfile. The ContextGetter
- // provided by TestingProfile only has support for the CookieMonster.
- virtual URLRequestContextGetter* GetRequestContext() { return NULL; }
-
virtual ExtensionsService* GetExtensionsService() {
return service_.get();
}