ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / browsing_data / mock_browsing_data_service_worker_helper.cc
blob581638e3c46f282ec5e223949d4b603112f1dc5d
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/mock_browsing_data_service_worker_helper.h"
7 #include <vector>
9 #include "base/callback.h"
10 #include "base/logging.h"
11 #include "base/stl_util.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/storage_partition.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 MockBrowsingDataServiceWorkerHelper::MockBrowsingDataServiceWorkerHelper(
18 Profile* profile)
19 : BrowsingDataServiceWorkerHelper(
20 content::BrowserContext::GetDefaultStoragePartition(profile)->
21 GetServiceWorkerContext()) {
24 MockBrowsingDataServiceWorkerHelper::~MockBrowsingDataServiceWorkerHelper() {
27 void MockBrowsingDataServiceWorkerHelper::StartFetching(
28 const FetchCallback& callback) {
29 ASSERT_FALSE(callback.is_null());
30 ASSERT_TRUE(callback_.is_null());
31 callback_ = callback;
34 void MockBrowsingDataServiceWorkerHelper::DeleteServiceWorkers(
35 const GURL& origin) {
36 ASSERT_FALSE(callback_.is_null());
37 ASSERT_TRUE(ContainsKey(origins_, origin));
38 origins_[origin] = false;
41 void MockBrowsingDataServiceWorkerHelper::AddServiceWorkerSamples() {
42 const GURL kOrigin1("https://swhost1:1/");
43 std::vector<GURL> scopes1;
44 scopes1.push_back(GURL("https://swhost1:1/app1/*"));
45 scopes1.push_back(GURL("https://swhost1:1/app2/*"));
46 const GURL kOrigin2("https://swhost2:2/");
47 std::vector<GURL> scopes2;
48 scopes2.push_back(GURL("https://swhost2:2/*"));
50 content::ServiceWorkerUsageInfo info1(kOrigin1, scopes1);
51 response_.push_back(info1);
52 origins_[kOrigin1] = true;
54 content::ServiceWorkerUsageInfo info2(kOrigin2, scopes2);
55 response_.push_back(info2);
56 origins_[kOrigin2] = true;
59 void MockBrowsingDataServiceWorkerHelper::Notify() {
60 callback_.Run(response_);
63 void MockBrowsingDataServiceWorkerHelper::Reset() {
64 for (auto& pair : origins_)
65 pair.second = true;
68 bool MockBrowsingDataServiceWorkerHelper::AllDeleted() {
69 for (const auto& pair : origins_) {
70 if (pair.second)
71 return false;
73 return true;