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

Side by Side Diff: chrome/browser/extensions/activity_log/fullstream_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: Fixed browser test. 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/run_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/fullstream_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/test/test_browser_thread_bundle.h"
19 #include "sql/statement.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 #include "chrome/browser/chromeos/settings/device_settings_service.h"
26 #endif
27
28 namespace extensions {
29
30 class FullStreamUIPolicyTest : public testing::Test {
31 public:
32 FullStreamUIPolicyTest()
33 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
34 saved_cmdline_(CommandLine::NO_PROGRAM) {
35 #if defined OS_CHROMEOS
36 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
37 #endif
38 CommandLine command_line(CommandLine::NO_PROGRAM);
39 saved_cmdline_ = *CommandLine::ForCurrentProcess();
40 profile_.reset(new TestingProfile());
41 CommandLine::ForCurrentProcess()->AppendSwitch(
42 switches::kEnableExtensionActivityLogging);
43 CommandLine::ForCurrentProcess()->AppendSwitch(
44 switches::kEnableExtensionActivityLogTesting);
45 extension_service_ = static_cast<TestExtensionSystem*>(
46 ExtensionSystem::Get(profile_.get()))->CreateExtensionService
47 (&command_line, base::FilePath(), false);
48 }
49
50 virtual ~FullStreamUIPolicyTest() {
51 #if defined OS_CHROMEOS
52 test_user_manager_.reset();
53 #endif
54 base::RunLoop().RunUntilIdle();
55 profile_.reset(NULL);
56 base::RunLoop().RunUntilIdle();
57 // Restore the original command line and undo the affects of SetUp().
58 *CommandLine::ForCurrentProcess() = saved_cmdline_;
59 }
60
61 static void RetrieveActions_LogAndFetchActions(
62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
63 ASSERT_EQ(2, static_cast<int>(i->size()));
64 }
65
66 static void Arguments_Present(
67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
68 scoped_refptr<Action> last = i->front();
69 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
70 "call, API: extension.connect, ARGS: \"hello\", \"world\"";
71 ASSERT_EQ(args, last->PrintForDebug());
72 }
73
74 protected:
75 ExtensionService* extension_service_;
76 scoped_ptr<TestingProfile> profile_;
77 content::TestBrowserThreadBundle thread_bundle_;
78 // Used to preserve a copy of the original command line.
79 // The test framework will do this itself as well. However, by then,
80 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in
81 // TearDown().
82 CommandLine saved_cmdline_;
83
84 #if defined OS_CHROMEOS
85 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
86 chromeos::ScopedTestCrosSettings test_cros_settings_;
87 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
88 #endif
89 };
90
91 TEST_F(FullStreamUIPolicyTest, Construct) {
92 scoped_ptr<ActivityLogPolicy> policy(new FullStreamUIPolicy(profile_.get()));
93 scoped_refptr<const Extension> extension =
94 ExtensionBuilder()
95 .SetManifest(DictionaryBuilder()
96 .Set("name", "Test extension")
97 .Set("version", "1.0.0")
98 .Set("manifest_version", 2))
99 .Build();
100 extension_service_->AddExtension(extension);
101 scoped_ptr<ListValue> args(new ListValue());
102 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
103 std::string("tabs.testMethod"), GURL(), args.get(), NULL);
104 }
105
106 TEST_F(FullStreamUIPolicyTest, LogAndFetchActions) {
107 scoped_ptr<ActivityLogPolicy> policy(new FullStreamUIPolicy(profile_.get()));
108 scoped_refptr<const Extension> extension =
109 ExtensionBuilder()
110 .SetManifest(DictionaryBuilder()
111 .Set("name", "Test extension")
112 .Set("version", "1.0.0")
113 .Set("manifest_version", 2))
114 .Build();
115 extension_service_->AddExtension(extension);
116 scoped_ptr<ListValue> args(new ListValue());
117 GURL gurl("http://www.google.com");
118
119 // Write some API calls
120 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(),
121 std::string("tabs.testMethod"), GURL(), args.get(), NULL);
122 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM,
123 extension->id(), std::string("document.write"),
124 gurl, args.get(), NULL);
125 policy->ReadData(extension->id(), 0,
126 base::Bind(FullStreamUIPolicyTest::RetrieveActions_LogAndFetchActions));
127 }
128
129 TEST_F(FullStreamUIPolicyTest, LogWithArguments) {
130 scoped_ptr<ActivityLogPolicy> policy(new FullStreamUIPolicy(profile_.get()));
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("extension.connect"), GURL(), args.get(), NULL);
144 policy->ReadData(extension->id(), 0,
145 base::Bind(FullStreamUIPolicyTest::Arguments_Present));
146 }
147
148 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698