| 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 "chrome/browser/tab_contents/web_contents_user_data.h" | 5 #include "chrome/browser/tab_contents/web_contents_user_data.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "content/public/test/web_contents_tester.h" | 11 #include "content/public/test/web_contents_tester.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class WebContentsAttachedClass1 | 16 class WebContentsAttachedClass1 |
| 17 : public WebContentsUserData<WebContentsAttachedClass1> { | 17 : public WebContentsUserData<WebContentsAttachedClass1> { |
| 18 public: | 18 public: |
| 19 virtual ~WebContentsAttachedClass1() {} |
| 20 private: |
| 19 explicit WebContentsAttachedClass1(content::WebContents* contents) {} | 21 explicit WebContentsAttachedClass1(content::WebContents* contents) {} |
| 20 virtual ~WebContentsAttachedClass1() {} | |
| 21 static int kUserDataKey; | 22 static int kUserDataKey; |
| 23 friend class WebContentsUserData<WebContentsAttachedClass1>; |
| 22 }; | 24 }; |
| 23 | 25 |
| 24 class WebContentsAttachedClass2 | 26 class WebContentsAttachedClass2 |
| 25 : public WebContentsUserData<WebContentsAttachedClass2> { | 27 : public WebContentsUserData<WebContentsAttachedClass2> { |
| 26 public: | 28 public: |
| 29 virtual ~WebContentsAttachedClass2() {} |
| 30 private: |
| 27 explicit WebContentsAttachedClass2(content::WebContents* contents) {} | 31 explicit WebContentsAttachedClass2(content::WebContents* contents) {} |
| 28 virtual ~WebContentsAttachedClass2() {} | |
| 29 static int kUserDataKey; | 32 static int kUserDataKey; |
| 33 friend class WebContentsUserData<WebContentsAttachedClass2>; |
| 30 }; | 34 }; |
| 31 | 35 |
| 32 int WebContentsAttachedClass1::kUserDataKey; | 36 int WebContentsAttachedClass1::kUserDataKey; |
| 33 int WebContentsAttachedClass2::kUserDataKey; | 37 int WebContentsAttachedClass2::kUserDataKey; |
| 34 | 38 |
| 35 } // namespace | 39 } // namespace |
| 36 | 40 |
| 37 typedef ChromeRenderViewHostTestHarness WebContentsUserDataTest; | 41 typedef ChromeRenderViewHostTestHarness WebContentsUserDataTest; |
| 38 | 42 |
| 39 TEST_F(WebContentsUserDataTest, OneInstanceTwoAttachments) { | 43 TEST_F(WebContentsUserDataTest, OneInstanceTwoAttachments) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 WebContentsAttachedClass1::CreateForWebContents(contents); | 102 WebContentsAttachedClass1::CreateForWebContents(contents); |
| 99 clazz = WebContentsAttachedClass1::FromWebContents(contents); | 103 clazz = WebContentsAttachedClass1::FromWebContents(contents); |
| 100 ASSERT_TRUE(clazz != NULL); | 104 ASSERT_TRUE(clazz != NULL); |
| 101 | 105 |
| 102 WebContentsAttachedClass1::CreateForWebContents(contents); | 106 WebContentsAttachedClass1::CreateForWebContents(contents); |
| 103 WebContentsAttachedClass1* class_again = | 107 WebContentsAttachedClass1* class_again = |
| 104 WebContentsAttachedClass1::FromWebContents(contents); | 108 WebContentsAttachedClass1::FromWebContents(contents); |
| 105 ASSERT_TRUE(class_again != NULL); | 109 ASSERT_TRUE(class_again != NULL); |
| 106 ASSERT_EQ(clazz, class_again); | 110 ASSERT_EQ(clazz, class_again); |
| 107 } | 111 } |
| OLD | NEW |