blob: 60875ced676b4987c22f700a027ccda2d932fe55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/file_path.h"
#include "base/file_util.h"
#include "content/browser/in_process_webkit/webkit_context.h"
#include "content/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/quota/mock_special_storage_policy.h"
class DOMStorageTest : public testing::Test {
public:
DOMStorageTest()
: message_loop_(MessageLoop::TYPE_IO),
webkit_thread_(BrowserThread::WEBKIT, &message_loop_) {
}
protected:
MessageLoop message_loop_;
private:
BrowserThread webkit_thread_;
};
TEST_F(DOMStorageTest, SessionOnly) {
GURL session_only_origin("http://www.sessiononly.com");
scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
new quota::MockSpecialStoragePolicy;
special_storage_policy->AddSessionOnly(session_only_origin);
// A scope for deleting TestBrowserContext early enough.
{
TestBrowserContext browser_context;
// Create databases for permanent and session-only origins.
FilePath domstorage_dir = browser_context.GetPath().Append(
DOMStorageContext::kLocalStorageDirectory);
FilePath::StringType session_only_database(
FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
FilePath::StringType permanent_database(
FILE_PATH_LITERAL("http_www.permanent.com_0"));
session_only_database.append(DOMStorageContext::kLocalStorageExtension);
permanent_database.append(DOMStorageContext::kLocalStorageExtension);
FilePath session_only_database_path =
domstorage_dir.Append(session_only_database);
FilePath permanent_database_path =
domstorage_dir.Append(permanent_database);
ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1));
ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1));
// Inject MockSpecialStoragePolicy into DOMStorageContext.
browser_context.GetWebKitContext()->dom_storage_context()->
special_storage_policy_ = special_storage_policy;
// Tell the WebKitContext explicitly do clean up the session-only
// data. TestBrowserContext doesn't do it automatically
// when destructed. The deletion is done immediately since we're on the
// WEBKIT thread (created by the test).
browser_context.GetWebKitContext()->DeleteSessionOnlyData();
// Expected result: the database file for the permanent storage remains but
// the database for the session only storage was deleted.
EXPECT_FALSE(file_util::PathExists(session_only_database_path));
EXPECT_TRUE(file_util::PathExists(permanent_database_path));
}
// Run the message loop to ensure that DOMStorageContext gets destroyed.
message_loop_.RunAllPending();
}
|