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

Side by Side Diff: chrome/browser/cookies_tree_model_unittest.cc

Issue 525106: Move code duplicated in two tests up into the TestingProfile. (Closed)
Patch Set: Created 10 years, 11 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/cookies_tree_model.h" 5 #include "chrome/browser/cookies_tree_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "chrome/browser/net/url_request_context_getter.h" 10 #include "chrome/browser/net/url_request_context_getter.h"
11 #include "chrome/test/testing_profile.h" 11 #include "chrome/test/testing_profile.h"
12 #include "net/url_request/url_request_context.h" 12 #include "net/url_request/url_request_context.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 15
16 namespace { 16 namespace {
17 17
18 class TestURLRequestContext : public URLRequestContext {
19 public:
20 TestURLRequestContext() {
21 cookie_store_ = new net::CookieMonster();
22 }
23 };
24
25 class TestURLRequestContextGetter : public URLRequestContextGetter {
26 public:
27 virtual URLRequestContext* GetURLRequestContext() {
28 if (!context_)
29 context_ = new TestURLRequestContext();
30 return context_.get();
31 }
32 private:
33 scoped_refptr<URLRequestContext> context_;
34 };
35
36 class CookieTestingProfile : public TestingProfile {
37 public:
38 virtual URLRequestContextGetter* GetRequestContext() {
39 if (!url_request_context_getter_.get())
40 url_request_context_getter_ = new TestURLRequestContextGetter;
41 return url_request_context_getter_.get();
42 }
43 virtual ~CookieTestingProfile() {}
44
45 net::CookieMonster* GetCookieMonster() {
46 return GetRequestContext()->GetCookieStore()->GetCookieMonster();
47 }
48
49 private:
50 scoped_refptr<URLRequestContextGetter> url_request_context_getter_;
51 };
52
53 class CookiesTreeModelTest : public testing::Test { 18 class CookiesTreeModelTest : public testing::Test {
54 public: 19 public:
55 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) { 20 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) {
56 } 21 }
57 22
58 virtual ~CookiesTreeModelTest() { 23 virtual ~CookiesTreeModelTest() {
59 } 24 }
60 25
61 virtual void SetUp() { 26 virtual void SetUp() {
62 profile_.reset(new CookieTestingProfile()); 27 profile_.reset(new TestingProfile());
28 profile_->CreateRequestContext();
63 } 29 }
64 30
65 // Get the cookie names in the cookie list, as a comma seperated string. 31 // Get the cookie names in the cookie list, as a comma seperated string.
66 // (Note that the CookieMonster cookie list is sorted by domain.) 32 // (Note that the CookieMonster cookie list is sorted by domain.)
67 // Ex: 33 // Ex:
68 // monster->SetCookie(GURL("http://b"), "X=1") 34 // monster->SetCookie(GURL("http://b"), "X=1")
69 // monster->SetCookie(GURL("http://a"), "Y=1") 35 // monster->SetCookie(GURL("http://a"), "Y=1")
70 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); 36 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str());
71 std::string GetMonsterCookies(net::CookieMonster* monster) { 37 std::string GetMonsterCookies(net::CookieMonster* monster) {
72 std::vector<std::string> parts; 38 std::vector<std::string> parts;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // find the parent and index 75 // find the parent and index
110 CookieTreeNode* parent_node = node->GetParent(); 76 CookieTreeNode* parent_node = node->GetParent();
111 DCHECK(parent_node); 77 DCHECK(parent_node);
112 int ct_node_index = parent_node->IndexOfChild(node); 78 int ct_node_index = parent_node->IndexOfChild(node);
113 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); 79 delete parent_node->GetModel()->Remove(parent_node, ct_node_index);
114 } 80 }
115 protected: 81 protected:
116 MessageLoop message_loop_; 82 MessageLoop message_loop_;
117 ChromeThread io_thread_; 83 ChromeThread io_thread_;
118 84
119 scoped_ptr<CookieTestingProfile> profile_; 85 scoped_ptr<TestingProfile> profile_;
120 }; 86 };
121 87
122 TEST_F(CookiesTreeModelTest, RemoveAll) { 88 TEST_F(CookiesTreeModelTest, RemoveAll) {
123 net::CookieMonster* monster = profile_->GetCookieMonster(); 89 net::CookieMonster* monster = profile_->GetCookieMonster();
124 monster->SetCookie(GURL("http://foo"), "A=1"); 90 monster->SetCookie(GURL("http://foo"), "A=1");
125 monster->SetCookie(GURL("http://foo2"), "B=1"); 91 monster->SetCookie(GURL("http://foo2"), "B=1");
126 CookiesTreeModel cookies_model(profile_.get()); 92 CookiesTreeModel cookies_model(profile_.get());
127 93
128 // Reset the selection of the first row. 94 // Reset the selection of the first row.
129 { 95 {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 { 283 {
318 SCOPED_TRACE("Second origin removed"); 284 SCOPED_TRACE("Second origin removed");
319 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); 285 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str());
320 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); 286 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str());
321 } 287 }
322 } 288 }
323 289
324 290
325 291
326 } // namespace 292 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698