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

Side by Side Diff: content/browser/in_process_webkit/dom_storage_unittest.cc

Issue 7619010: Session-only local storage cleared on exit. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Tests. Created 9 years, 4 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
(Empty)
1 // Copyright (c) 2011 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 "base/file_path.h"
6 #include "base/file_util.h"
7 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
8 #include "chrome/test/base/testing_browser_process.h"
9 #include "chrome/test/base/testing_browser_process_test.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "content/browser/in_process_webkit/webkit_context.h"
12
13 class DOMStorageTest : public TestingBrowserProcessTest {
14 public:
15 DOMStorageTest()
16 : message_loop_(MessageLoop::TYPE_IO),
17 webkit_thread_(BrowserThread::WEBKIT, &message_loop_) {
18 }
19 protected:
20 MessageLoop message_loop_;
21
22 private:
23 BrowserThread webkit_thread_;
24 };
25
26 TEST_F(DOMStorageTest, SessionOnly) {
27 GURL session_only_origin("http://www.sessiononly.com");
28 scoped_refptr<MockExtensionSpecialStoragePolicy>
29 extension_special_storage_policy(new MockExtensionSpecialStoragePolicy);
30 extension_special_storage_policy->AddSessionOnly(session_only_origin);
31
32 TestingProfile profile;
33 profile.SetExtensionSpecialStoragePolicy(
34 extension_special_storage_policy.get());
35
36 // Create databases for permanent and session-only origins.
37 FilePath domstorage_dir = profile.GetPath().Append(
38 DOMStorageContext::kLocalStorageDirectory);
39 FilePath::StringType session_only_database(
40 FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
41 FilePath::StringType permanent_database(
42 FILE_PATH_LITERAL("http_www.permanent.com_0"));
43 session_only_database.append(DOMStorageContext::kLocalStorageExtension);
44 permanent_database.append(DOMStorageContext::kLocalStorageExtension);
45 FilePath session_only_database_path =
46 domstorage_dir.Append(session_only_database);
47 FilePath permanent_database_path =
48 domstorage_dir.Append(permanent_database);
49
50 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
51
52 ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1));
53 ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
54
55 // Tell the WebKitContext explicitly do clean up the session-only
56 // data. TestingProfile (unlike ProfileImpl) doesn't do it automatically when
57 // destructed. The deletion is done immediately since we're on the WEBKIT
58 // thread (created by the test).
59 profile.GetWebKitContext()->DeleteSessionOnlyData();
60
61 // Expected result: the database file for the permanent storage remains but
62 // the database for the session only storage was deleted.
63 EXPECT_FALSE(file_util::PathExists(session_only_database_path));
64 EXPECT_TRUE(file_util::PathExists(permanent_database_path));
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698