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