OLD | NEW |
---|---|
(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 "chrome/browser/extensions/activity_log.h" | |
8 #include "chrome/browser/extensions/extension_service.h" | |
9 #include "chrome/browser/extensions/test_extension_system.h" | |
10 #include "chrome/common/chrome_constants.h" | |
11 #include "chrome/common/extensions/extension_builder.h" | |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
13 #include "chrome/test/base/testing_profile.h" | |
14 #include "content/public/browser/browser_thread.h" | |
15 #include "content/public/test/test_browser_thread.h" | |
16 #include "sql/statement.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
19 namespace extensions { | |
20 namespace { | |
Eric Dingle
2012/12/13 20:37:34
No need for the anonymous namespace.
felt
2012/12/15 02:51:52
Done.
| |
21 | |
22 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | |
23 public: | |
24 ActivityLogTest() | |
25 : ui_thread_(BrowserThread::UI, MessageLoop::current()), | |
26 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} | |
27 | |
28 virtual void SetUp() OVERRIDE { | |
29 ChromeRenderViewHostTestHarness::SetUp(); | |
30 CommandLine command_line(CommandLine::NO_PROGRAM); | |
31 profile_ = | |
32 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
33 extension_service_ = static_cast<TestExtensionSystem*>( | |
34 ExtensionSystem::Get(profile_))->CreateExtensionService( | |
35 &command_line, FilePath(), false); | |
36 } | |
37 | |
38 protected: | |
39 ExtensionService* extension_service_; | |
40 Profile* profile_; | |
41 | |
42 private: | |
43 content::TestBrowserThread ui_thread_; | |
Eric Dingle
2012/12/13 20:37:34
I haven't written tests with the TestBrowserThread
felt
2012/12/15 02:51:52
Yes, it seems like they're needed by ChromeRenderV
| |
44 content::TestBrowserThread file_thread_; | |
45 }; | |
46 | |
47 TEST_F(ActivityLogTest, ConstructAndLog) { | |
48 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); | |
49 scoped_refptr<const Extension> extension = | |
50 ExtensionBuilder() | |
51 .SetManifest(DictionaryBuilder() | |
52 .Set("name", "Test extension") | |
53 .Set("version", "1.0.0") | |
54 .Set("manifest_version", 2)) | |
55 .Build(); | |
56 extension_service_->AddExtension(extension); | |
57 ListValue args; | |
58 for (int i = 0; i < 30; i++) { | |
59 // Run this a bunch of times and hope that if something goes wrong with | |
60 // threading, 30 times is enough to cause it to fail. | |
61 activity_log->LogManagerAction(extension, | |
62 std::string("tabs.testMethod"), | |
63 args); | |
64 } | |
65 // Need to ensure the writes were completed. | |
66 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2)); | |
67 FilePath db_file = profile_->GetPath().Append(chrome::kActivityLogFilename); | |
68 sql::Connection db; | |
69 ASSERT_TRUE(db.Open(db_file)); | |
70 std::string sql_str = "SELECT * FROM " + std::string(manager_table_name_); | |
71 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); | |
72 ASSERT_TRUE(statement.Step()); | |
73 ASSERT_EQ("UNKNOWN_ACTION", statement.ColumnString(2)); | |
74 ASSERT_EQ("TABS", statement.ColumnString(3)); | |
75 ASSERT_EQ("tabs.testMethod()", statement.ColumnString(4)); | |
76 } | |
77 | |
78 } // namespace | |
79 } // namespace extensions | |
80 | |
OLD | NEW |