• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
6 
7 #include "base/basictypes.h"
8 #include "base/bind.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"
21 
22 namespace {
23 typedef BrowsingDataHelperCallback<content::IndexedDBInfo>
24     TestCompletionCallback;
25 
26 class BrowsingDataIndexedDBHelperTest : public InProcessBrowserTest {
27  public:
IndexedDBContext()28   content::IndexedDBContext* IndexedDBContext() {
29     return content::BrowserContext::GetDefaultStoragePartition(
30         browser()->profile())->GetIndexedDBContext();
31   }
32 };
33 
IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest,CannedAddIndexedDB)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"));
38 
39   scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
40       new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
41   helper->AddIndexedDB(origin1, description);
42   helper->AddIndexedDB(origin2, description);
43 
44   TestCompletionCallback callback;
45   helper->StartFetching(
46       base::Bind(&TestCompletionCallback::callback,
47                  base::Unretained(&callback)));
48 
49   std::list<content::IndexedDBInfo> result =
50       callback.result();
51 
52   ASSERT_EQ(2U, result.size());
53   std::list<content::IndexedDBInfo>::iterator info =
54       result.begin();
55   EXPECT_EQ(origin1, info->origin_);
56   info++;
57   EXPECT_EQ(origin2, info->origin_);
58 }
59 
IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest,CannedUnique)60 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) {
61   const GURL origin("http://host1:1/");
62   const base::string16 description(base::ASCIIToUTF16("description"));
63 
64   scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
65       new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
66   helper->AddIndexedDB(origin, description);
67   helper->AddIndexedDB(origin, description);
68 
69   TestCompletionCallback callback;
70   helper->StartFetching(
71       base::Bind(&TestCompletionCallback::callback,
72                  base::Unretained(&callback)));
73 
74   std::list<content::IndexedDBInfo> result =
75       callback.result();
76 
77   ASSERT_EQ(1U, result.size());
78   EXPECT_EQ(origin, result.begin()->origin_);
79 }
80 }  // namespace
81