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

Side by Side Diff: chrome/browser/extensions/activity_log_unittest.cc

Issue 11946028: Record event activity to the extension activity log. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rename ActivityLog::IsLoggingEnabled Created 7 years, 10 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "chrome/browser/extensions/activity_log.h" 8 #include "chrome/browser/extensions/activity_log.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/test_extension_system.h" 10 #include "chrome/browser/extensions/test_extension_system.h"
(...skipping 19 matching lines...) Expand all
30 virtual void SetUp() OVERRIDE { 30 virtual void SetUp() OVERRIDE {
31 ChromeRenderViewHostTestHarness::SetUp(); 31 ChromeRenderViewHostTestHarness::SetUp();
32 CommandLine command_line(CommandLine::NO_PROGRAM); 32 CommandLine command_line(CommandLine::NO_PROGRAM);
33 profile_ = 33 profile_ =
34 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 34 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
35 extension_service_ = static_cast<TestExtensionSystem*>( 35 extension_service_ = static_cast<TestExtensionSystem*>(
36 ExtensionSystem::Get(profile_))->CreateExtensionService( 36 ExtensionSystem::Get(profile_))->CreateExtensionService(
37 &command_line, FilePath(), false); 37 &command_line, FilePath(), false);
38 CommandLine::ForCurrentProcess()->AppendSwitch( 38 CommandLine::ForCurrentProcess()->AppendSwitch(
39 switches::kEnableExtensionActivityUI); 39 switches::kEnableExtensionActivityUI);
40 ActivityLog::RecomputeLoggingIsEnabled();
40 db_thread_.Start(); 41 db_thread_.Start();
41 } 42 }
42 43
43 ~ActivityLogTest() { 44 ~ActivityLogTest() {
44 base::WaitableEvent done(false, false); 45 base::WaitableEvent done(false, false);
45 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 46 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
46 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 47 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
47 done.Wait(); 48 done.Wait();
48 db_thread_.Stop(); 49 db_thread_.Stop();
49 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 50 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
50 MessageLoop::current()->Run(); 51 MessageLoop::current()->Run();
51 } 52 }
52 53
53 protected: 54 protected:
54 ExtensionService* extension_service_; 55 ExtensionService* extension_service_;
55 Profile* profile_; 56 Profile* profile_;
56 57
57 private: 58 private:
58 content::TestBrowserThread ui_thread_; 59 content::TestBrowserThread ui_thread_;
59 content::TestBrowserThread db_thread_; 60 content::TestBrowserThread db_thread_;
60 content::TestBrowserThread file_thread_; 61 content::TestBrowserThread file_thread_;
61 }; 62 };
62 63
63 TEST_F(ActivityLogTest, Enabled) { 64 TEST_F(ActivityLogTest, Enabled) {
64 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); 65 ASSERT_TRUE(ActivityLog::IsLogEnabled());
65 ASSERT_TRUE(activity_log->IsLoggingEnabled());
66 } 66 }
67 67
68 TEST_F(ActivityLogTest, ConstructAndLog) { 68 TEST_F(ActivityLogTest, ConstructAndLog) {
69 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); 69 ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
70 scoped_refptr<const Extension> extension = 70 scoped_refptr<const Extension> extension =
71 ExtensionBuilder() 71 ExtensionBuilder()
72 .SetManifest(DictionaryBuilder() 72 .SetManifest(DictionaryBuilder()
73 .Set("name", "Test extension") 73 .Set("name", "Test extension")
74 .Set("version", "1.0.0") 74 .Set("version", "1.0.0")
75 .Set("manifest_version", 2)) 75 .Set("manifest_version", 2))
76 .Build(); 76 .Build();
77 extension_service_->AddExtension(extension); 77 extension_service_->AddExtension(extension);
78 scoped_ptr<ListValue> args(new ListValue()); 78 scoped_ptr<ListValue> args(new ListValue());
79 for (int i = 0; i < 30; i++) { 79 for (int i = 0; i < 30; i++) {
80 // Run this a bunch of times and hope that if something goes wrong with 80 // Run this a bunch of times and hope that if something goes wrong with
81 // threading, 30 times is enough to cause it to fail. 81 // threading, 30 times is enough to cause it to fail.
82 ASSERT_TRUE(activity_log->IsLoggingEnabled()); 82 ASSERT_TRUE(ActivityLog::IsLogEnabled());
83 activity_log->LogAPIAction(extension, 83 activity_log->LogAPIAction(extension,
84 std::string("tabs.testMethod"), 84 std::string("tabs.testMethod"),
85 args.get(), 85 args.get(),
86 ""); 86 "");
87 } 87 }
88 // Need to ensure the writes were completed. 88 // Need to ensure the writes were completed.
89 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3)); 89 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(3));
90 FilePath db_file = profile_->GetPath().Append( 90 FilePath db_file = profile_->GetPath().Append(
91 chrome::kExtensionActivityLogFilename); 91 chrome::kExtensionActivityLogFilename);
92 sql::Connection db; 92 sql::Connection db;
93 ASSERT_TRUE(db.Open(db_file)); 93 ASSERT_TRUE(db.Open(db_file));
94 std::string sql_str = "SELECT * FROM " + 94 std::string sql_str = "SELECT * FROM " +
95 std::string(APIAction::kTableName); 95 std::string(APIAction::kTableName);
96 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); 96 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
97 ASSERT_TRUE(statement.Step()); 97 ASSERT_TRUE(statement.Step());
98 ASSERT_EQ("UNKNOWN_ACTION", statement.ColumnString(2)); 98 ASSERT_EQ("CALL", statement.ColumnString(2));
99 ASSERT_EQ("TABS", statement.ColumnString(3)); 99 ASSERT_EQ("UNKNOWN_VERB", statement.ColumnString(3));
100 ASSERT_EQ("tabs.testMethod()", statement.ColumnString(4)); 100 ASSERT_EQ("TABS", statement.ColumnString(4));
101 ASSERT_EQ("tabs.testMethod()", statement.ColumnString(5));
101 } 102 }
102 103
103 } // namespace extensions 104 } // namespace extensions
104 105
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log.cc ('k') | chrome/browser/extensions/api/web_request/web_request_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698