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

Unified Diff: content/browser/in_process_webkit/dom_storage_browsertest.cc

Issue 7480041: Adding session-only localStorage. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Streamlining: Moving ResourceContext& from DOMStorageContext to DOMMessageFilter. 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/in_process_webkit/dom_storage_browsertest.cc
diff --git a/content/browser/in_process_webkit/dom_storage_browsertest.cc b/content/browser/in_process_webkit/dom_storage_browsertest.cc
index c237351212a6818fc617a7584f7e319810ef43a2..b67cb0f043ead1606b8e30ad9c473e6e3d6f3e5f 100644
--- a/content/browser/in_process_webkit/dom_storage_browsertest.cc
+++ b/content/browser/in_process_webkit/dom_storage_browsertest.cc
@@ -6,13 +6,116 @@
#include "base/file_util.h"
#include "base/scoped_temp_dir.h"
#include "base/test/thread_test_helper.h"
+#include "base/utf_string_conversions.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/testing_profile.h"
+#include "content/browser/in_process_webkit/dom_storage_area.h"
#include "content/browser/in_process_webkit/dom_storage_context.h"
+#include "content/browser/in_process_webkit/dom_storage_message_filter.h"
+#include "content/browser/in_process_webkit/dom_storage_namespace.h"
#include "content/browser/in_process_webkit/webkit_context.h"
+namespace base {
+class MessageLoopProxy;
+}
+
typedef InProcessBrowserTest DOMStorageBrowserTest;
+namespace dom_storage_test_helpers {
+
+class ChangingSettingsTestHelper : public base::ThreadTestHelper {
+ public:
+ ChangingSettingsTestHelper(base::MessageLoopProxy* target_thread,
+ DOMStorageContext* storage_context)
+ : base::ThreadTestHelper(target_thread),
+ storage_context_(storage_context){
+ }
+ virtual ~ChangingSettingsTestHelper() {
+ }
+ void RunTest() {
+ DOMStorageNamespace* storage_namespace =
+ storage_context_->GetStorageNamespace(0, true);
+
+ // After a storage for an origin is created, it can always be retrieved,
+ // even if the content setting for that origin is changed.
+ string16 origin1(ASCIIToUTF16("http://www.someorigin.com"));
+ string16 origin2(ASCIIToUTF16("http://www.someotherorigin.com"));
+
+ DOMStorageArea* storage_area1 =
+ storage_namespace->GetStorageArea(origin1, true);
+ EXPECT_TRUE(storage_area1 != NULL);
+ EXPECT_TRUE(storage_area1 ==
+ storage_namespace->GetStorageArea(origin1, false));
+ EXPECT_TRUE(storage_area1 ==
+ storage_namespace->GetStorageArea(origin1, true));
+
+ DOMStorageArea* storage_area2 =
+ storage_namespace->GetStorageArea(origin2, false);
+ EXPECT_TRUE(storage_area2 != NULL);
+ EXPECT_TRUE(storage_area2 != storage_area1);
+ EXPECT_TRUE(storage_area2 ==
+ storage_namespace->GetStorageArea(origin2, false));
+ EXPECT_TRUE(storage_area2 ==
+ storage_namespace->GetStorageArea(origin2, true));
+ set_test_result(true);
+ }
+ DOMStorageContext* storage_context_;
+};
+
+class SessionOnlyTestHelper : public base::ThreadTestHelper {
+ public:
+ SessionOnlyTestHelper(base::MessageLoopProxy* target_thread,
+ DOMStorageContext* storage_context,
+ WebKitContext* webkit_context,
+ const content::ResourceContext& resource_context)
+ : base::ThreadTestHelper(target_thread),
+ storage_context_(storage_context),
+ webkit_context_(webkit_context),
+ resource_context_(resource_context) {
+ }
+ virtual ~SessionOnlyTestHelper() {
+ }
+ void RunTest() {
+ DOMStorageNamespace* storage_namespace =
+ storage_context_->GetStorageNamespace(0, true);
+
+ // Write data into the session-only localStorage and the permanent
+ // localStorage.
+ string16 session_only_origin(ASCIIToUTF16("http://www.sessiononly.com"));
+ string16 permanent_origin(ASCIIToUTF16("http://www.permanent.com"));
+
+ DOMStorageArea* session_only_storage_area =
+ storage_namespace->GetStorageArea(session_only_origin, true);
+ EXPECT_TRUE(session_only_storage_area != NULL);
+ DOMStorageArea* permanent_storage_area =
+ storage_namespace->GetStorageArea(permanent_origin, false);
+ EXPECT_TRUE(permanent_storage_area != NULL);
+
+ string16 key(ASCIIToUTF16("Key"));
+ string16 value(ASCIIToUTF16("Value"));
+ WebKit::WebStorageArea::Result result;
+ NullableString16 old_value;
+ scoped_refptr<DOMStorageMessageFilter> filter =
+ new DOMStorageMessageFilter(0, webkit_context_, resource_context_);
+
+ // Invoke DOMStorageArea::SetItem with this indirection, to have the message
+ // filters set up correctly.
+ filter->OnSetItem(session_only_storage_area->id(), key, value, GURL(""),
+ &result, &old_value);
+ EXPECT_TRUE(result == WebKit::WebStorageArea::ResultOK);
+ filter->OnSetItem(permanent_storage_area->id(), key, value, GURL(""),
+ &result, &old_value);
+ EXPECT_TRUE(result == WebKit::WebStorageArea::ResultOK);
+
+ set_test_result(true);
+ }
+ DOMStorageContext* storage_context_;
+ WebKitContext* webkit_context_;
+ const content::ResourceContext& resource_context_;
+};
+
+} // namespace dom_storage_test_helpers
+
// In proc browser test is needed here because ClearLocalState indirectly calls
// WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin.
IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) {
@@ -52,3 +155,66 @@ IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) {
ASSERT_FALSE(file_util::PathExists(temp_file_path_1));
ASSERT_TRUE(file_util::PathExists(temp_file_path_2));
}
+
+IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ChangingSettings) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath domstorage_dir = temp_dir.path().Append(
+ DOMStorageContext::kLocalStorageDirectory);
+ ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
+
+ TestingProfile profile;
+
+ scoped_refptr<dom_storage_test_helpers::ChangingSettingsTestHelper> helper(
+ new dom_storage_test_helpers::ChangingSettingsTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT),
+ profile.GetWebKitContext()->dom_storage_context()));
+ ASSERT_TRUE(helper->Run());
+}
+
+IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, SessionOnly) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath domstorage_dir = temp_dir.path().Append(
+ DOMStorageContext::kLocalStorageDirectory);
+ ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
+
+ // Create the scope which will ensure we run the destructor of the webkit
+ // context which should trigger the clean up.
+ {
+ TestingProfile profile;
+ DOMStorageContext* storage_context =
+ profile.GetWebKitContext()->dom_storage_context();
+ storage_context->set_data_path(temp_dir.path());
+
+ scoped_refptr<dom_storage_test_helpers::SessionOnlyTestHelper> helper(
+ new dom_storage_test_helpers::SessionOnlyTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT),
+ storage_context,
+ profile.GetWebKitContext(),
+ profile.GetResourceContext()));
+ ASSERT_TRUE(helper->Run());
+ }
+ // Make sure we wait until the destructor has run.
+ scoped_refptr<base::ThreadTestHelper> helper(
+ new base::ThreadTestHelper(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)));
+ ASSERT_TRUE(helper->Run());
+
+ // Expected result: the database file for the permanent storage was created,
+ // but the database for the session only storage was not created.
+ FilePath::StringType session_only_database(
+ FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
+ FilePath::StringType permanent_database(
+ FILE_PATH_LITERAL("http_www.permanent.com_0"));
+ session_only_database.append(DOMStorageContext::kLocalStorageExtension);
+ permanent_database.append(DOMStorageContext::kLocalStorageExtension);
+
+ FilePath session_only_database_path =
+ domstorage_dir.Append(session_only_database);
+ FilePath permanent_database_path =
+ domstorage_dir.Append(permanent_database);
+
+ EXPECT_FALSE(file_util::PathExists(session_only_database_path));
+ EXPECT_TRUE(file_util::PathExists(permanent_database_path));
+}
« no previous file with comments | « content/browser/content_browser_client.h ('k') | content/browser/in_process_webkit/dom_storage_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698