OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "signin_manager_android.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <set> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/run_loop.h" |
| 12 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "chrome/test/base/testing_profile_manager.h" |
| 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browsing_data_remover.h" |
| 17 #include "content/public/browser/storage_partition.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 |
| 21 class SigninManagerAndroidTest : public ::testing::Test { |
| 22 public: |
| 23 SigninManagerAndroidTest() |
| 24 : profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
| 25 ~SigninManagerAndroidTest() override{}; |
| 26 |
| 27 void SetUp() override { |
| 28 ASSERT_TRUE(profile_manager_.SetUp()); |
| 29 profile_ = profile_manager_.CreateTestingProfile("Testing Profile"); |
| 30 } |
| 31 |
| 32 TestingProfile* profile() { return profile_; } |
| 33 |
| 34 private: |
| 35 content::TestBrowserThreadBundle thread_bundle_; |
| 36 TestingProfileManager profile_manager_; |
| 37 TestingProfile* profile_; // Owned by |profile_manager_|. |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(SigninManagerAndroidTest); |
| 40 }; |
| 41 |
| 42 TEST_F(SigninManagerAndroidTest, DeleteGoogleServiceWorkerCaches) { |
| 43 struct TestCase { |
| 44 std::string worker_url; |
| 45 bool should_be_deleted; |
| 46 } kTestCases[] = { |
| 47 // A Google domain. |
| 48 {"https://google.com/foo/bar", true}, |
| 49 |
| 50 // A Google domain with long TLD. |
| 51 {"https://plus.google.co.uk/?query_params", true}, |
| 52 |
| 53 // Youtube. |
| 54 {"https://youtube.com", false}, |
| 55 |
| 56 // A random domain. |
| 57 {"https://a.b.c.example.com", false}, |
| 58 |
| 59 // Another Google domain. |
| 60 {"https://www.google.de/worker.html", true}, |
| 61 |
| 62 // Ports don't matter, only TLDs. |
| 63 {"https://google.com:8444/worker.html", true}, |
| 64 }; |
| 65 |
| 66 // Add service workers. |
| 67 scoped_refptr<CannedBrowsingDataCacheStorageHelper> helper( |
| 68 new CannedBrowsingDataCacheStorageHelper( |
| 69 content::BrowserContext::GetDefaultStoragePartition(profile()) |
| 70 ->GetCacheStorageContext())); |
| 71 |
| 72 for (const TestCase& test_case : kTestCases) |
| 73 helper->AddCacheStorage(GURL(test_case.worker_url)); |
| 74 |
| 75 ASSERT_EQ(arraysize(kTestCases), helper->GetCacheStorageCount()); |
| 76 |
| 77 // Delete service workers and wait for completion. |
| 78 base::RunLoop run_loop; |
| 79 SigninManagerAndroid::WipeData(profile(), |
| 80 false /* only Google service worker caches */, |
| 81 run_loop.QuitClosure()); |
| 82 run_loop.Run(); |
| 83 |
| 84 // Test whether the correct service worker caches were deleted. |
| 85 std::set<std::string> remaining_cache_storages; |
| 86 for (const auto& info : helper->GetCacheStorageUsageInfo()) |
| 87 remaining_cache_storages.insert(info.origin.spec()); |
| 88 |
| 89 for (const TestCase& test_case : kTestCases) { |
| 90 EXPECT_EQ(test_case.should_be_deleted, |
| 91 base::ContainsKey(remaining_cache_storages, test_case.worker_url)) |
| 92 << test_case.worker_url << " should " |
| 93 << (test_case.should_be_deleted ? "" : "NOT ") |
| 94 << "be deleted, but it was" |
| 95 << (test_case.should_be_deleted ? "NOT" : "") << "."; |
| 96 } |
| 97 } |
OLD | NEW |