summaryrefslogtreecommitdiffstats
path: root/content/browser/in_process_webkit/webkit_context_unittest.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 17:40:50 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 17:40:50 +0000
commit567812dd45d36e093554664bdbd4284a9670a8b3 (patch)
tree803b8da070eabfd2efa6a50b53f331c4255bbbc6 /content/browser/in_process_webkit/webkit_context_unittest.cc
parentabe19c107967234fce377db157b8b963f83ec529 (diff)
downloadchromium_src-567812dd45d36e093554664bdbd4284a9670a8b3.zip
chromium_src-567812dd45d36e093554664bdbd4284a9670a8b3.tar.gz
chromium_src-567812dd45d36e093554664bdbd4284a9670a8b3.tar.bz2
Move in_process_webkit dir from chrome\browser to content\browser.
Review URL: http://codereview.chromium.org/6580019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/in_process_webkit/webkit_context_unittest.cc')
-rw-r--r--content/browser/in_process_webkit/webkit_context_unittest.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/content/browser/in_process_webkit/webkit_context_unittest.cc b/content/browser/in_process_webkit/webkit_context_unittest.cc
new file mode 100644
index 0000000..811a3d0
--- /dev/null
+++ b/content/browser/in_process_webkit/webkit_context_unittest.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/testing_profile.h"
+#include "content/browser/browser_thread.h"
+#include "content/browser/in_process_webkit/dom_storage_context.h"
+#include "content/browser/in_process_webkit/webkit_context.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class MockDOMStorageContext : public DOMStorageContext {
+ public:
+ explicit MockDOMStorageContext(WebKitContext* webkit_context)
+ : DOMStorageContext(webkit_context),
+ purge_count_(0) {
+ }
+
+ virtual void PurgeMemory() {
+ EXPECT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
+ ++purge_count_;
+ }
+
+ int purge_count() const { return purge_count_; }
+
+ private:
+ int purge_count_;
+};
+
+TEST(WebKitContextTest, Basic) {
+ TestingProfile profile;
+
+ scoped_refptr<WebKitContext> context1(new WebKitContext(&profile, false));
+ EXPECT_TRUE(profile.GetPath() == context1->data_path());
+ EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito());
+
+ scoped_refptr<WebKitContext> context2(new WebKitContext(&profile, false));
+ EXPECT_TRUE(context1->data_path() == context2->data_path());
+ EXPECT_TRUE(context1->is_incognito() == context2->is_incognito());
+}
+
+TEST(WebKitContextTest, PurgeMemory) {
+ // Start up a WebKit thread for the WebKitContext to call the
+ // DOMStorageContext on.
+ BrowserThread webkit_thread(BrowserThread::WEBKIT);
+ webkit_thread.Start();
+
+ // Create the contexts.
+ TestingProfile profile;
+ scoped_refptr<WebKitContext> context(new WebKitContext(&profile, false));
+ MockDOMStorageContext* mock_context =
+ new MockDOMStorageContext(context.get());
+ context->set_dom_storage_context(mock_context); // Takes ownership.
+
+ // Ensure PurgeMemory() calls our mock object on the right thread.
+ EXPECT_EQ(0, mock_context->purge_count());
+ context->PurgeMemory();
+ webkit_thread.Stop(); // Blocks until all tasks are complete.
+ EXPECT_EQ(1, mock_context->purge_count());
+}