| 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 "content/public/browser/web_contents_user_data.h" | 5 #include "content/public/browser/web_contents_user_data.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 8 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 9 #include "content/public/test/test_renderer_host.h" | 10 #include "content/public/test/test_renderer_host.h" |
| 10 #include "content/public/test/web_contents_tester.h" | 11 #include "content/public/test/web_contents_tester.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 class WebContentsAttachedClass1 | 16 class WebContentsAttachedClass1 |
| 16 : public WebContentsUserData<WebContentsAttachedClass1> { | 17 : public WebContentsUserData<WebContentsAttachedClass1> { |
| 17 public: | 18 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 WebContentsAttachedClass1::FromWebContents(contents); | 58 WebContentsAttachedClass1::FromWebContents(contents); |
| 58 ASSERT_TRUE(class1again != NULL); | 59 ASSERT_TRUE(class1again != NULL); |
| 59 class2 = WebContentsAttachedClass2::FromWebContents(contents); | 60 class2 = WebContentsAttachedClass2::FromWebContents(contents); |
| 60 ASSERT_TRUE(class2 != NULL); | 61 ASSERT_TRUE(class2 != NULL); |
| 61 ASSERT_EQ(class1, class1again); | 62 ASSERT_EQ(class1, class1again); |
| 62 ASSERT_NE(static_cast<void*>(class1), static_cast<void*>(class2)); | 63 ASSERT_NE(static_cast<void*>(class1), static_cast<void*>(class2)); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(WebContentsUserDataTest, TwoInstancesOneAttachment) { | 66 TEST_F(WebContentsUserDataTest, TwoInstancesOneAttachment) { |
| 66 WebContents* contents1 = web_contents(); | 67 WebContents* contents1 = web_contents(); |
| 67 scoped_ptr<WebContents> contents2( | 68 std::unique_ptr<WebContents> contents2( |
| 68 WebContentsTester::CreateTestWebContents(browser_context(), NULL)); | 69 WebContentsTester::CreateTestWebContents(browser_context(), NULL)); |
| 69 | 70 |
| 70 WebContentsAttachedClass1* one_class = | 71 WebContentsAttachedClass1* one_class = |
| 71 WebContentsAttachedClass1::FromWebContents(contents1); | 72 WebContentsAttachedClass1::FromWebContents(contents1); |
| 72 ASSERT_EQ(NULL, one_class); | 73 ASSERT_EQ(NULL, one_class); |
| 73 WebContentsAttachedClass1* two_class = | 74 WebContentsAttachedClass1* two_class = |
| 74 WebContentsAttachedClass1::FromWebContents(contents2.get()); | 75 WebContentsAttachedClass1::FromWebContents(contents2.get()); |
| 75 ASSERT_EQ(NULL, two_class); | 76 ASSERT_EQ(NULL, two_class); |
| 76 | 77 |
| 77 WebContentsAttachedClass1::CreateForWebContents(contents1); | 78 WebContentsAttachedClass1::CreateForWebContents(contents1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 101 ASSERT_TRUE(clazz != NULL); | 102 ASSERT_TRUE(clazz != NULL); |
| 102 | 103 |
| 103 WebContentsAttachedClass1::CreateForWebContents(contents); | 104 WebContentsAttachedClass1::CreateForWebContents(contents); |
| 104 WebContentsAttachedClass1* class_again = | 105 WebContentsAttachedClass1* class_again = |
| 105 WebContentsAttachedClass1::FromWebContents(contents); | 106 WebContentsAttachedClass1::FromWebContents(contents); |
| 106 ASSERT_TRUE(class_again != NULL); | 107 ASSERT_TRUE(class_again != NULL); |
| 107 ASSERT_EQ(clazz, class_again); | 108 ASSERT_EQ(clazz, class_again); |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace content | 111 } // namespace content |
| OLD | NEW |