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" |
14 #include "chrome/test/test_url_request_context_getter.h" | |
erikwright (departed)
2011/07/25 16:27:16
Do you need this, or just url_request_context_gett
| |
13 #include "chrome/test/testing_profile.h" | 15 #include "chrome/test/testing_profile.h" |
14 #include "content/browser/appcache/chrome_appcache_service.h" | 16 #include "content/browser/appcache/chrome_appcache_service.h" |
17 #include "net/base/cookie_monster.h" | |
18 #include "net/url_request/url_request_context.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webkit/appcache/appcache.h" | 20 #include "webkit/appcache/appcache.h" |
17 #include "webkit/appcache/appcache_group.h" | 21 #include "webkit/appcache/appcache_group.h" |
18 #include "webkit/appcache/appcache_storage.h" | 22 #include "webkit/appcache/appcache_storage.h" |
19 #include "webkit/fileapi/file_system_context.h" | 23 #include "webkit/fileapi/file_system_context.h" |
20 #include "webkit/fileapi/file_system_operation_context.h" | 24 #include "webkit/fileapi/file_system_operation_context.h" |
21 #include "webkit/fileapi/file_system_file_util.h" | 25 #include "webkit/fileapi/file_system_file_util.h" |
22 #include "webkit/fileapi/file_system_path_manager.h" | 26 #include "webkit/fileapi/file_system_path_manager.h" |
23 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 27 #include "webkit/fileapi/sandbox_mount_point_provider.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 const GURL kProtectedManifest("http://www.protected.com/cache.manifest"); | 39 const GURL kProtectedManifest("http://www.protected.com/cache.manifest"); |
36 const GURL kNormalManifest("http://www.normal.com/cache.manifest"); | 40 const GURL kNormalManifest("http://www.normal.com/cache.manifest"); |
37 | 41 |
38 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { | 42 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { |
39 public: | 43 public: |
40 BrowsingDataRemoverTester() {} | 44 BrowsingDataRemoverTester() |
45 : start_(false), | |
46 already_quit_(false) {} | |
41 virtual ~BrowsingDataRemoverTester() {} | 47 virtual ~BrowsingDataRemoverTester() {} |
42 | 48 |
43 void BlockUntilNotified() { | 49 void BlockUntilNotified() { |
44 MessageLoop::current()->Run(); | 50 if (!already_quit_) { |
51 start_ = true; | |
52 MessageLoop::current()->Run(); | |
53 } else { | |
54 already_quit_ = false; | |
55 } | |
45 } | 56 } |
46 | 57 |
47 protected: | 58 protected: |
48 // BrowsingDataRemover::Observer implementation. | 59 // BrowsingDataRemover::Observer implementation. |
49 virtual void OnBrowsingDataRemoverDone() { | 60 virtual void OnBrowsingDataRemoverDone() { |
50 Notify(); | 61 Notify(); |
51 } | 62 } |
52 | 63 |
53 void Notify() { | 64 void Notify() { |
54 MessageLoop::current()->Quit(); | 65 if (start_) { |
66 MessageLoop::current()->Quit(); | |
67 start_ = false; | |
68 } else { | |
69 already_quit_ = true; | |
70 } | |
55 } | 71 } |
56 | 72 |
57 private: | 73 private: |
74 // Helps prevent from running message_loop, if the callback invoked | |
75 // immediately. | |
76 bool start_; | |
77 bool already_quit_; | |
78 | |
58 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester); | 79 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester); |
59 }; | 80 }; |
60 | 81 |
82 class RemoveCookieTester : public BrowsingDataRemoverTester { | |
83 public: | |
84 explicit RemoveCookieTester(TestingProfile* profile) { | |
85 profile->CreateRequestContext(); | |
86 monster_ = profile->GetRequestContext()->GetURLRequestContext()-> | |
87 cookie_store()->GetCookieMonster(); | |
88 } | |
89 | |
90 // Returns true, if the given cookie exists in the cookie store. | |
91 bool ContainsCookie() { | |
92 monster_->GetCookiesAsync(kOrigin1, | |
93 base::Bind(&RemoveCookieTester::GetCookieCallback, | |
94 base::Unretained(this))); | |
95 BlockUntilNotified(); | |
96 return get_cookie_success_; | |
97 } | |
98 | |
99 void AddCookie() { | |
100 monster_->SetCookieWithOptionsAsync( | |
101 kOrigin1, "A=1", net::CookieOptions(), | |
102 base::Bind(&RemoveCookieTester::SetCookieCallback, | |
103 base::Unretained(this))); | |
104 BlockUntilNotified(); | |
105 } | |
106 | |
107 private: | |
108 void GetCookieCallback(const std::string& cookies) { | |
109 if (cookies == "A=1") { | |
110 get_cookie_success_ = true; | |
111 } else { | |
112 EXPECT_EQ(cookies, ""); | |
113 get_cookie_success_ = false; | |
114 } | |
115 Notify(); | |
116 } | |
117 | |
118 void SetCookieCallback(bool result) { | |
119 ASSERT_TRUE(result); | |
120 Notify(); | |
121 } | |
122 | |
123 bool get_cookie_success_; | |
124 | |
125 net::CookieStore* monster_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); | |
128 }; | |
129 | |
61 class RemoveHistoryTester : public BrowsingDataRemoverTester { | 130 class RemoveHistoryTester : public BrowsingDataRemoverTester { |
62 public: | 131 public: |
63 explicit RemoveHistoryTester(TestingProfile* profile) | 132 explicit RemoveHistoryTester(TestingProfile* profile) |
64 : query_url_success_(false) { | 133 : query_url_success_(false) { |
65 profile->CreateHistoryService(true, false); | 134 profile->CreateHistoryService(true, false); |
66 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 135 history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
67 } | 136 } |
68 | 137 |
69 // Returns true, if the given URL exists in the history service. | 138 // Returns true, if the given URL exists in the history service. |
70 bool HistoryContainsURL(const GURL& url) { | 139 bool HistoryContainsURL(const GURL& url) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 BrowserThread ui_thread_; | 369 BrowserThread ui_thread_; |
301 BrowserThread db_thread_; | 370 BrowserThread db_thread_; |
302 BrowserThread webkit_thread_; | 371 BrowserThread webkit_thread_; |
303 BrowserThread file_thread_; | 372 BrowserThread file_thread_; |
304 BrowserThread io_thread_; | 373 BrowserThread io_thread_; |
305 scoped_ptr<TestingProfile> profile_; | 374 scoped_ptr<TestingProfile> profile_; |
306 | 375 |
307 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 376 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
308 }; | 377 }; |
309 | 378 |
379 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { | |
380 scoped_ptr<RemoveCookieTester> tester( | |
381 new RemoveCookieTester(GetProfile())); | |
382 | |
383 tester->AddCookie(); | |
384 ASSERT_TRUE(tester->ContainsCookie()); | |
385 | |
386 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | |
387 base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); | |
388 | |
389 EXPECT_FALSE(tester->ContainsCookie()); | |
390 } | |
391 | |
310 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { | 392 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { |
311 scoped_ptr<RemoveHistoryTester> tester( | 393 scoped_ptr<RemoveHistoryTester> tester( |
312 new RemoveHistoryTester(GetProfile())); | 394 new RemoveHistoryTester(GetProfile())); |
313 | 395 |
314 tester->AddHistory(kOrigin1, base::Time::Now()); | 396 tester->AddHistory(kOrigin1, base::Time::Now()); |
315 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 397 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
316 | 398 |
317 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 399 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
318 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); | 400 base::Time::Now(), BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
319 | 401 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 tester->BlockUntilNotified(); | 487 tester->BlockUntilNotified(); |
406 | 488 |
407 // Results: appcaches for the normal origin got deleted, appcaches for the | 489 // Results: appcaches for the normal origin got deleted, appcaches for the |
408 // protected origin didn't. | 490 // protected origin didn't. |
409 origins = reader.ReadAppCaches(); | 491 origins = reader.ReadAppCaches(); |
410 EXPECT_EQ(1UL, origins->size()); | 492 EXPECT_EQ(1UL, origins->size()); |
411 EXPECT_TRUE(origins->find(kProtectedManifest.GetOrigin()) != origins->end()); | 493 EXPECT_TRUE(origins->find(kProtectedManifest.GetOrigin()) != origins->end()); |
412 } | 494 } |
413 | 495 |
414 } // namespace | 496 } // namespace |
OLD | NEW |