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

Side by Side Diff: chrome/browser/android/signin/signin_manager_android_unittest.cc

Issue 2966763003: [Prototype] Delete Google service worker caches on Android signout (Closed)
Patch Set: Fix the test. Created 3 years, 5 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
(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_service_worker_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, DeleteGoogleServiceWorkers) {
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<CannedBrowsingDataServiceWorkerHelper> helper(
68 new CannedBrowsingDataServiceWorkerHelper(
69 content::BrowserContext::GetDefaultStoragePartition(profile())
70 ->GetServiceWorkerContext()));
71
72 for (const TestCase& test_case : kTestCases) {
73 std::vector<GURL> scopes = {GURL("/")}; // the entire origin
74 helper->AddServiceWorker(GURL(test_case.worker_url), scopes);
75 }
76
77 ASSERT_EQ(arraysize(kTestCases), helper->GetServiceWorkerCount());
78
79 // Delete service workers and wait for completion.
80 base::RunLoop run_loop;
81 SigninManagerAndroid::WipeData(profile(), false /* only service workers */,
82 run_loop.QuitClosure());
83 run_loop.Run();
84
85 // Test whether the correct service workers were deleted.
86 std::set<std::string> remaining_workers;
87 for (const auto& info : helper->GetServiceWorkerUsageInfo())
88 remaining_workers.insert(info.origin.spec());
89
90 for (const TestCase& test_case : kTestCases) {
91 EXPECT_EQ(test_case.should_be_deleted,
92 base::ContainsKey(remaining_workers, test_case.worker_url))
93 << test_case.worker_url << " should "
94 << (test_case.should_be_deleted ? "" : "NOT ")
95 << "be deleted, but it was"
96 << (test_case.should_be_deleted ? "NOT" : "") << ".";
97 }
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698