Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_indexed_db_helper_browsertest.cc
blob5f785c02e7c5313ab632589d99da10c4810f5666
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.
5 #include <string>
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"
22 namespace {
23 typedef BrowsingDataHelperCallback<content::IndexedDBInfo>
24 TestCompletionCallback;
26 class BrowsingDataIndexedDBHelperTest : public InProcessBrowserTest {
27 public:
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 =
50 callback.result();
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);
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 =
75 callback.result();
77 ASSERT_EQ(1U, result.size());
78 EXPECT_EQ(origin, result.begin()->origin);
80 } // namespace