Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Side by Side Diff: webkit/dom_storage/dom_storage_area_unittest.cc

Issue 9389009: Hook up DomStorageArea with a DomStorageDatabase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try and make the Windows try bot happy. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h"
6 #include "base/scoped_temp_dir.h"
5 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
7 #include "webkit/dom_storage/dom_storage_area.h" 9 #include "webkit/dom_storage/dom_storage_area.h"
10 #include "webkit/dom_storage/dom_storage_types.h"
8 11
9 namespace dom_storage { 12 namespace dom_storage {
10 13
11 TEST(DomStorageAreaTest, DomStorageAreaBasics) { 14 TEST(DomStorageAreaTest, DomStorageAreaBasics) {
12 const GURL kOrigin("http://dom_storage/"); 15 const GURL kOrigin("http://dom_storage/");
13 const string16 kKey(ASCIIToUTF16("key")); 16 const string16 kKey(ASCIIToUTF16("key"));
14 const string16 kValue(ASCIIToUTF16("value")); 17 const string16 kValue(ASCIIToUTF16("value"));
15 const string16 kKey2(ASCIIToUTF16("key2")); 18 const string16 kKey2(ASCIIToUTF16("key2"));
16 const string16 kValue2(ASCIIToUTF16("value2")); 19 const string16 kValue2(ASCIIToUTF16("value2"));
17 20
(...skipping 28 matching lines...) Expand all
46 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); 49 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value));
47 EXPECT_NE(copy->map_.get(), area->map_.get()); 50 EXPECT_NE(copy->map_.get(), area->map_.get());
48 copy = area->ShallowCopy(2); 51 copy = area->ShallowCopy(2);
49 EXPECT_EQ(copy->map_.get(), area->map_.get()); 52 EXPECT_EQ(copy->map_.get(), area->map_.get());
50 EXPECT_NE(0u, area->Length()); 53 EXPECT_NE(0u, area->Length());
51 EXPECT_TRUE(area->Clear()); 54 EXPECT_TRUE(area->Clear());
52 EXPECT_EQ(0u, area->Length()); 55 EXPECT_EQ(0u, area->Length());
53 EXPECT_NE(copy->map_.get(), area->map_.get()); 56 EXPECT_NE(copy->map_.get(), area->map_.get());
54 } 57 }
55 58
59 TEST(DomStorageAreaTest, BackingDatabaseOpened) {
60 const int64 kNonLocalStorageNamespaceId = kLocalStorageNamespaceId + 1;
61 const GURL origin("http://www.google.com");
62 ScopedTempDir temp_dir;
63 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
64
65 // No directory, backing should be null.
66 {
67 scoped_refptr<DomStorageArea> area(
68 new DomStorageArea(kLocalStorageNamespaceId, origin, FilePath(),
69 NULL));
70 EXPECT_EQ(NULL, area->backing_.get());
71 EXPECT_TRUE(area->initial_import_done_);
72 EXPECT_FALSE(file_util::PathExists(
73 FilePath().AppendASCII("http_www.google.com_0.localstorage")));
74 }
75
76 // Valid directory and origin but non-local namespace id. Backing should
77 // be null.
78 {
79 scoped_refptr<DomStorageArea> area(
80 new DomStorageArea(kNonLocalStorageNamespaceId, origin,
81 temp_dir.path(), NULL));
82 EXPECT_EQ(NULL, area->backing_.get());
83 EXPECT_TRUE(area->initial_import_done_);
84
85 NullableString16 old_value;
86 area->SetItem(ASCIIToUTF16("test"), ASCIIToUTF16("value"), &old_value);
87 ASSERT_TRUE(old_value.is_null());
88
89 // Check that saving a value has still left us without a backing database.
90 EXPECT_EQ(NULL, area->backing_.get());
91 EXPECT_FALSE(file_util::PathExists(
92 temp_dir.path().AppendASCII("http_www.google.com_0.localstorage")));
93 }
94
95 // Valid directory and origin with local storage namespace id - backing
96 // should be open.
97 {
98 scoped_refptr<DomStorageArea> area(
99 new DomStorageArea(kLocalStorageNamespaceId, origin,
100 temp_dir.path(), NULL));
101 EXPECT_TRUE(area->backing_.get());
102 EXPECT_FALSE(area->initial_import_done_);
103 // Need to write something to ensure that the database is created.
104 NullableString16 old_value;
105 area->SetItem(ASCIIToUTF16("test"), ASCIIToUTF16("value"), &old_value);
106 ASSERT_TRUE(old_value.is_null());
107 EXPECT_TRUE(area->initial_import_done_);
108 EXPECT_TRUE(area->backing_->IsOpen());
109 EXPECT_TRUE(file_util::PathExists(
110 temp_dir.path().AppendASCII("http_www.google.com_0.localstorage")));
111 }
112 }
113
114 TEST(DomStorageAreaTest, TestDatabaseFilePath) {
115 EXPECT_EQ(FilePath().AppendASCII("file_path_to_0.localstorage"),
116 DomStorageArea::DatabaseFileNameFromOrigin(
117 GURL("file://path_to/index.html")));
118
119 EXPECT_EQ(FilePath().AppendASCII("https_www.google.com_0.localstorage"),
120 DomStorageArea::DatabaseFileNameFromOrigin(
121 GURL("https://www.google.com/")));
122
123 EXPECT_EQ(FilePath().AppendASCII("https_www.google.com_8080.localstorage"),
124 DomStorageArea::DatabaseFileNameFromOrigin(
125 GURL("https://www.google.com:8080")));
126 }
127
56 } // namespace dom_storage 128 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698