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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/activity_log.cc ('k') | chrome/browser/extensions/blocked_actions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/synchronization/waitable_event.h"
8 #include "chrome/browser/extensions/activity_log.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/test_extension_system.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/extensions/extension_builder.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/test/test_browser_thread.h"
17 #include "sql/statement.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace extensions {
21
22 class ActivityLogTest : public ChromeRenderViewHostTestHarness {
23 public:
24 ActivityLogTest()
25 : ui_thread_(BrowserThread::UI, MessageLoop::current()),
26 db_thread_(BrowserThread::DB),
27 file_thread_(BrowserThread::FILE, MessageLoop::current()) {}
28
29 virtual void SetUp() OVERRIDE {
30 ChromeRenderViewHostTestHarness::SetUp();
31 CommandLine command_line(CommandLine::NO_PROGRAM);
32 profile_ =
33 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
34 extension_service_ = static_cast<TestExtensionSystem*>(
35 ExtensionSystem::Get(profile_))->CreateExtensionService(
36 &command_line, FilePath(), false);
37 db_thread_.Start();
38 }
39
40 ~ActivityLogTest() {
41 base::WaitableEvent done(false, false);
42 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
43 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
44 done.Wait();
45 db_thread_.Stop();
46 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
47 MessageLoop::current()->Run();
48 }
49
50 protected:
51 ExtensionService* extension_service_;
52 Profile* profile_;
53
54 private:
55 content::TestBrowserThread ui_thread_;
56 content::TestBrowserThread db_thread_;
57 content::TestBrowserThread file_thread_;
58 };
59
60 TEST_F(ActivityLogTest, ConstructAndLog) {
61 ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
62 scoped_refptr<const Extension> extension =
63 ExtensionBuilder()
64 .SetManifest(DictionaryBuilder()
65 .Set("name", "Test extension")
66 .Set("version", "1.0.0")
67 .Set("manifest_version", 2))
68 .Build();
69 extension_service_->AddExtension(extension);
70 ListValue* args = new ListValue();
71 for (int i = 0; i < 30; i++) {
72 // Run this a bunch of times and hope that if something goes wrong with
73 // threading, 30 times is enough to cause it to fail.
74 activity_log->LogAPIAction(extension, std::string("tabs.testMethod"), args);
75 }
76 // Need to ensure the writes were completed.
77 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3));
78 FilePath db_file = profile_->GetPath().Append(
79 chrome::kExtensionActivityLogFilename);
80 sql::Connection db;
81 ASSERT_TRUE(db.Open(db_file));
82 std::string sql_str = "SELECT * FROM " + std::string(manager_table_name_);
83 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
84 ASSERT_TRUE(statement.Step());
85 ASSERT_EQ("UNKNOWN_ACTION", statement.ColumnString(2));
86 ASSERT_EQ("TABS", statement.ColumnString(3));
87 ASSERT_EQ("tabs.testMethod()", statement.ColumnString(4));
88 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.
89 }
90
91 } // namespace extensions
92
OLDNEW
« 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