Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_service_worker_helper_unittest.cc
blob57a9b224ac09cdca844d86a6cbd0c7454086d702
1 // Copyright 2014 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.
5 #include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
7 #include <vector>
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/storage_partition.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace {
19 class CannedBrowsingDataServiceWorkerHelperTest : public testing::Test {
20 public:
21 content::ServiceWorkerContext* ServiceWorkerContext() {
22 return content::BrowserContext::GetDefaultStoragePartition(&profile_)->
23 GetServiceWorkerContext();
26 private:
27 content::TestBrowserThreadBundle thread_bundle_;
28 TestingProfile profile_;
31 TEST_F(CannedBrowsingDataServiceWorkerHelperTest, Empty) {
32 const GURL origin("https://host1:1/");
33 std::vector<GURL> scopes;
34 scopes.push_back(GURL("https://host1:1/*"));
36 scoped_refptr<CannedBrowsingDataServiceWorkerHelper> helper(
37 new CannedBrowsingDataServiceWorkerHelper(ServiceWorkerContext()));
39 ASSERT_TRUE(helper->empty());
40 helper->AddServiceWorker(origin, scopes);
41 ASSERT_FALSE(helper->empty());
42 helper->Reset();
43 ASSERT_TRUE(helper->empty());
46 TEST_F(CannedBrowsingDataServiceWorkerHelperTest, Delete) {
47 const GURL origin1("http://host1:9000");
48 std::vector<GURL> scopes1;
49 scopes1.push_back(GURL("http://host1:9000/*"));
51 const GURL origin2("https://example.com");
52 std::vector<GURL> scopes2;
53 scopes2.push_back(GURL("https://example.com/app1/*"));
54 scopes2.push_back(GURL("https://example.com/app2/*"));
56 scoped_refptr<CannedBrowsingDataServiceWorkerHelper> helper(
57 new CannedBrowsingDataServiceWorkerHelper(ServiceWorkerContext()));
59 EXPECT_TRUE(helper->empty());
60 helper->AddServiceWorker(origin1, scopes1);
61 helper->AddServiceWorker(origin2, scopes2);
62 EXPECT_EQ(2u, helper->GetServiceWorkerCount());
63 helper->DeleteServiceWorkers(origin2);
64 EXPECT_EQ(1u, helper->GetServiceWorkerCount());
67 TEST_F(CannedBrowsingDataServiceWorkerHelperTest, IgnoreExtensionsAndDevTools) {
68 const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/");
69 const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/");
70 const std::vector<GURL> scopes;
72 scoped_refptr<CannedBrowsingDataServiceWorkerHelper> helper(
73 new CannedBrowsingDataServiceWorkerHelper(ServiceWorkerContext()));
75 ASSERT_TRUE(helper->empty());
76 helper->AddServiceWorker(origin1, scopes);
77 ASSERT_TRUE(helper->empty());
78 helper->AddServiceWorker(origin2, scopes);
79 ASSERT_TRUE(helper->empty());
82 } // namespace