Commit 5eaad14f authored by alexeypa@google.com's avatar alexeypa@google.com

Revert 153571 - Create base class for TabHelpers.

WebContentsUserDataTest.BasicTest is flaky.

BUG=107201
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10868115

TBR=avi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10873101

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153591 0039d316-1c4b-4281-b951-d872f2087c98
parent c3cae2ed
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
#define CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
#include "base/supports_user_data.h"
#include "content/public/browser/web_contents.h"
// A base class for classes attached to, and scoped to, the lifetime of a
// WebContents. For example:
//
// class FooTabHelper : public WebContentsUserData<FooTabHelper> {
// public:
// explicit FooTabHelper(content::WebContents* contents);
// virtual ~FooTabHelper();
//
template <typename T>
class WebContentsUserData : public base::SupportsUserData::Data {
public:
// Creates an object of type T, and attaches it to the specified WebContents.
static void CreateForWebContents(content::WebContents* contents) {
void* key = reinterpret_cast<void*>(&CreateForWebContents);
contents->SetUserData(key, new T(contents));
}
// Retrieves the instance of type T that was attached to the specified
// WebContents (via CreateForWebContents above) and returns it. If no instance
// of the type was attached, returns NULL.
static T* FromWebContents(content::WebContents* contents) {
void* key = reinterpret_cast<void*>(&CreateForWebContents);
return static_cast<T*>(contents->GetUserData(key));
}
};
#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_USER_DATA_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/tab_contents/web_contents_user_data.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/web_contents.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class WebContentsAttachedClass1
: public WebContentsUserData<WebContentsAttachedClass1> {
public:
explicit WebContentsAttachedClass1(content::WebContents* contents) {}
virtual ~WebContentsAttachedClass1() {}
};
class WebContentsAttachedClass2
: public WebContentsUserData<WebContentsAttachedClass2> {
public:
explicit WebContentsAttachedClass2(content::WebContents* contents) {}
virtual ~WebContentsAttachedClass2() {}
};
} // namespace
typedef ChromeRenderViewHostTestHarness WebContentsUserDataTest;
TEST_F(WebContentsUserDataTest, BasicTest) {
content::WebContents* contents = web_contents();
WebContentsAttachedClass1* class1 =
WebContentsAttachedClass1::FromWebContents(contents);
ASSERT_EQ(NULL, class1);
WebContentsAttachedClass2* class2 =
WebContentsAttachedClass2::FromWebContents(contents);
ASSERT_EQ(NULL, class2);
WebContentsAttachedClass1::CreateForWebContents(contents);
class1 = WebContentsAttachedClass1::FromWebContents(contents);
ASSERT_TRUE(class1 != NULL);
class2 = WebContentsAttachedClass2::FromWebContents(contents);
ASSERT_EQ(NULL, class2);
WebContentsAttachedClass2::CreateForWebContents(contents);
WebContentsAttachedClass1* class1again =
WebContentsAttachedClass1::FromWebContents(contents);
ASSERT_TRUE(class1again != NULL);
class2 = WebContentsAttachedClass2::FromWebContents(contents);
ASSERT_TRUE(class2 != NULL);
ASSERT_EQ(class1, class1again);
ASSERT_NE(static_cast<void*>(class1), static_cast<void*>(class2));
}
......@@ -2418,7 +2418,6 @@
'browser/tab_contents/spelling_bubble_model.h',
'browser/tab_contents/spelling_menu_observer.cc',
'browser/tab_contents/spelling_menu_observer.h',
'browser/tab_contents/web_contents_user_data.h',
'browser/tab_contents/web_drag_bookmark_handler_aura.cc',
'browser/tab_contents/web_drag_bookmark_handler_aura.h',
'browser/tab_contents/web_drag_bookmark_handler_gtk.cc',
......
......@@ -1651,7 +1651,6 @@
'browser/sync/test_profile_sync_service.h',
'browser/tab_contents/render_view_context_menu_unittest.cc',
'browser/tab_contents/thumbnail_generator_unittest.cc',
'browser/tab_contents/web_contents_user_data_unittest.cc',
'browser/task_manager/task_manager_unittest.cc',
'browser/task_profiler/task_profiler_data_serializer_unittest.cc',
'browser/themes/browser_theme_pack_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment