Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_indexed_db_helper_unittest.cc
blob387341438302e23317f6c4ee43bbdac770f813ec
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 "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/storage_partition.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace {
17 class CannedBrowsingDataIndexedDBHelperTest : public testing::Test {
18 public:
19 virtual void SetUp() OVERRIDE {
20 IndexedDBContext()->SetTaskRunnerForTesting(
21 base::MessageLoopProxy::current().get());
24 content::IndexedDBContext* IndexedDBContext() {
25 return content::BrowserContext::GetDefaultStoragePartition(&profile_)->
26 GetIndexedDBContext();
29 private:
30 content::TestBrowserThreadBundle thread_bundle_;
31 TestingProfile profile_;
34 TEST_F(CannedBrowsingDataIndexedDBHelperTest, Empty) {
35 const GURL origin("http://host1:1/");
36 const base::string16 description(base::ASCIIToUTF16("description"));
38 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
39 new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
41 ASSERT_TRUE(helper->empty());
42 helper->AddIndexedDB(origin, description);
43 ASSERT_FALSE(helper->empty());
44 helper->Reset();
45 ASSERT_TRUE(helper->empty());
48 TEST_F(CannedBrowsingDataIndexedDBHelperTest, Delete) {
49 const GURL origin1("http://host1:9000");
50 const base::string16 db1(base::ASCIIToUTF16("db1"));
52 const GURL origin2("http://example.com");
53 const base::string16 db2(base::ASCIIToUTF16("db2"));
54 const base::string16 db3(base::ASCIIToUTF16("db3"));
56 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
57 new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
59 EXPECT_TRUE(helper->empty());
60 helper->AddIndexedDB(origin1, db1);
61 helper->AddIndexedDB(origin2, db2);
62 helper->AddIndexedDB(origin2, db3);
63 EXPECT_EQ(3u, helper->GetIndexedDBCount());
64 helper->DeleteIndexedDB(origin2);
65 EXPECT_EQ(1u, helper->GetIndexedDBCount());
68 TEST_F(CannedBrowsingDataIndexedDBHelperTest, IgnoreExtensionsAndDevTools) {
69 const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/");
70 const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/");
71 const base::string16 description(base::ASCIIToUTF16("description"));
73 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
74 new CannedBrowsingDataIndexedDBHelper(IndexedDBContext()));
76 ASSERT_TRUE(helper->empty());
77 helper->AddIndexedDB(origin1, description);
78 ASSERT_TRUE(helper->empty());
79 helper->AddIndexedDB(origin2, description);
80 ASSERT_TRUE(helper->empty());
83 } // namespace