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

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

Issue 9836066: Have content cancel requests for ResourceContexts when they shutdown, instead of depending on the e… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/in_process_webkit/dom_storage_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/scoped_temp_dir.h"
8 #include "base/test/thread_test_helper.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "content/browser/in_process_webkit/dom_storage_context_impl.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/common/url_constants.h"
13 #include "content/test/test_browser_context.h"
14 #include "googleurl/src/gurl.h"
15 #include "webkit/dom_storage/dom_storage_types.h"
16 #include "webkit/quota/special_storage_policy.h"
17
18 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND
19 // No longer applicable.
20 #else
21
22 using content::BrowserContext;
23 using content::BrowserThread;
24
25 typedef InProcessBrowserTest DOMStorageBrowserTest;
26
27 namespace {
28
29 class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
30 public:
31 TestSpecialStoragePolicy() {
32 }
33
34 virtual bool IsStorageProtected(const GURL& origin) OVERRIDE {
35 return origin.SchemeIs(chrome::kChromeDevToolsScheme);
36 }
37
38 virtual bool IsStorageUnlimited(const GURL& origin) OVERRIDE {
39 return false;
40 }
41
42 virtual bool IsFileHandler(const std::string& extension_id) OVERRIDE {
43 return false;
44 }
45
46 virtual bool IsStorageSessionOnly(const GURL& origin) OVERRIDE {
47 return false;
48 }
49
50 virtual bool HasSessionOnlyOrigins() OVERRIDE {
51 return false;
52 }
53 };
54
55 } // namespace
56
57 #if defined(OS_MACOSX)
58 // http://crbug.com/115150. On Mac, failure rate is about 30% currently.
59 #define MAYBE_ClearLocalState DISABLED_ClearLocalState
60 #else
61 #define MAYBE_ClearLocalState ClearLocalState
62 #endif
63
64 // In proc browser test is needed here because ClearLocalState indirectly calls
65 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin.
66 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, MAYBE_ClearLocalState) {
67 // Create test files.
68 ScopedTempDir temp_dir;
69 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
70 FilePath domstorage_dir = temp_dir.path().Append(
71 DOMStorageContextImpl::kLocalStorageDirectory);
72 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
73
74 FilePath::StringType file_name_1(FILE_PATH_LITERAL("http_foo_0"));
75 file_name_1.append(DOMStorageContextImpl::kLocalStorageExtension);
76 FilePath::StringType file_name_2(FILE_PATH_LITERAL("chrome-devtools_foo_0"));
77 file_name_2.append(DOMStorageContextImpl::kLocalStorageExtension);
78 FilePath temp_file_path_1 = domstorage_dir.Append(file_name_1);
79 FilePath temp_file_path_2 = domstorage_dir.Append(file_name_2);
80
81 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_1, ".", 1));
82 ASSERT_EQ(1, file_util::WriteFile(temp_file_path_2, "o", 1));
83
84 // Create the scope which will ensure we run the destructor of the webkit
85 // context which should trigger the clean up.
86 {
87 TestBrowserContext browser_context;
88 browser_context.SetSpecialStoragePolicy(new TestSpecialStoragePolicy());
89 DOMStorageContextImpl* dom_storage_context =
90 static_cast<DOMStorageContextImpl*>(
91 BrowserContext::GetDOMStorageContext(&browser_context));
92 dom_storage_context->set_data_path_for_testing(temp_dir.path());
93 dom_storage_context->SetClearLocalState(true);
94 }
95 // Make sure we wait until the destructor has run.
96 scoped_refptr<base::ThreadTestHelper> helper(
97 new base::ThreadTestHelper(
98 BrowserThread::GetMessageLoopProxyForThread(
99 BrowserThread::WEBKIT_DEPRECATED)));
100 ASSERT_TRUE(helper->Run());
101
102 // Because we specified https for scheme to be skipped the second file
103 // should survive and the first go into vanity.
104 ASSERT_FALSE(file_util::PathExists(temp_file_path_1));
105 ASSERT_TRUE(file_util::PathExists(temp_file_path_2));
106 }
107
108 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/in_process_webkit/dom_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698