| OLD | NEW |
| 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 "chrome/test/testing_profile.h" | 5 #include "chrome/test/testing_profile.h" |
| 6 #include "content/browser/browser_thread.h" | 6 #include "content/browser/browser_thread.h" |
| 7 #include "content/browser/in_process_webkit/dom_storage_context.h" | 7 #include "content/browser/in_process_webkit/dom_storage_context.h" |
| 8 #include "content/browser/in_process_webkit/webkit_context.h" | 8 #include "content/browser/in_process_webkit/webkit_context.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 class MockDOMStorageContext : public DOMStorageContext { | 11 class MockDOMStorageContext : public DOMStorageContext { |
| 12 public: | 12 public: |
| 13 MockDOMStorageContext(WebKitContext* webkit_context, | 13 MockDOMStorageContext(WebKitContext* webkit_context, |
| 14 quota::SpecialStoragePolicy* special_storage_policy) | 14 quota::SpecialStoragePolicy* special_storage_policy, |
| 15 : DOMStorageContext(webkit_context, special_storage_policy), | 15 const content::ResourceContext& resource_context) |
| 16 : DOMStorageContext(webkit_context, |
| 17 special_storage_policy, |
| 18 resource_context), |
| 16 purge_count_(0) { | 19 purge_count_(0) { |
| 17 } | 20 } |
| 18 | 21 |
| 19 virtual void PurgeMemory() { | 22 virtual void PurgeMemory() { |
| 20 EXPECT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 23 EXPECT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 21 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 24 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 22 ++purge_count_; | 25 ++purge_count_; |
| 23 } | 26 } |
| 24 | 27 |
| 25 int purge_count() const { return purge_count_; } | 28 int purge_count() const { return purge_count_; } |
| 26 | 29 |
| 27 private: | 30 private: |
| 28 int purge_count_; | 31 int purge_count_; |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 TEST(WebKitContextTest, Basic) { | 34 TEST(WebKitContextTest, Basic) { |
| 32 TestingProfile profile; | 35 TestingProfile profile; |
| 33 scoped_refptr<WebKitContext> context1(new WebKitContext( | 36 scoped_refptr<WebKitContext> context1(new WebKitContext( |
| 34 profile.IsOffTheRecord(), profile.GetPath(), | 37 profile.IsOffTheRecord(), profile.GetPath(), |
| 35 profile.GetSpecialStoragePolicy(), | 38 profile.GetSpecialStoragePolicy(), |
| 39 profile.GetResourceContext(), |
| 36 false, NULL, NULL)); | 40 false, NULL, NULL)); |
| 37 EXPECT_TRUE(profile.GetPath() == context1->data_path()); | 41 EXPECT_TRUE(profile.GetPath() == context1->data_path()); |
| 38 EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito()); | 42 EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito()); |
| 39 | 43 |
| 40 scoped_refptr<WebKitContext> context2(new WebKitContext( | 44 scoped_refptr<WebKitContext> context2(new WebKitContext( |
| 41 profile.IsOffTheRecord(), profile.GetPath(), | 45 profile.IsOffTheRecord(), profile.GetPath(), |
| 42 profile.GetSpecialStoragePolicy(), | 46 profile.GetSpecialStoragePolicy(), |
| 47 profile.GetResourceContext(), |
| 43 false, NULL, NULL)); | 48 false, NULL, NULL)); |
| 44 EXPECT_TRUE(context1->data_path() == context2->data_path()); | 49 EXPECT_TRUE(context1->data_path() == context2->data_path()); |
| 45 EXPECT_TRUE(context1->is_incognito() == context2->is_incognito()); | 50 EXPECT_TRUE(context1->is_incognito() == context2->is_incognito()); |
| 46 } | 51 } |
| 47 | 52 |
| 48 TEST(WebKitContextTest, PurgeMemory) { | 53 TEST(WebKitContextTest, PurgeMemory) { |
| 49 // Start up a WebKit thread for the WebKitContext to call the | 54 // Start up a WebKit thread for the WebKitContext to call the |
| 50 // DOMStorageContext on. | 55 // DOMStorageContext on. |
| 51 MessageLoop message_loop(MessageLoop::TYPE_DEFAULT); | 56 MessageLoop message_loop(MessageLoop::TYPE_DEFAULT); |
| 52 BrowserThread webkit_thread(BrowserThread::WEBKIT, &message_loop); | 57 BrowserThread webkit_thread(BrowserThread::WEBKIT, &message_loop); |
| 53 | 58 |
| 54 { | 59 { |
| 55 // Create the contexts. | 60 // Create the contexts. |
| 56 TestingProfile profile; | 61 TestingProfile profile; |
| 57 scoped_refptr<WebKitContext> context(new WebKitContext( | 62 scoped_refptr<WebKitContext> context(new WebKitContext( |
| 58 profile.IsOffTheRecord(), profile.GetPath(), | 63 profile.IsOffTheRecord(), profile.GetPath(), |
| 59 profile.GetSpecialStoragePolicy(), | 64 profile.GetSpecialStoragePolicy(), |
| 65 profile.GetResourceContext(), |
| 60 false, NULL, NULL)); | 66 false, NULL, NULL)); |
| 61 MockDOMStorageContext* mock_context = new MockDOMStorageContext( | 67 MockDOMStorageContext* mock_context = new MockDOMStorageContext( |
| 62 context.get(), profile.GetSpecialStoragePolicy()); | 68 context.get(), |
| 69 profile.GetSpecialStoragePolicy(), |
| 70 profile.GetResourceContext()); |
| 63 context->set_dom_storage_context(mock_context); // Takes ownership. | 71 context->set_dom_storage_context(mock_context); // Takes ownership. |
| 64 | 72 |
| 65 // Ensure PurgeMemory() calls our mock object on the right thread. | 73 // Ensure PurgeMemory() calls our mock object on the right thread. |
| 66 EXPECT_EQ(0, mock_context->purge_count()); | 74 EXPECT_EQ(0, mock_context->purge_count()); |
| 67 context->PurgeMemory(); | 75 context->PurgeMemory(); |
| 68 MessageLoop::current()->RunAllPending(); | 76 MessageLoop::current()->RunAllPending(); |
| 69 EXPECT_EQ(1, mock_context->purge_count()); | 77 EXPECT_EQ(1, mock_context->purge_count()); |
| 70 } | 78 } |
| 71 // WebKitContext's destructor posts stuff to the webkit thread. Let | 79 // WebKitContext's destructor posts stuff to the webkit thread. Let |
| 72 // WebKitContext go out of scope here before processing WebKitContext's | 80 // WebKitContext go out of scope here before processing WebKitContext's |
| 73 // clean-up tasks. | 81 // clean-up tasks. |
| 74 MessageLoop::current()->RunAllPending(); | 82 MessageLoop::current()->RunAllPending(); |
| 75 } | 83 } |
| OLD | NEW |