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