| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_timeouts.h" |
| 14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 15 #include "content/browser/browsing_data/conditional_cache_deletion_helper.h" | 16 #include "content/browser/browsing_data/conditional_cache_deletion_helper.h" |
| 16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/storage_partition.h" | 19 #include "content/public/browser/storage_partition.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/cache_test_util.h" | 21 #include "content/public/test/cache_test_util.h" |
| 21 #include "content/public/test/content_browser_test.h" | 22 #include "content/public/test/content_browser_test.h" |
| 22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
| 23 #include "net/disk_cache/disk_cache.h" | 24 #include "net/disk_cache/disk_cache.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Expect that the keys with values 56 and 42 were deleted. | 113 // Expect that the keys with values 56 and 42 were deleted. |
| 113 keys.erase("56"); | 114 keys.erase("56"); |
| 114 keys.erase("42"); | 115 keys.erase("42"); |
| 115 CompareRemainingKeys(keys); | 116 CompareRemainingKeys(keys); |
| 116 } | 117 } |
| 117 | 118 |
| 118 // Tests that ConditionalCacheDeletionHelper correctly constructs a condition | 119 // Tests that ConditionalCacheDeletionHelper correctly constructs a condition |
| 119 // for time and URL. | 120 // for time and URL. |
| 120 // | 121 // |
| 121 // Note: This test depends on the timing in cache backends and can be flaky | 122 // Note: This test depends on the timing in cache backends and can be flaky |
| 122 // if those backends are slow. If this turns out to be a problem, consider | 123 // if those backends are slow. |
| 123 // increasing the |timeout_ms| constant. | |
| 124 // | 124 // |
| 125 // Flakily timing out on Mac 10.11 (crbug.com/646119) and flakily | 125 // Flakily timing out on Mac 10.11 (crbug.com/646119) and flakily |
| 126 // failing on Linux/ChromeOS (crbug.com/624836). | 126 // failing on Linux/ChromeOS (crbug.com/624836) |
| 127 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_CHROMEOS) | 127 // --> Switched to tiny_timeout and enabled the test on all platforms to check |
| 128 // if it will be more stable now. |
| 129 #if false |
| 128 #define MAYBE_TimeAndURL DISABLED_TimeAndURL | 130 #define MAYBE_TimeAndURL DISABLED_TimeAndURL |
| 129 #else | 131 #else |
| 130 #define MAYBE_TimeAndURL TimeAndURL | 132 #define MAYBE_TimeAndURL TimeAndURL |
| 131 #endif | 133 #endif |
| 132 IN_PROC_BROWSER_TEST_F(ConditionalCacheDeletionHelperBrowserTest, | 134 IN_PROC_BROWSER_TEST_F(ConditionalCacheDeletionHelperBrowserTest, |
| 133 MAYBE_TimeAndURL) { | 135 MAYBE_TimeAndURL) { |
| 134 const int64_t timeout_ms = 1; | |
| 135 | 136 |
| 136 // Create some entries. | 137 // Create some entries. |
| 137 std::set<std::string> keys; | 138 std::set<std::string> keys; |
| 138 keys.insert("https://google.com/index.html"); | 139 keys.insert("https://google.com/index.html"); |
| 139 keys.insert("https://example.com/foo/bar/icon.png"); | 140 keys.insert("https://example.com/foo/bar/icon.png"); |
| 140 keys.insert("http://chrome.com"); | 141 keys.insert("http://chrome.com"); |
| 141 | 142 |
| 142 GetCacheTestUtil()->CreateCacheEntries(keys); | 143 GetCacheTestUtil()->CreateCacheEntries(keys); |
| 143 | 144 |
| 144 // Wait |timeout_ms| milliseconds for the cache to write the entries. | 145 // Wait some milliseconds for the cache to write the entries. |
| 145 // This assures that future entries will have timestamps strictly greater than | 146 // This assures that future entries will have timestamps strictly greater than |
| 146 // the ones we just added. | 147 // the ones we just added. |
| 147 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(timeout_ms)); | 148 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 148 base::Time now = base::Time::Now(); | 149 base::Time now = base::Time::Now(); |
| 149 | 150 |
| 150 // Create a few more entries with a later timestamp. | 151 // Create a few more entries with a later timestamp. |
| 151 std::set<std::string> newer_keys; | 152 std::set<std::string> newer_keys; |
| 152 newer_keys.insert("https://google.com/"); | 153 newer_keys.insert("https://google.com/"); |
| 153 newer_keys.insert("https://example.com/foo/bar/icon2.png"); | 154 newer_keys.insert("https://example.com/foo/bar/icon2.png"); |
| 154 newer_keys.insert("https://example.com/foo/bar/icon3.png"); | 155 newer_keys.insert("https://example.com/foo/bar/icon3.png"); |
| 155 newer_keys.insert("http://example.com/foo/bar/icon4.png"); | 156 newer_keys.insert("http://example.com/foo/bar/icon4.png"); |
| 156 | 157 |
| 157 GetCacheTestUtil()->CreateCacheEntries(newer_keys); | 158 GetCacheTestUtil()->CreateCacheEntries(newer_keys); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 170 WaitForTasksOnIOThread(); | 171 WaitForTasksOnIOThread(); |
| 171 | 172 |
| 172 // Expect that only "icon2.png" and "icon3.png" were deleted. | 173 // Expect that only "icon2.png" and "icon3.png" were deleted. |
| 173 keys.insert(newer_keys.begin(), newer_keys.end()); | 174 keys.insert(newer_keys.begin(), newer_keys.end()); |
| 174 keys.erase("https://example.com/foo/bar/icon2.png"); | 175 keys.erase("https://example.com/foo/bar/icon2.png"); |
| 175 keys.erase("https://example.com/foo/bar/icon3.png"); | 176 keys.erase("https://example.com/foo/bar/icon3.png"); |
| 176 CompareRemainingKeys(keys); | 177 CompareRemainingKeys(keys); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace content | 180 } // namespace content |
| OLD | NEW |