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

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

Issue 11421192: Save extension activity log to a file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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
« no previous file with comments | « chrome/browser/extensions/activity_log.cc ('k') | chrome/browser/extensions/blocked_actions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/activity_log_unittest.cc
===================================================================
--- chrome/browser/extensions/activity_log_unittest.cc (revision 0)
+++ chrome/browser/extensions/activity_log_unittest.cc (revision 0)
@@ -0,0 +1,92 @@
+// 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 "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/browser/extensions/activity_log.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/test_extension_system.h"
+#include "chrome/common/chrome_constants.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"
+#include "sql/statement.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+class ActivityLogTest : public ChromeRenderViewHostTestHarness {
+ public:
+ ActivityLogTest()
+ : ui_thread_(BrowserThread::UI, MessageLoop::current()),
+ db_thread_(BrowserThread::DB),
+ file_thread_(BrowserThread::FILE, MessageLoop::current()) {}
+
+ 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, FilePath(), false);
+ db_thread_.Start();
+ }
+
+ ~ActivityLogTest() {
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
+ db_thread_.Stop();
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
+ MessageLoop::current()->Run();
+ }
+
+ protected:
+ ExtensionService* extension_service_;
+ Profile* profile_;
+
+ private:
+ content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
+ content::TestBrowserThread file_thread_;
+};
+
+TEST_F(ActivityLogTest, ConstructAndLog) {
+ 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);
+ ListValue* args = new ListValue();
+ for (int i = 0; i < 30; i++) {
+ // Run this a bunch of times and hope that if something goes wrong with
+ // threading, 30 times is enough to cause it to fail.
+ activity_log->LogAPIAction(extension, std::string("tabs.testMethod"), args);
+ }
+ // Need to ensure the writes were completed.
+ base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3));
+ FilePath db_file = profile_->GetPath().Append(
+ chrome::kExtensionActivityLogFilename);
+ sql::Connection db;
+ ASSERT_TRUE(db.Open(db_file));
+ std::string sql_str = "SELECT * FROM " + std::string(manager_table_name_);
+ sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
+ ASSERT_TRUE(statement.Step());
+ ASSERT_EQ("UNKNOWN_ACTION", statement.ColumnString(2));
+ ASSERT_EQ("TABS", statement.ColumnString(3));
+ ASSERT_EQ("tabs.testMethod()", statement.ColumnString(4));
+ delete args;
Eric Dingle 2012/12/19 16:04:11 You could also just use scoped_ptr.
felt 2012/12/19 17:56:27 Done.
+}
+
+} // namespace extensions
+
« no previous file with comments | « chrome/browser/extensions/activity_log.cc ('k') | chrome/browser/extensions/blocked_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698