| 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..e2a692af52a3db69ca5515178f6ad5edf07a9419 100644
|
| --- a/content/browser/in_process_webkit/dom_storage_browsertest.cc
|
| +++ b/content/browser/in_process_webkit/dom_storage_browsertest.cc
|
| @@ -6,13 +6,113 @@
|
| #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)
|
| + : base::ThreadTestHelper(target_thread),
|
| + storage_context_(storage_context),
|
| + webkit_context_(webkit_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, false);
|
| + EXPECT_TRUE(session_only_storage_area != NULL);
|
| + DOMStorageArea* permanent_storage_area =
|
| + storage_namespace->GetStorageArea(permanent_origin, true);
|
| + 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_);
|
| +
|
| + // 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_;
|
| +};
|
| +
|
| +} // 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 +152,67 @@ 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;
|
| + DOMStorageContext* storage_context =
|
| + profile.GetWebKitContext()->dom_storage_context();
|
| +
|
| + scoped_refptr<dom_storage_test_helpers::ChangingSettingsTestHelper> helper(
|
| + new dom_storage_test_helpers::ChangingSettingsTestHelper(
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT),
|
| + 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()));
|
| + 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));
|
| +}
|
|
|