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

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

Issue 9419033: Move creation of BrowserContext objects that live in content to content, instead of depending on th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fix memory leaks in tests Created 8 years, 10 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
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 "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/test/thread_test_helper.h" 8 #include "base/test/thread_test_helper.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "content/browser/in_process_webkit/dom_storage_context.h" 11 #include "content/browser/in_process_webkit/dom_storage_context.h"
12 #include "content/browser/in_process_webkit/webkit_context.h" 12 #include "content/browser/in_process_webkit/webkit_context.h"
13 13
14 using content::BrowserContext;
14 using content::BrowserThread; 15 using content::BrowserThread;
15 16
16 typedef InProcessBrowserTest DOMStorageBrowserTest; 17 typedef InProcessBrowserTest DOMStorageBrowserTest;
17 18
18 // In proc browser test is needed here because ClearLocalState indirectly calls 19 // In proc browser test is needed here because ClearLocalState indirectly calls
19 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. 20 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin.
20 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) { 21 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) {
21 // Create test files. 22 // Create test files.
22 ScopedTempDir temp_dir; 23 ScopedTempDir temp_dir;
23 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 24 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
24 FilePath domstorage_dir = temp_dir.path().Append( 25 FilePath domstorage_dir = temp_dir.path().Append(
25 DOMStorageContext::kLocalStorageDirectory); 26 DOMStorageContext::kLocalStorageDirectory);
26 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir)); 27 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
27 28
28 FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_foo_0")); 29 FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_foo_0"));
29 file_name_1.append(DOMStorageContext::kLocalStorageExtension); 30 file_name_1.append(DOMStorageContext::kLocalStorageExtension);
30 FilePath::StringType file_name_2(FILE_PATH_LITERAL("chrome-extension_foo_0")); 31 FilePath::StringType file_name_2(FILE_PATH_LITERAL("chrome-extension_foo_0"));
31 file_name_2.append(DOMStorageContext::kLocalStorageExtension); 32 file_name_2.append(DOMStorageContext::kLocalStorageExtension);
32 FilePath temp_file_path_1 = domstorage_dir.Append(file_name_1); 33 FilePath temp_file_path_1 = domstorage_dir.Append(file_name_1);
33 FilePath temp_file_path_2 = domstorage_dir.Append(file_name_2); 34 FilePath temp_file_path_2 = domstorage_dir.Append(file_name_2);
34 35
35 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1)); 36 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1));
36 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1)); 37 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1));
37 38
38 // Create the scope which will ensure we run the destructor of the webkit 39 // Create the scope which will ensure we run the destructor of the webkit
39 // context which should trigger the clean up. 40 // context which should trigger the clean up.
40 { 41 {
41 TestingProfile profile; 42 TestingProfile profile;
42 WebKitContext *webkit_context = profile.GetWebKitContext(); 43 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
43 webkit_context->dom_storage_context()-> 44 webkit_context->dom_storage_context()->
44 set_data_path_for_testing(temp_dir.path()); 45 set_data_path_for_testing(temp_dir.path());
45 webkit_context->set_clear_local_state_on_exit(true); 46 webkit_context->set_clear_local_state_on_exit(true);
46 } 47 }
47 // Make sure we wait until the destructor has run. 48 // Make sure we wait until the destructor has run.
48 scoped_refptr<base::ThreadTestHelper> helper( 49 scoped_refptr<base::ThreadTestHelper> helper(
49 new base::ThreadTestHelper( 50 new base::ThreadTestHelper(
50 BrowserThread::GetMessageLoopProxyForThread( 51 BrowserThread::GetMessageLoopProxyForThread(
51 BrowserThread::WEBKIT_DEPRECATED))); 52 BrowserThread::WEBKIT_DEPRECATED)));
52 ASSERT_TRUE(helper->Run()); 53 ASSERT_TRUE(helper->Run());
53 54
54 // Because we specified https for scheme to be skipped the second file 55 // Because we specified https for scheme to be skipped the second file
55 // should survive and the first go into vanity. 56 // should survive and the first go into vanity.
56 ASSERT_FALSE(file_util::PathExists(temp_file_path_1)); 57 ASSERT_FALSE(file_util::PathExists(temp_file_path_1));
57 ASSERT_TRUE(file_util::PathExists(temp_file_path_2)); 58 ASSERT_TRUE(file_util::PathExists(temp_file_path_2));
58 } 59 }
OLDNEW
« no previous file with comments | « content/browser/file_system/file_system_browsertest.cc ('k') | content/browser/in_process_webkit/dom_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698