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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/extensions/activity_log/activity_log.h"
10 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/test_extension_system.h"
13 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/extension_builder.h"
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/test/test_browser_thread.h"
20 #include "sql/statement.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 #if defined(OS_CHROMEOS)
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/settings/cros_settings.h"
26 #include "chrome/browser/chromeos/settings/device_settings_service.h"
27 #endif
28
29 namespace extensions {
30
31 class StreamWithoutArgsUIPolicyTest : public ChromeRenderViewHostTestHarness {
32 public:
33 StreamWithoutArgsUIPolicyTest()
34 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
35 db_thread_(BrowserThread::DB, base::MessageLoop::current()),
36 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
37
38 virtual void SetUp() OVERRIDE {
39 ChromeRenderViewHostTestHarness::SetUp();
40 CommandLine command_line(CommandLine::NO_PROGRAM);
41 profile_ =
42 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
43 extension_service_ = static_cast<TestExtensionSystem*>(
44 ExtensionSystem::Get(profile_))->CreateExtensionService(
45 &command_line, base::FilePath(), false);
46 CommandLine::ForCurrentProcess()->AppendSwitch(
47 switches::kEnableExtensionActivityLogTesting);
48 }
49
50 virtual ~StreamWithoutArgsUIPolicyTest() {
51 base::MessageLoop::current()->PostTask(FROM_HERE,
52 base::MessageLoop::QuitClosure());
53 base::MessageLoop::current()->Run();
54 }
55
56 static void RetrieveActions_LogAndFetchActions(
57 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
58 ASSERT_EQ(2, static_cast<int>(i->size()));
59 }
60
61 static void Arguments_Missing(
62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
63 scoped_refptr<Action> last = i->front();
64 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
65 "CALL, API: tabs.testMethod, ARGS: ";
66 ASSERT_EQ(noargs, last->PrintForDebug());
67 }
68
69 protected:
70 ExtensionService* extension_service_;
71 Profile* profile_;
72
73 private:
74 content::TestBrowserThread ui_thread_;
75 content::TestBrowserThread db_thread_;
76 content::TestBrowserThread file_thread_;
77
78 #if defined OS_CHROMEOS
79 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
80 chromeos::ScopedTestCrosSettings test_cros_settings_;
81 chromeos::ScopedTestUserManager test_user_manager_;
82 #endif
83 };
84
85 TEST_F(StreamWithoutArgsUIPolicyTest, Construct) {
86 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
87 BrowserThread::UI);
88 scoped_refptr<const Extension> extension =
89 ExtensionBuilder()
90 .SetManifest(DictionaryBuilder()
91 .Set("name", "Test extension")
92 .Set("version", "1.0.0")
93 .Set("manifest_version", 2))
94 .Build();
95 extension_service_->AddExtension(extension);
96 scoped_ptr<ListValue> args(new ListValue());
97 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
98 std::string("tabs.testMethod"), NULL, args.get(), NULL);
99 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.
100 }
101
102 TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) {
103 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
104 BrowserThread::UI);
105 scoped_refptr<const Extension> extension =
106 ExtensionBuilder()
107 .SetManifest(DictionaryBuilder()
108 .Set("name", "Test extension")
109 .Set("version", "1.0.0")
110 .Set("manifest_version", 2))
111 .Build();
112 extension_service_->AddExtension(extension);
113 scoped_ptr<ListValue> args(new ListValue());
114 GURL* gurl = new GURL("http://www.google.com");
115
116 // Write some API calls
117 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
118 std::string("tabs.testMethod"), NULL, args.get(), NULL);
119 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM,
120 extension->id(), std::string("document.write"), gurl, args.get(), NULL);
121 policy->ReadData(extension->id(), 0,
122 base::Bind(
123 StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions));
124 delete policy;
125 delete gurl;
126 }
127
128 TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) {
129 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_,
130 BrowserThread::UI);
131 scoped_refptr<const Extension> extension =
132 ExtensionBuilder()
133 .SetManifest(DictionaryBuilder()
134 .Set("name", "Test extension")
135 .Set("version", "1.0.0")
136 .Set("manifest_version", 2))
137 .Build();
138 extension_service_->AddExtension(extension);
139 scoped_ptr<ListValue> args(new ListValue());
140 args->Set(0, new base::StringValue("hello"));
141 args->Set(1, new base::StringValue("world"));
142 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
143 std::string("tabs.testMethod"), NULL, args.get(), NULL);
144 policy->ReadData(extension->id(), 0,
145 base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing));
146 delete policy;
147 }
148
149 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698