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

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: Code review comments (tiny). 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/test/base/testing_browser_process.h"
8 #include "chrome/test/base/testing_browser_process_test.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "content/browser/in_process_webkit/webkit_context.h"
11 #include "webkit/quota/mock_special_storage_policy.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<quota::MockSpecialStoragePolicy> special_storage_policy =
29 new quota::MockSpecialStoragePolicy;
30 special_storage_policy->AddSessionOnly(session_only_origin);
31
32 TestingProfile profile;
33
34 // Create databases for permanent and session-only origins.
35 FilePath domstorage_dir = profile.GetPath().Append(
36 DOMStorageContext::kLocalStorageDirectory);
37 FilePath::StringType session_only_database(
38 FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
39 FilePath::StringType permanent_database(
40 FILE_PATH_LITERAL("http_www.permanent.com_0"));
41 session_only_database.append(DOMStorageContext::kLocalStorageExtension);
42 permanent_database.append(DOMStorageContext::kLocalStorageExtension);
43 FilePath session_only_database_path =
44 domstorage_dir.Append(session_only_database);
45 FilePath permanent_database_path =
46 domstorage_dir.Append(permanent_database);
47
48 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
49
50 ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1));
51 ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
52
53 // Inject MockSpecialStoragePolicy into DOMStorageContext.
54 profile.GetWebKitContext()->dom_storage_context()->special_storage_policy_ =
55 special_storage_policy;
56
57 // Tell the WebKitContext explicitly do clean up the session-only
58 // data. TestingProfile (unlike ProfileImpl) doesn't do it automatically when
59 // destructed. The deletion is done immediately since we're on the WEBKIT
60 // thread (created by the test).
61 profile.GetWebKitContext()->DeleteSessionOnlyData();
62
63 // Expected result: the database file for the permanent storage remains but
64 // the database for the session only storage was deleted.
65 EXPECT_FALSE(file_util::PathExists(session_only_database_path));
66 EXPECT_TRUE(file_util::PathExists(permanent_database_path));
67 }
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/dom_storage_context.cc ('k') | content/browser/in_process_webkit/webkit_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698