Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Unified Diff: chrome/browser/extensions/activity_log/activity_log_unittest.cc

Issue 15686007: Remove Activity Log usage of Extension objects (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added removed code back to see if that fixes persistent memory errors Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/activity_log/activity_log_unittest.cc
diff --git a/chrome/browser/extensions/activity_log/activity_log_unittest.cc b/chrome/browser/extensions/activity_log/activity_log_unittest.cc
index d37f6827e97b0091ddf062dea5b38e3f615ac861..9e0bb12e134871d53f4c1d415e9fed1f98dac839 100644
--- a/chrome/browser/extensions/activity_log/activity_log_unittest.cc
+++ b/chrome/browser/extensions/activity_log/activity_log_unittest.cc
@@ -4,6 +4,8 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/extensions/activity_log/dom_actions.h"
@@ -13,7 +15,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/dom_action_types.h"
#include "chrome/common/extensions/extension_builder.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
@@ -26,34 +27,44 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#endif
+namespace {
+
+const char kExtensionId[] = "abc";
+
+} // namespace
+
namespace extensions {
-class ActivityLogTest : public ChromeRenderViewHostTestHarness {
+class ActivityLogTest : public testing::Test {
public:
ActivityLogTest()
- : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
- db_thread_(BrowserThread::DB, base::MessageLoop::current()),
- file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
+ : message_loop_(base::MessageLoop::TYPE_IO),
+ ui_thread_(BrowserThread::UI, &message_loop_),
+ db_thread_(BrowserThread::DB, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_),
+ io_thread_(BrowserThread::IO, &message_loop_) {}
virtual void SetUp() OVERRIDE {
- ChromeRenderViewHostTestHarness::SetUp();
CommandLine command_line(CommandLine::NO_PROGRAM);
- profile_ =
- Profile::FromBrowserContext(web_contents()->GetBrowserContext());
- extension_service_ = static_cast<TestExtensionSystem*>(
- ExtensionSystem::Get(profile_))->CreateExtensionService(
- &command_line, base::FilePath(), false);
+ profile_.reset(new TestingProfile());
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExtensionActivityLogging);
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExtensionActivityLogTesting);
ActivityLog::RecomputeLoggingIsEnabled();
+ extension_service_ = static_cast<TestExtensionSystem*>(
+ ExtensionSystem::Get(profile_.get()))->CreateExtensionService(
+ &command_line, base::FilePath(), false);
}
- virtual ~ActivityLogTest() {
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::MessageLoop::QuitClosure());
- base::MessageLoop::current()->Run();
+ virtual void TearDown() OVERRIDE {
+ base::RunLoop().RunUntilIdle();
+ profile_.reset(NULL);
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::MessageLoop::QuitClosure(),
+ base::TimeDelta::FromSeconds(4)); // Don't hang on failure.
+ base::RunLoop().RunUntilIdle();
}
static void RetrieveActions_LogAndFetchActions(
@@ -64,7 +75,8 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness {
static void Arguments_Missing(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
scoped_refptr<Action> last = i->front();
- std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
+ std::string id(kExtensionId);
+ std::string noargs = "ID: " + id + ", CATEGORY: "
"CALL, API: tabs.testMethod, ARGS: ";
ASSERT_EQ(noargs, last->PrintForDebug());
}
@@ -72,19 +84,22 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness {
static void Arguments_Present(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
scoped_refptr<Action> last = i->front();
- std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
+ std::string id(kExtensionId);
+ std::string args = "ID: " + id + ", CATEGORY: "
"CALL, API: extension.connect, ARGS: \"hello\", \"world\"";
ASSERT_EQ(args, last->PrintForDebug());
}
protected:
+ scoped_ptr<TestingProfile> profile_;
ExtensionService* extension_service_;
- Profile* profile_;
private:
+ base::MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
content::TestBrowserThread file_thread_;
+ content::TestBrowserThread io_thread_;
#if defined OS_CHROMEOS
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
@@ -98,7 +113,6 @@ TEST_F(ActivityLogTest, Enabled) {
}
TEST_F(ActivityLogTest, Construct) {
- ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
@@ -107,29 +121,22 @@ TEST_F(ActivityLogTest, Construct) {
.Set("manifest_version", 2))
.Build();
extension_service_->AddExtension(extension);
+ ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
scoped_ptr<ListValue> args(new ListValue());
ASSERT_TRUE(ActivityLog::IsLogEnabled());
activity_log->LogAPIAction(
- extension, std::string("tabs.testMethod"), args.get(), std::string());
+ kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
}
TEST_F(ActivityLogTest, LogAndFetchActions) {
- ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
- scoped_refptr<const Extension> extension =
- ExtensionBuilder()
- .SetManifest(DictionaryBuilder()
- .Set("name", "Test extension")
- .Set("version", "1.0.0")
- .Set("manifest_version", 2))
- .Build();
- extension_service_->AddExtension(extension);
+ ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
scoped_ptr<ListValue> args(new ListValue());
ASSERT_TRUE(ActivityLog::IsLogEnabled());
// Write some API calls
activity_log->LogAPIAction(
- extension, std::string("tabs.testMethod"), args.get(), std::string());
- activity_log->LogDOMAction(extension,
+ kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
+ activity_log->LogDOMAction(kExtensionId,
GURL("http://www.google.com"),
string16(),
std::string("document.write"),
@@ -137,35 +144,26 @@ TEST_F(ActivityLogTest, LogAndFetchActions) {
DomActionType::METHOD,
std::string("extra"));
activity_log->GetActions(
- extension->id(),
+ kExtensionId,
0,
base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions));
}
TEST_F(ActivityLogTest, LogWithoutArguments) {
- ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
+ ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
activity_log->SetArgumentLoggingForTesting(false);
- scoped_refptr<const Extension> extension =
- ExtensionBuilder()
- .SetManifest(DictionaryBuilder()
- .Set("name", "Test extension")
- .Set("version", "1.0.0")
- .Set("manifest_version", 2))
- .Build();
- extension_service_->AddExtension(extension);
ASSERT_TRUE(ActivityLog::IsLogEnabled());
scoped_ptr<ListValue> args(new ListValue());
args->Set(0, new base::StringValue("hello"));
args->Set(1, new base::StringValue("world"));
activity_log->LogAPIAction(
- extension, std::string("tabs.testMethod"), args.get(), std::string());
+ kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
activity_log->GetActions(
- extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Missing));
+ kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing));
}
TEST_F(ActivityLogTest, LogWithArguments) {
- ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
@@ -174,15 +172,18 @@ TEST_F(ActivityLogTest, LogWithArguments) {
.Set("manifest_version", 2))
.Build();
extension_service_->AddExtension(extension);
+ ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
ASSERT_TRUE(ActivityLog::IsLogEnabled());
scoped_ptr<ListValue> args(new ListValue());
args->Set(0, new base::StringValue("hello"));
args->Set(1, new base::StringValue("world"));
- activity_log->LogAPIAction(
- extension, std::string("extension.connect"), args.get(), std::string());
+ activity_log->LogAPIAction(kExtensionId,
+ std::string("extension.connect"),
+ args.get(),
+ std::string());
activity_log->GetActions(
- extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present));
+ kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present));
}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_log.cc ('k') | chrome/browser/extensions/api/web_request/web_request_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698