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.
7 #include "base/basictypes.h"
9 #include "base/bind_helpers.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browsing_data/browsing_data_helper_browsertest.h"
15 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "content/public/browser/storage_partition.h"
20 #include "testing/gtest/include/gtest/gtest.h"
23 typedef BrowsingDataHelperCallback
<content::IndexedDBInfo
>
24 TestCompletionCallback
;
26 class BrowsingDataIndexedDBHelperTest
: public InProcessBrowserTest
{
28 content::IndexedDBContext
* IndexedDBContext() {
29 return content::BrowserContext::GetDefaultStoragePartition(
30 browser()->profile())->GetIndexedDBContext();
34 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest
, CannedAddIndexedDB
) {
35 const GURL
origin1("http://host1:1/");
36 const GURL
origin2("http://host2:1/");
37 const base::string16
description(base::ASCIIToUTF16("description"));
39 scoped_refptr
<CannedBrowsingDataIndexedDBHelper
> helper(
40 new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
41 helper
->AddIndexedDB(origin1
, description
);
42 helper
->AddIndexedDB(origin2
, description
);
44 TestCompletionCallback callback
;
45 helper
->StartFetching(
46 base::Bind(&TestCompletionCallback::callback
,
47 base::Unretained(&callback
)));
49 std::list
<content::IndexedDBInfo
> result
=
52 ASSERT_EQ(2U, result
.size());
53 std::list
<content::IndexedDBInfo
>::iterator info
=
55 EXPECT_EQ(origin1
, info
->origin_
);
57 EXPECT_EQ(origin2
, info
->origin_
);
60 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest
, CannedUnique
) {
61 const GURL
origin("http://host1:1/");
62 const base::string16
description(base::ASCIIToUTF16("description"));
64 scoped_refptr
<CannedBrowsingDataIndexedDBHelper
> helper(
65 new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
66 helper
->AddIndexedDB(origin
, description
);
67 helper
->AddIndexedDB(origin
, description
);
69 TestCompletionCallback callback
;
70 helper
->StartFetching(
71 base::Bind(&TestCompletionCallback::callback
,
72 base::Unretained(&callback
)));
74 std::list
<content::IndexedDBInfo
> result
=
77 ASSERT_EQ(1U, result
.size());
78 EXPECT_EQ(origin
, result
.begin()->origin_
);