1// Copyright (c) 2012 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 "chrome/browser/browsing_data/mock_browsing_data_indexed_db_helper.h" 6 7#include "base/callback.h" 8#include "base/logging.h" 9#include "chrome/browser/profiles/profile.h" 10#include "content/public/browser/browser_context.h" 11#include "content/public/browser/storage_partition.h" 12#include "testing/gtest/include/gtest/gtest.h" 13 14MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper( 15 Profile* profile) 16 : BrowsingDataIndexedDBHelper( 17 content::BrowserContext::GetDefaultStoragePartition(profile)-> 18 GetIndexedDBContext()) { 19} 20 21MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { 22} 23 24void MockBrowsingDataIndexedDBHelper::StartFetching( 25 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& 26 callback) { 27 ASSERT_FALSE(callback.is_null()); 28 ASSERT_TRUE(callback_.is_null()); 29 callback_ = callback; 30} 31 32void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB( 33 const GURL& origin) { 34 ASSERT_FALSE(callback_.is_null()); 35 ASSERT_TRUE(origins_.find(origin) != origins_.end()); 36 origins_[origin] = false; 37} 38 39void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { 40 const GURL kOrigin1("http://idbhost1:1/"); 41 const GURL kOrigin2("http://idbhost2:2/"); 42 content::IndexedDBInfo info1(kOrigin1, 1, base::Time(), base::FilePath(), 0); 43 response_.push_back(info1); 44 origins_[kOrigin1] = true; 45 content::IndexedDBInfo info2(kOrigin2, 2, base::Time(), base::FilePath(), 0); 46 response_.push_back(info2); 47 origins_[kOrigin2] = true; 48} 49 50void MockBrowsingDataIndexedDBHelper::Notify() { 51 callback_.Run(response_); 52} 53 54void MockBrowsingDataIndexedDBHelper::Reset() { 55 for (std::map<GURL, bool>::iterator i = origins_.begin(); 56 i != origins_.end(); ++i) 57 i->second = true; 58} 59 60bool MockBrowsingDataIndexedDBHelper::AllDeleted() { 61 for (std::map<GURL, bool>::const_iterator i = origins_.begin(); 62 i != origins_.end(); ++i) 63 if (i->second) 64 return false; 65 return true; 66} 67