OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/test/simple_test_clock.h" | 15 #include "base/test/simple_test_clock.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 19 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
19 #include "chrome/browser/extensions/activity_log/activity_database.h" | 20 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 21 #include "chrome/browser/extensions/activity_log/activity_log_task_runner.h" |
20 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" | 22 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/test_extension_system.h" | 24 #include "chrome/browser/extensions/test_extension_system.h" |
23 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
26 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
27 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
29 #include "extensions/common/dom_action_types.h" | 31 #include "extensions/common/dom_action_types.h" |
30 #include "sql/statement.h" | 32 #include "sql/statement.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
32 | 34 |
33 using content::BrowserThread; | |
34 | |
35 namespace constants = activity_log_constants; | 35 namespace constants = activity_log_constants; |
36 | 36 |
37 namespace extensions { | 37 namespace extensions { |
38 | 38 |
39 // A dummy implementation of ActivityDatabase::Delegate, sufficient for | 39 // A dummy implementation of ActivityDatabase::Delegate, sufficient for |
40 // the unit tests. | 40 // the unit tests. |
41 class ActivityDatabaseTestPolicy : public ActivityDatabase::Delegate { | 41 class ActivityDatabaseTestPolicy : public ActivityDatabase::Delegate { |
42 public: | 42 public: |
43 ActivityDatabaseTestPolicy() {} | 43 ActivityDatabaseTestPolicy() {} |
44 | 44 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, | 98 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, |
99 scoped_refptr<Action> action) { | 99 scoped_refptr<Action> action) { |
100 queue_.push_back(action); | 100 queue_.push_back(action); |
101 db->AdviseFlush(queue_.size()); | 101 db->AdviseFlush(queue_.size()); |
102 } | 102 } |
103 | 103 |
104 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { | 104 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { |
105 protected: | 105 protected: |
106 void SetUp() override { | 106 void SetUp() override { |
107 ChromeRenderViewHostTestHarness::SetUp(); | 107 ChromeRenderViewHostTestHarness::SetUp(); |
| 108 SetActivityLogTaskRunnerForTesting( |
| 109 base::ThreadTaskRunnerHandle::Get().get()); |
108 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 110 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
109 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 111 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
110 switches::kEnableExtensionActivityLogTesting); | 112 switches::kEnableExtensionActivityLogTesting); |
111 } | 113 } |
112 | 114 |
113 void TearDown() override { | 115 void TearDown() override { |
| 116 SetActivityLogTaskRunnerForTesting(nullptr); |
114 ChromeRenderViewHostTestHarness::TearDown(); | 117 ChromeRenderViewHostTestHarness::TearDown(); |
115 } | 118 } |
116 | 119 |
117 // Creates a test database and initializes the table schema. | 120 // Creates a test database and initializes the table schema. |
118 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { | 121 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { |
119 db_delegate_ = new ActivityDatabaseTestPolicy(); | 122 db_delegate_ = new ActivityDatabaseTestPolicy(); |
120 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); | 123 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); |
121 activity_db->Init(db_file); | 124 activity_db->Init(db_file); |
122 CHECK(activity_db->is_db_valid()); | 125 CHECK(activity_db->is_db_valid()); |
123 return activity_db; | 126 return activity_db; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); | 264 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); |
262 ActivityDatabase* activity_db = new ActivityDatabase(delegate); | 265 ActivityDatabase* activity_db = new ActivityDatabase(delegate); |
263 scoped_refptr<Action> action = new Action( | 266 scoped_refptr<Action> action = new Action( |
264 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); | 267 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); |
265 action->mutable_args()->AppendString("woof"); | 268 action->mutable_args()->AppendString("woof"); |
266 delegate->Record(activity_db, action); | 269 delegate->Record(activity_db, action); |
267 activity_db->Close(); | 270 activity_db->Close(); |
268 } | 271 } |
269 | 272 |
270 } // namespace extensions | 273 } // namespace extensions |
OLD | NEW |