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

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

Issue 15573003: New architecture of the activity logging: Policies for summarization (and compression) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. 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/stream_noargs_ui_policy_unittest.cc
diff --git a/chrome/browser/extensions/activity_log/stream_noargs_ui_policy_unittest.cc b/chrome/browser/extensions/activity_log/stream_noargs_ui_policy_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2bc75cd72097bd81a2ee1cb60693f1ff1dc49544
--- /dev/null
+++ b/chrome/browser/extensions/activity_log/stream_noargs_ui_policy_unittest.cc
@@ -0,0 +1,149 @@
+// Copyright 2013 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/message_loop.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/browser/extensions/activity_log/activity_log.h"
+#include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.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/chrome_switches.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"
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#endif
+
+namespace extensions {
+
+class StreamWithoutArgsUIPolicyTest : public ChromeRenderViewHostTestHarness {
+ public:
+ StreamWithoutArgsUIPolicyTest()
+ : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
+ db_thread_(BrowserThread::DB, base::MessageLoop::current()),
+ file_thread_(BrowserThread::FILE, base::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, base::FilePath(), false);
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableExtensionActivityLogTesting);
+ }
+
+ virtual ~StreamWithoutArgsUIPolicyTest() {
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::MessageLoop::QuitClosure());
+ base::MessageLoop::current()->Run();
+ }
+
+ static void RetrieveActions_LogAndFetchActions(
+ scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
+ ASSERT_EQ(2, static_cast<int>(i->size()));
+ }
+
+ static void Arguments_Missing(
+ scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
+ scoped_refptr<Action> last = i->front();
+ std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
+ "CALL, API: tabs.testMethod, ARGS: ";
+ ASSERT_EQ(noargs, last->PrintForDebug());
+ }
+
+ protected:
+ ExtensionService* extension_service_;
+ Profile* profile_;
+
+ private:
+ content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
+ content::TestBrowserThread file_thread_;
+
+#if defined OS_CHROMEOS
+ chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
+ chromeos::ScopedTestCrosSettings test_cros_settings_;
+ chromeos::ScopedTestUserManager test_user_manager_;
+#endif
+};
+
+TEST_F(StreamWithoutArgsUIPolicyTest, Construct) {
+ ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
+ BrowserThread::UI);
+ 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);
+ scoped_ptr<ListValue> args(new ListValue());
+ policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
+ std::string("tabs.testMethod"), NULL, args.get(), NULL);
+ delete policy;
Matt Perry 2013/06/13 18:23:23 use a scoped_ptr, or even just allocate it on the
dbabic 2013/06/13 23:10:08 Done.
+}
+
+TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) {
+ ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
+ BrowserThread::UI);
+ 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);
+ scoped_ptr<ListValue> args(new ListValue());
+ GURL* gurl = new GURL("http://www.google.com");
+
+ // Write some API calls
+ policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
+ std::string("tabs.testMethod"), NULL, args.get(), NULL);
+ policy->ProcessAction(ActivityLogPolicy::ACTION_DOM,
+ extension->id(), std::string("document.write"), gurl, args.get(), NULL);
+ policy->ReadData(extension->id(), 0,
+ base::Bind(
+ StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions));
+ delete policy;
+ delete gurl;
+}
+
+TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) {
+ ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
+ BrowserThread::UI);
+ 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);
+ scoped_ptr<ListValue> args(new ListValue());
+ args->Set(0, new base::StringValue("hello"));
+ args->Set(1, new base::StringValue("world"));
+ policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
+ std::string("tabs.testMethod"), NULL, args.get(), NULL);
+ policy->ReadData(extension->id(), 0,
+ base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing));
+ delete policy;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698