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

Side by Side Diff: chrome/browser/browsing_data_local_storage_helper_browsertest.cc

Issue 7480041: Adding session-only localStorage. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Adding tests. Created 9 years, 4 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/test/thread_test_helper.h" 12 #include "base/test/thread_test_helper.h"
13 #include "chrome/browser/browsing_data_helper_browsertest.h" 13 #include "chrome/browser/browsing_data_helper_browsertest.h"
14 #include "chrome/browser/browsing_data_local_storage_helper.h" 14 #include "chrome/browser/browsing_data_local_storage_helper.h"
15 #include "chrome/test/in_process_browser_test.h" 15 #include "chrome/test/in_process_browser_test.h"
16 #include "chrome/test/testing_profile.h" 16 #include "chrome/test/testing_profile.h"
17 #include "chrome/test/ui_test_utils.h" 17 #include "chrome/test/ui_test_utils.h"
18 #include "content/browser/in_process_webkit/webkit_context.h" 18 #include "content/browser/in_process_webkit/webkit_context.h"
19 #include "content/browser/in_process_webkit/webkit_thread.h" 19 #include "content/browser/in_process_webkit/webkit_thread.h"
20 #include "content/browser/mock_resource_context.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace { 23 namespace {
23 typedef 24 typedef
24 BrowsingDataHelperCallback<BrowsingDataLocalStorageHelper::LocalStorageInfo> 25 BrowsingDataHelperCallback<BrowsingDataLocalStorageHelper::LocalStorageInfo>
25 TestCompletionCallback; 26 TestCompletionCallback;
26 27
27 const FilePath::CharType kTestFile0[] = 28 const FilePath::CharType kTestFile0[] =
28 FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage"); 29 FILE_PATH_LITERAL("http_www.chromium.org_0.localstorage");
29 30
30 const FilePath::CharType kTestFile1[] = 31 const FilePath::CharType kTestFile1[] =
31 FILE_PATH_LITERAL("http_www.google.com_0.localstorage"); 32 FILE_PATH_LITERAL("http_www.google.com_0.localstorage");
32 33
33 const FilePath::CharType kTestFileInvalid[] = 34 const FilePath::CharType kTestFileInvalid[] =
34 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo"); 35 FILE_PATH_LITERAL("http_www.google.com_localstorage_0.foo");
35 36
36 // This is only here to test that extension state is not listed by the helper. 37 // This is only here to test that extension state is not listed by the helper.
37 const FilePath::CharType kTestFileExtension[] = FILE_PATH_LITERAL( 38 const FilePath::CharType kTestFileExtension[] = FILE_PATH_LITERAL(
38 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0.localstorage"); 39 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0.localstorage");
39 40
40 class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest { 41 class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest {
42 public:
43 virtual void SetUpOnMainThread() {
44 // Make sure TestURLRequestContext gets initliazed early enough (it needs to
45 // be constructed in the UI thread). Normally Profile's URLRequestContext is
46 // initialized early enough, but the same is not true for the
47 // TestingProfile.
48 content::MockResourceContext::GetInstance();
49 }
41 protected: 50 protected:
42 void CreateLocalStorageFilesForTest() { 51 void CreateLocalStorageFilesForTest() {
43 FilePath storage_path = GetLocalStoragePathForTestingProfile(); 52 FilePath storage_path = GetLocalStoragePathForTestingProfile();
44 file_util::CreateDirectory(storage_path); 53 file_util::CreateDirectory(storage_path);
45 const FilePath::CharType* kFilesToCreate[] = { 54 const FilePath::CharType* kFilesToCreate[] = {
46 kTestFile0, kTestFile1, kTestFileInvalid, kTestFileExtension 55 kTestFile0, kTestFile1, kTestFileInvalid, kTestFileExtension
47 }; 56 };
48 for (size_t i = 0; i < arraysize(kFilesToCreate); ++i) { 57 for (size_t i = 0; i < arraysize(kFilesToCreate); ++i) {
49 FilePath file_path = storage_path.Append(kFilesToCreate[i]); 58 FilePath file_path = storage_path.Append(kFilesToCreate[i]);
50 file_util::WriteFile(file_path, NULL, 0); 59 file_util::WriteFile(file_path, NULL, 0);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 helper->StartFetching( 184 helper->StartFetching(
176 NewCallback(&callback, &TestCompletionCallback::callback)); 185 NewCallback(&callback, &TestCompletionCallback::callback));
177 186
178 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = 187 std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result =
179 callback.result(); 188 callback.result();
180 189
181 ASSERT_EQ(1u, result.size()); 190 ASSERT_EQ(1u, result.size());
182 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); 191 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value());
183 } 192 }
184 } // namespace 193 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698