OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "content/browser/browser_thread_impl.h" | 7 #include "content/browser/browser_thread_impl.h" |
8 #include "content/browser/in_process_webkit/webkit_context.h" | |
9 #include "content/browser/in_process_webkit/dom_storage_context_impl.h" | 8 #include "content/browser/in_process_webkit/dom_storage_context_impl.h" |
10 #include "content/test/test_browser_context.h" | 9 #include "content/test/test_browser_context.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/quota/mock_special_storage_policy.h" | 11 #include "webkit/quota/mock_special_storage_policy.h" |
13 | 12 |
14 using content::BrowserContext; | 13 using content::BrowserContext; |
15 using content::BrowserThread; | 14 using content::BrowserThread; |
16 using content::BrowserThreadImpl; | 15 using content::BrowserThreadImpl; |
17 | 16 |
18 class DOMStorageTest : public testing::Test { | 17 class DOMStorageTest : public testing::Test { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 domstorage_dir.Append(session_only_database); | 49 domstorage_dir.Append(session_only_database); |
51 FilePath permanent_database_path = | 50 FilePath permanent_database_path = |
52 domstorage_dir.Append(permanent_database); | 51 domstorage_dir.Append(permanent_database); |
53 | 52 |
54 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir)); | 53 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir)); |
55 | 54 |
56 ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1)); | 55 ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1)); |
57 ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1)); | 56 ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1)); |
58 | 57 |
59 // Inject MockSpecialStoragePolicy into DOMStorageContext. | 58 // Inject MockSpecialStoragePolicy into DOMStorageContext. |
60 BrowserContext::GetWebKitContext(browser_context.get())-> | 59 DOMStorageContextImpl* dom_storage_context = |
61 dom_storage_context()->special_storage_policy_ = special_storage_policy; | 60 static_cast<DOMStorageContextImpl*>( |
| 61 BrowserContext::GetDOMStorageContext(browser_context.get())); |
| 62 dom_storage_context->special_storage_policy_ = special_storage_policy; |
62 | 63 |
63 // Delete the TestBrowserContext but own the temp dir. This way the | 64 // Delete the TestBrowserContext but own the temp dir. This way the |
64 // temporary data directory stays alive long enough to conduct the test. | 65 // temporary data directory stays alive long enough to conduct the test. |
65 ScopedTempDir temp_dir; | 66 ScopedTempDir temp_dir; |
66 ignore_result(temp_dir.Set(browser_context->TakePath())); | 67 ignore_result(temp_dir.Set(browser_context->TakePath())); |
67 browser_context.reset(); | 68 browser_context.reset(); |
68 // Run the message loop to ensure that DOMStorageContext gets destroyed. | 69 // Run the message loop to ensure that DOMStorageContext gets destroyed. |
69 message_loop_.RunAllPending(); | 70 message_loop_.RunAllPending(); |
70 | 71 |
71 // Expected result: the database file for the permanent storage remains but | 72 // Expected result: the database file for the permanent storage remains but |
(...skipping 24 matching lines...) Expand all Loading... |
96 FilePath permanent_database_path = | 97 FilePath permanent_database_path = |
97 domstorage_dir.Append(permanent_database); | 98 domstorage_dir.Append(permanent_database); |
98 | 99 |
99 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir)); | 100 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir)); |
100 | 101 |
101 ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1)); | 102 ASSERT_EQ(1, file_util::WriteFile(session_only_database_path, ".", 1)); |
102 ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1)); | 103 ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1)); |
103 | 104 |
104 // Inject MockSpecialStoragePolicy into DOMStorageContext. | 105 // Inject MockSpecialStoragePolicy into DOMStorageContext. |
105 DOMStorageContextImpl* dom_storage_context = | 106 DOMStorageContextImpl* dom_storage_context = |
106 BrowserContext::GetWebKitContext(browser_context.get())-> | 107 static_cast<DOMStorageContextImpl*>( |
107 dom_storage_context(); | 108 BrowserContext::GetDOMStorageContext(browser_context.get())); |
108 dom_storage_context->special_storage_policy_ = special_storage_policy; | 109 dom_storage_context->special_storage_policy_ = special_storage_policy; |
109 | 110 |
110 dom_storage_context->set_clear_local_state_on_exit(true); | 111 dom_storage_context->set_clear_local_state_on_exit(true); |
111 | 112 |
112 // Save session state. This should bypass the destruction-time deletion. | 113 // Save session state. This should bypass the destruction-time deletion. |
113 dom_storage_context->SaveSessionState(); | 114 dom_storage_context->SaveSessionState(); |
114 | 115 |
115 // Delete the TestBrowserContext but own the temp dir. This way the | 116 // Delete the TestBrowserContext but own the temp dir. This way the |
116 // temporary data directory stays alive long enough to conduct the test. | 117 // temporary data directory stays alive long enough to conduct the test. |
117 ScopedTempDir temp_dir; | 118 ScopedTempDir temp_dir; |
118 ignore_result(temp_dir.Set(browser_context->TakePath())); | 119 ignore_result(temp_dir.Set(browser_context->TakePath())); |
119 browser_context.reset(); | 120 browser_context.reset(); |
120 // Run the message loop to ensure that DOMStorageContext gets destroyed. | 121 // Run the message loop to ensure that DOMStorageContext gets destroyed. |
121 message_loop_.RunAllPending(); | 122 message_loop_.RunAllPending(); |
122 | 123 |
123 // Expected result: no database files were deleted because of | 124 // Expected result: no database files were deleted because of |
124 // SaveSessionState. | 125 // SaveSessionState. |
125 EXPECT_TRUE(file_util::PathExists(session_only_database_path)); | 126 EXPECT_TRUE(file_util::PathExists(session_only_database_path)); |
126 EXPECT_TRUE(file_util::PathExists(permanent_database_path)); | 127 EXPECT_TRUE(file_util::PathExists(permanent_database_path)); |
127 } | 128 } |
OLD | NEW |