OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
11 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" | 12 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" |
12 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
14 #include "chrome/test/testing_browser_process_test.h" | 15 #include "chrome/test/testing_browser_process_test.h" |
| 16 #include "net/base/cookie_monster.h" |
| 17 #include "net/url_request/url_request_context.h" |
| 18 #include "net/url_request/url_request_context_getter.cc" |
15 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webkit/fileapi/file_system_context.h" | 20 #include "webkit/fileapi/file_system_context.h" |
17 #include "webkit/fileapi/file_system_file_util.h" | 21 #include "webkit/fileapi/file_system_file_util.h" |
18 #include "webkit/fileapi/file_system_operation_context.h" | 22 #include "webkit/fileapi/file_system_operation_context.h" |
19 #include "webkit/fileapi/file_system_path_manager.h" | 23 #include "webkit/fileapi/file_system_path_manager.h" |
20 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
21 #include "webkit/quota/mock_quota_manager.h" | 25 #include "webkit/quota/mock_quota_manager.h" |
22 #include "webkit/quota/quota_manager.h" | 26 #include "webkit/quota/quota_manager.h" |
23 #include "webkit/quota/quota_types.h" | 27 #include "webkit/quota/quota_types.h" |
24 | 28 |
25 namespace { | 29 namespace { |
26 | 30 |
27 const char kTestkOrigin1[] = "http://host1:1/"; | 31 const char kTestkOrigin1[] = "http://host1:1/"; |
28 const char kTestkOrigin2[] = "http://host2:1/"; | 32 const char kTestkOrigin2[] = "http://host2:1/"; |
29 const char kTestkOrigin3[] = "http://host3:1/"; | 33 const char kTestkOrigin3[] = "http://host3:1/"; |
30 | 34 |
31 const GURL kOrigin1(kTestkOrigin1); | 35 const GURL kOrigin1(kTestkOrigin1); |
32 const GURL kOrigin2(kTestkOrigin2); | 36 const GURL kOrigin2(kTestkOrigin2); |
33 const GURL kOrigin3(kTestkOrigin3); | 37 const GURL kOrigin3(kTestkOrigin3); |
34 | 38 |
35 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { | 39 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { |
36 public: | 40 public: |
37 BrowsingDataRemoverTester() {} | 41 BrowsingDataRemoverTester() |
| 42 : start_(false), |
| 43 already_quit_(false) {} |
38 virtual ~BrowsingDataRemoverTester() {} | 44 virtual ~BrowsingDataRemoverTester() {} |
39 | 45 |
40 void BlockUntilNotified() { | 46 void BlockUntilNotified() { |
41 MessageLoop::current()->Run(); | 47 if (!already_quit_) { |
| 48 DCHECK(!start_); |
| 49 start_ = true; |
| 50 MessageLoop::current()->Run(); |
| 51 } else { |
| 52 DCHECK(!start_); |
| 53 already_quit_ = false; |
| 54 } |
42 } | 55 } |
43 | 56 |
44 protected: | 57 protected: |
45 // BrowsingDataRemover::Observer implementation. | 58 // BrowsingDataRemover::Observer implementation. |
46 virtual void OnBrowsingDataRemoverDone() { | 59 virtual void OnBrowsingDataRemoverDone() { |
47 Notify(); | 60 Notify(); |
48 } | 61 } |
49 | 62 |
50 void Notify() { | 63 void Notify() { |
51 MessageLoop::current()->Quit(); | 64 if (start_) { |
| 65 DCHECK(!already_quit_); |
| 66 MessageLoop::current()->Quit(); |
| 67 start_ = false; |
| 68 } else { |
| 69 DCHECK(!already_quit_); |
| 70 already_quit_ = true; |
| 71 } |
52 } | 72 } |
53 | 73 |
54 private: | 74 private: |
| 75 // Helps prevent from running message_loop, if the callback invoked |
| 76 // immediately. |
| 77 bool start_; |
| 78 bool already_quit_; |
| 79 |
55 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester); | 80 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester); |
56 }; | 81 }; |
57 | 82 |
58 // Testers ------------------------------------------------------------------- | 83 // Testers ------------------------------------------------------------------- |
59 | 84 |
| 85 class RemoveCookieTester : public BrowsingDataRemoverTester { |
| 86 public: |
| 87 explicit RemoveCookieTester(TestingProfile* profile) |
| 88 : get_cookie_success_(false) { |
| 89 profile->CreateRequestContext(); |
| 90 monster_ = profile->GetRequestContext()->GetURLRequestContext()-> |
| 91 cookie_store()->GetCookieMonster(); |
| 92 } |
| 93 |
| 94 // Returns true, if the given cookie exists in the cookie store. |
| 95 bool ContainsCookie() { |
| 96 get_cookie_success_ = false; |
| 97 monster_->GetCookiesWithOptionsAsync( |
| 98 kOrigin1, net::CookieOptions(), |
| 99 base::Bind(&RemoveCookieTester::GetCookieCallback, |
| 100 base::Unretained(this))); |
| 101 BlockUntilNotified(); |
| 102 return get_cookie_success_; |
| 103 } |
| 104 |
| 105 void AddCookie() { |
| 106 monster_->SetCookieWithOptionsAsync( |
| 107 kOrigin1, "A=1", net::CookieOptions(), |
| 108 base::Bind(&RemoveCookieTester::SetCookieCallback, |
| 109 base::Unretained(this))); |
| 110 BlockUntilNotified(); |
| 111 } |
| 112 |
| 113 private: |
| 114 void GetCookieCallback(const std::string& cookies) { |
| 115 if (cookies == "A=1") { |
| 116 get_cookie_success_ = true; |
| 117 } else { |
| 118 EXPECT_EQ(cookies, ""); |
| 119 get_cookie_success_ = false; |
| 120 } |
| 121 Notify(); |
| 122 } |
| 123 |
| 124 void SetCookieCallback(bool result) { |
| 125 ASSERT_TRUE(result); |
| 126 Notify(); |
| 127 } |
| 128 |
| 129 bool get_cookie_success_; |
| 130 |
| 131 net::CookieStore* monster_; |
| 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); |
| 134 }; |
| 135 |
60 class RemoveHistoryTester : public BrowsingDataRemoverTester { | 136 class RemoveHistoryTester : public BrowsingDataRemoverTester { |
61 public: | 137 public: |
62 explicit RemoveHistoryTester(TestingProfile* profile) | 138 explicit RemoveHistoryTester(TestingProfile* profile) |
63 : query_url_success_(false) { | 139 : query_url_success_(false) { |
64 profile->CreateHistoryService(true, false); | 140 profile->CreateHistoryService(true, false); |
65 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 141 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
66 } | 142 } |
67 | 143 |
68 // Returns true, if the given URL exists in the history service. | 144 // Returns true, if the given URL exists in the history service. |
69 bool HistoryContainsURL(const GURL& url) { | 145 bool HistoryContainsURL(const GURL& url) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 BrowserThread webkit_thread_; | 289 BrowserThread webkit_thread_; |
214 BrowserThread file_thread_; | 290 BrowserThread file_thread_; |
215 BrowserThread io_thread_; | 291 BrowserThread io_thread_; |
216 scoped_ptr<TestingProfile> profile_; | 292 scoped_ptr<TestingProfile> profile_; |
217 | 293 |
218 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 294 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
219 }; | 295 }; |
220 | 296 |
221 // Tests --------------------------------------------------------------------- | 297 // Tests --------------------------------------------------------------------- |
222 | 298 |
| 299 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { |
| 300 scoped_ptr<RemoveCookieTester> tester( |
| 301 new RemoveCookieTester(GetProfile())); |
| 302 |
| 303 tester->AddCookie(); |
| 304 ASSERT_TRUE(tester->ContainsCookie()); |
| 305 |
| 306 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 307 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 308 |
| 309 EXPECT_FALSE(tester->ContainsCookie()); |
| 310 } |
| 311 |
223 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { | 312 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { |
224 scoped_ptr<RemoveHistoryTester> tester( | 313 scoped_ptr<RemoveHistoryTester> tester( |
225 new RemoveHistoryTester(GetProfile())); | 314 new RemoveHistoryTester(GetProfile())); |
226 | 315 |
227 tester->AddHistory(kOrigin1, base::Time::Now()); | 316 tester->AddHistory(kOrigin1, base::Time::Now()); |
228 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 317 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
229 | 318 |
230 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 319 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
231 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); | 320 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
232 | 321 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 quota::kStorageTypeTemporary)); | 494 quota::kStorageTypeTemporary)); |
406 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 495 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
407 quota::kStorageTypePersistent)); | 496 quota::kStorageTypePersistent)); |
408 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 497 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
409 quota::kStorageTypePersistent)); | 498 quota::kStorageTypePersistent)); |
410 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 499 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
411 quota::kStorageTypePersistent)); | 500 quota::kStorageTypePersistent)); |
412 } | 501 } |
413 | 502 |
414 } // namespace | 503 } // namespace |
OLD | NEW |