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