OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/in_process_webkit/indexed_db_context.h" | 11 #include "chrome/browser/in_process_webkit/indexed_db_context.h" |
| 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
| 17 #include "chrome/test/testing_profile.h" |
| 18 #include "chrome/test/thread_test_helper.h" |
16 #include "chrome/test/ui_test_utils.h" | 19 #include "chrome/test/ui_test_utils.h" |
17 | 20 |
18 // This browser test is aimed towards exercising the IndexedDB bindings and | 21 // This browser test is aimed towards exercising the IndexedDB bindings and |
19 // the actual implementation that lives in the browser side (in_process_webkit). | 22 // the actual implementation that lives in the browser side (in_process_webkit). |
20 class IndexedDBBrowserTest : public InProcessBrowserTest { | 23 class IndexedDBBrowserTest : public InProcessBrowserTest { |
21 public: | 24 public: |
22 IndexedDBBrowserTest() { | 25 IndexedDBBrowserTest() { |
23 EnableDOMAutomation(); | 26 EnableDOMAutomation(); |
24 } | 27 } |
25 | 28 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // In proc browser test is needed here because ClearLocalState indirectly calls | 88 // In proc browser test is needed here because ClearLocalState indirectly calls |
86 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. | 89 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. |
87 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) { | 90 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) { |
88 // Create test files. | 91 // Create test files. |
89 ScopedTempDir temp_dir; | 92 ScopedTempDir temp_dir; |
90 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 93 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
91 FilePath indexeddb_dir = temp_dir.path().Append( | 94 FilePath indexeddb_dir = temp_dir.path().Append( |
92 IndexedDBContext::kIndexedDBDirectory); | 95 IndexedDBContext::kIndexedDBDirectory); |
93 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); | 96 ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir)); |
94 | 97 |
95 FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_www.google.com_0")); | 98 FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_foo_0")); |
96 file_name_1.append(IndexedDBContext::kIndexedDBExtension); | 99 file_name_1.append(IndexedDBContext::kIndexedDBExtension); |
97 FilePath::StringType file_name_2(FILE_PATH_LITERAL("https_www.google.com_0")); | 100 FilePath::StringType file_name_2(FILE_PATH_LITERAL("chrome-extension_foo_0")); |
98 file_name_2.append(IndexedDBContext::kIndexedDBExtension); | 101 file_name_2.append(IndexedDBContext::kIndexedDBExtension); |
99 FilePath temp_file_path_1 = indexeddb_dir.Append(file_name_1); | 102 FilePath temp_file_path_1 = indexeddb_dir.Append(file_name_1); |
100 FilePath temp_file_path_2 = indexeddb_dir.Append(file_name_2); | 103 FilePath temp_file_path_2 = indexeddb_dir.Append(file_name_2); |
101 | 104 |
102 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1)); | 105 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1)); |
103 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1)); | 106 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1)); |
104 | 107 |
105 IndexedDBContext::ClearLocalState(temp_dir.path(), "https"); | 108 // Create the scope which will ensure we run the destructor of the webkit |
| 109 // context which should trigger the clean up. |
| 110 { |
| 111 TestingProfile profile; |
| 112 WebKitContext *webkit_context = profile.GetWebKitContext(); |
| 113 webkit_context->indexed_db_context()->set_data_path(indexeddb_dir); |
| 114 webkit_context->set_clear_local_state_on_exit(true); |
| 115 } |
| 116 // Make sure we wait until the destructor has run. |
| 117 scoped_refptr<ThreadTestHelper> helper( |
| 118 new ThreadTestHelper(BrowserThread::WEBKIT)); |
| 119 ASSERT_TRUE(helper->Run()); |
106 | 120 |
107 // Because we specified https for scheme to be skipped the second file | 121 // Because we specified https for scheme to be skipped the second file |
108 // should survive and the first go into vanity. | 122 // should survive and the first go into vanity. |
109 ASSERT_FALSE(file_util::PathExists(temp_file_path_1)); | 123 ASSERT_FALSE(file_util::PathExists(temp_file_path_1)); |
110 ASSERT_TRUE(file_util::PathExists(temp_file_path_2)); | 124 ASSERT_TRUE(file_util::PathExists(temp_file_path_2)); |
111 } | 125 } |
OLD | NEW |