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

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: Rename CommitChanges* methods. 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/message_loop.h"
7 #include "base/message_loop_proxy.h"
8 #include "base/scoped_temp_dir.h"
5 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
7 #include "webkit/dom_storage/dom_storage_area.h" 11 #include "webkit/dom_storage/dom_storage_area.h"
12 #include "webkit/dom_storage/dom_storage_task_runner.h"
13 #include "webkit/dom_storage/dom_storage_types.h"
8 14
9 namespace dom_storage { 15 namespace dom_storage {
10 16
11 TEST(DomStorageAreaTest, DomStorageAreaBasics) { 17 TEST(DomStorageAreaTest, DomStorageAreaBasics) {
12 const GURL kOrigin("http://dom_storage/"); 18 const GURL kOrigin("http://dom_storage/");
13 const string16 kKey(ASCIIToUTF16("key")); 19 const string16 kKey(ASCIIToUTF16("key"));
14 const string16 kValue(ASCIIToUTF16("value")); 20 const string16 kValue(ASCIIToUTF16("value"));
15 const string16 kKey2(ASCIIToUTF16("key2")); 21 const string16 kKey2(ASCIIToUTF16("key2"));
16 const string16 kValue2(ASCIIToUTF16("value2")); 22 const string16 kValue2(ASCIIToUTF16("value2"));
17 23
(...skipping 28 matching lines...) Expand all
46 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); 52 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value));
47 EXPECT_NE(copy->map_.get(), area->map_.get()); 53 EXPECT_NE(copy->map_.get(), area->map_.get());
48 copy = area->ShallowCopy(2); 54 copy = area->ShallowCopy(2);
49 EXPECT_EQ(copy->map_.get(), area->map_.get()); 55 EXPECT_EQ(copy->map_.get(), area->map_.get());
50 EXPECT_NE(0u, area->Length()); 56 EXPECT_NE(0u, area->Length());
51 EXPECT_TRUE(area->Clear()); 57 EXPECT_TRUE(area->Clear());
52 EXPECT_EQ(0u, area->Length()); 58 EXPECT_EQ(0u, area->Length());
53 EXPECT_NE(copy->map_.get(), area->map_.get()); 59 EXPECT_NE(copy->map_.get(), area->map_.get());
54 } 60 }
55 61
62 TEST(DomStorageAreaTest, BackingDatabaseOpened) {
63 const int64 kNonLocalStorageNamespaceId = kLocalStorageNamespaceId + 1;
64 const GURL origin("http://www.google.com");
65 const string16 kKey = ASCIIToUTF16("test");
66 const string16 kValue = ASCIIToUTF16("value");
67 ScopedTempDir temp_dir;
68 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
69
70 // No directory, backing should be null.
71 {
72 scoped_refptr<DomStorageArea> area(
73 new DomStorageArea(kLocalStorageNamespaceId, origin, FilePath(),
74 NULL));
75 EXPECT_EQ(NULL, area->backing_.get());
76 EXPECT_TRUE(area->initial_import_done_);
77 EXPECT_FALSE(file_util::PathExists(
78 FilePath().AppendASCII("http_www.google.com_0.localstorage")));
79 }
80
81 // Valid directory and origin but non-local namespace id. Backing should
82 // be null.
83 {
84 scoped_refptr<DomStorageArea> area(
85 new DomStorageArea(kNonLocalStorageNamespaceId, origin,
86 temp_dir.path(), NULL));
87 EXPECT_EQ(NULL, area->backing_.get());
88 EXPECT_TRUE(area->initial_import_done_);
89
90 NullableString16 old_value;
91 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value));
92 ASSERT_TRUE(old_value.is_null());
93
94 // Check that saving a value has still left us without a backing database.
95 EXPECT_EQ(NULL, area->backing_.get());
96 EXPECT_FALSE(file_util::PathExists(
97 temp_dir.path().AppendASCII("http_www.google.com_0.localstorage")));
98 }
99
100 // Valid directory and origin with local storage namespace id - backing
101 // should be open.
102 {
103 scoped_refptr<DomStorageArea> area(
104 new DomStorageArea(kLocalStorageNamespaceId, origin,
105 temp_dir.path(),
106 new DomStorageTaskRunner(base::MessageLoopProxy::current())));
107
108 EXPECT_TRUE(area->backing_.get());
109 EXPECT_FALSE(area->initial_import_done_);
110
111 // Need to write something to ensure that the database is created.
112 NullableString16 old_value;
113 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value));
114 ASSERT_TRUE(old_value.is_null());
115 EXPECT_TRUE(area->initial_import_done_);
116
117 // Need to wait for message loop to finish processing message to commit
118 // the changes to disk so we can verify the file gets created.
119 MessageLoop::current()->RunAllPending();
120
121 EXPECT_TRUE(area->backing_->IsOpen());
122 EXPECT_TRUE(file_util::PathExists(
123 temp_dir.path().AppendASCII("http_www.google.com_0.localstorage")));
124 EXPECT_EQ(kValue, area->GetItem(kKey).string());
125 }
126 }
127
128 TEST(DomStorageAreaTest, TestDatabaseFilePath) {
129 EXPECT_EQ(FilePath().AppendASCII("file_path_to_0.localstorage"),
130 DomStorageArea::DatabaseFileNameFromOrigin(
131 GURL("file://path_to/index.html")));
132
133 EXPECT_EQ(FilePath().AppendASCII("https_www.google.com_0.localstorage"),
134 DomStorageArea::DatabaseFileNameFromOrigin(
135 GURL("https://www.google.com/")));
136
137 EXPECT_EQ(FilePath().AppendASCII("https_www.google.com_8080.localstorage"),
138 DomStorageArea::DatabaseFileNameFromOrigin(
139 GURL("https://www.google.com:8080")));
140 }
141
56 } // namespace dom_storage 142 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698