| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/public/browser/web_contents_delegate.h" | 9 #include "content/public/browser/web_contents_delegate.h" |
| 10 #include "content/test/test_browser_context.h" | 10 #include "content/test/test_browser_context.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class MockWebContentsDelegate : public content::WebContentsDelegate { | 15 class MockWebContentsDelegate : public content::WebContentsDelegate { |
| 16 public: | 16 public: |
| 17 virtual ~MockWebContentsDelegate() {} | 17 virtual ~MockWebContentsDelegate() {} |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 TEST(WebContentsDelegateTest, UnregisterInDestructor) { | 20 TEST(WebContentsDelegateTest, UnregisterInDestructor) { |
| 21 MessageLoop loop(MessageLoop::TYPE_UI); | 21 MessageLoop loop(MessageLoop::TYPE_UI); |
| 22 TestBrowserContext browser_context; | 22 TestBrowserContext browser_context; |
| 23 | 23 |
| 24 scoped_ptr<WebContentsImpl> contents_a(new WebContentsImpl(&browser_context, | 24 scoped_ptr<WebContentsImpl> contents_a(new WebContentsImpl(&browser_context, |
| 25 NULL, | 25 NULL, |
| 26 MSG_ROUTING_NONE, | 26 MSG_ROUTING_NONE, |
| 27 NULL, | 27 NULL, |
| 28 NULL, |
| 28 NULL)); | 29 NULL)); |
| 29 scoped_ptr<WebContentsImpl> contents_b(new WebContentsImpl(&browser_context, | 30 scoped_ptr<WebContentsImpl> contents_b(new WebContentsImpl(&browser_context, |
| 30 NULL, | 31 NULL, |
| 31 MSG_ROUTING_NONE, | 32 MSG_ROUTING_NONE, |
| 32 NULL, | 33 NULL, |
| 34 NULL, |
| 33 NULL)); | 35 NULL)); |
| 34 EXPECT_TRUE(contents_a->GetDelegate() == NULL); | 36 EXPECT_TRUE(contents_a->GetDelegate() == NULL); |
| 35 EXPECT_TRUE(contents_b->GetDelegate() == NULL); | 37 EXPECT_TRUE(contents_b->GetDelegate() == NULL); |
| 36 | 38 |
| 37 scoped_ptr<MockWebContentsDelegate> delegate(new MockWebContentsDelegate()); | 39 scoped_ptr<MockWebContentsDelegate> delegate(new MockWebContentsDelegate()); |
| 38 | 40 |
| 39 // Setting a delegate should work correctly. | 41 // Setting a delegate should work correctly. |
| 40 contents_a->SetDelegate(delegate.get()); | 42 contents_a->SetDelegate(delegate.get()); |
| 41 EXPECT_EQ(delegate.get(), contents_a->GetDelegate()); | 43 EXPECT_EQ(delegate.get(), contents_a->GetDelegate()); |
| 42 EXPECT_TRUE(contents_b->GetDelegate() == NULL); | 44 EXPECT_TRUE(contents_b->GetDelegate() == NULL); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 EXPECT_TRUE(contents_a->GetDelegate() == NULL); | 67 EXPECT_TRUE(contents_a->GetDelegate() == NULL); |
| 66 EXPECT_TRUE(contents_b->GetDelegate() == NULL); | 68 EXPECT_TRUE(contents_b->GetDelegate() == NULL); |
| 67 | 69 |
| 68 // Destroy the WebContentses and run the message loop to prevent leaks. | 70 // Destroy the WebContentses and run the message loop to prevent leaks. |
| 69 contents_a.reset(NULL); | 71 contents_a.reset(NULL); |
| 70 contents_b.reset(NULL); | 72 contents_b.reset(NULL); |
| 71 loop.RunAllPending(); | 73 loop.RunAllPending(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 } // namespace | 76 } // namespace |
| OLD | NEW |