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

Side by Side Diff: components/rlz/rlz_tracker_unittest.cc

Issue 2949263003: Remove call to GetBlockingPool in RLZ (Closed)
Patch Set: Use PostDelayedTaskWithTraits Created 3 years, 4 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 "components/rlz/rlz_tracker.h" 5 #include "components/rlz/rlz_tracker.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/sequenced_worker_pool_owner.h" 14 #include "base/test/scoped_task_environment.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "components/rlz/rlz_tracker_delegate.h" 18 #include "components/rlz/rlz_tracker_delegate.h"
19 #include "net/url_request/url_request_test_util.h" 19 #include "net/url_request/url_request_test_util.h"
20 #include "rlz/test/rlz_test_helpers.h" 20 #include "rlz/test/rlz_test_helpers.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 #if defined(OS_IOS) 23 #if defined(OS_IOS)
24 #include "ui/base/device_form_factor.h" 24 #include "ui/base/device_form_factor.h"
25 #endif 25 #endif
26 26
27 using testing::AssertionResult; 27 using testing::AssertionResult;
28 using testing::AssertionSuccess; 28 using testing::AssertionSuccess;
29 using testing::AssertionFailure; 29 using testing::AssertionFailure;
30 30
31 namespace rlz { 31 namespace rlz {
32 namespace { 32 namespace {
33 33
34 class TestRLZTrackerDelegate : public RLZTrackerDelegate { 34 class TestRLZTrackerDelegate : public RLZTrackerDelegate {
35 public: 35 public:
36 TestRLZTrackerDelegate() 36 TestRLZTrackerDelegate()
37 : worker_pool_owner_(2, "TestRLZTracker"), 37 : request_context_getter_(new net::TestURLRequestContextGetter(
38 request_context_getter_(new net::TestURLRequestContextGetter(
39 base::ThreadTaskRunnerHandle::Get())) {} 38 base::ThreadTaskRunnerHandle::Get())) {}
40 39
41 void set_brand(const char* brand) { brand_override_ = brand; } 40 void set_brand(const char* brand) { brand_override_ = brand; }
42 41
43 void set_reactivation_brand(const char* reactivation_brand) { 42 void set_reactivation_brand(const char* reactivation_brand) {
44 // TODO(thakis): Reactivation doesn't exist on Mac yet. 43 // TODO(thakis): Reactivation doesn't exist on Mac yet.
45 reactivation_brand_override_ = reactivation_brand; 44 reactivation_brand_override_ = reactivation_brand;
46 } 45 }
47 46
48 void SimulateOmniboxUsage() { 47 void SimulateOmniboxUsage() {
(...skipping 13 matching lines...) Expand all
62 } 61 }
63 62
64 // RLZTrackerDelegate implementation. 63 // RLZTrackerDelegate implementation.
65 void Cleanup() override { 64 void Cleanup() override {
66 on_omnibox_search_callback_.Reset(); 65 on_omnibox_search_callback_.Reset();
67 on_homepage_search_callback_.Reset(); 66 on_homepage_search_callback_.Reset();
68 } 67 }
69 68
70 bool IsOnUIThread() override { return true; } 69 bool IsOnUIThread() override { return true; }
71 70
72 base::SequencedWorkerPool* GetBlockingPool() override {
73 return worker_pool_owner_.pool().get();
74 }
75
76 net::URLRequestContextGetter* GetRequestContext() override { 71 net::URLRequestContextGetter* GetRequestContext() override {
77 return request_context_getter_.get(); 72 return request_context_getter_.get();
78 } 73 }
79 74
80 bool GetBrand(std::string* brand) override { 75 bool GetBrand(std::string* brand) override {
81 *brand = brand_override_; 76 *brand = brand_override_;
82 return true; 77 return true;
83 } 78 }
84 79
85 bool IsBrandOrganic(const std::string& brand) override { 80 bool IsBrandOrganic(const std::string& brand) override {
(...skipping 17 matching lines...) Expand all
103 DCHECK(!callback.is_null()); 98 DCHECK(!callback.is_null());
104 on_omnibox_search_callback_ = callback; 99 on_omnibox_search_callback_ = callback;
105 } 100 }
106 101
107 void SetHomepageSearchCallback(const base::Closure& callback) override { 102 void SetHomepageSearchCallback(const base::Closure& callback) override {
108 DCHECK(!callback.is_null()); 103 DCHECK(!callback.is_null());
109 on_homepage_search_callback_ = callback; 104 on_homepage_search_callback_ = callback;
110 } 105 }
111 106
112 private: 107 private:
113 base::SequencedWorkerPoolOwner worker_pool_owner_;
114 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 108 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
115 109
116 std::string brand_override_; 110 std::string brand_override_;
117 std::string reactivation_brand_override_; 111 std::string reactivation_brand_override_;
118 base::Closure on_omnibox_search_callback_; 112 base::Closure on_omnibox_search_callback_;
119 base::Closure on_homepage_search_callback_; 113 base::Closure on_homepage_search_callback_;
120 114
121 DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate); 115 DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate);
122 }; 116 };
123 117
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 244
251 void SimulateOmniboxUsage(); 245 void SimulateOmniboxUsage();
252 void SimulateHomepageUsage(); 246 void SimulateHomepageUsage();
253 void SimulateAppListUsage(); 247 void SimulateAppListUsage();
254 void InvokeDelayedInit(); 248 void InvokeDelayedInit();
255 249
256 void ExpectEventRecorded(const char* event_name, bool expected); 250 void ExpectEventRecorded(const char* event_name, bool expected);
257 void ExpectRlzPingSent(bool expected); 251 void ExpectRlzPingSent(bool expected);
258 void ExpectReactivationRlzPingSent(bool expected); 252 void ExpectReactivationRlzPingSent(bool expected);
259 253
260 base::MessageLoop message_loop_; 254 base::test::ScopedTaskEnvironment scoped_task_environment_;
261 TestRLZTrackerDelegate* delegate_; 255 TestRLZTrackerDelegate* delegate_;
262 std::unique_ptr<TestRLZTracker> tracker_; 256 std::unique_ptr<TestRLZTracker> tracker_;
263 RlzLibTestNoMachineStateHelper m_rlz_test_helper_; 257 RlzLibTestNoMachineStateHelper m_rlz_test_helper_;
264 }; 258 };
265 259
266 void RlzLibTest::SetUp() { 260 void RlzLibTest::SetUp() {
267 testing::Test::SetUp(); 261 testing::Test::SetUp();
268 m_rlz_test_helper_.SetUp(); 262 m_rlz_test_helper_.SetUp();
269 263
270 delegate_ = new TestRLZTrackerDelegate; 264 delegate_ = new TestRLZTrackerDelegate;
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 996
1003 ExpectEventRecorded(OmniboxFirstSearch(), true); 997 ExpectEventRecorded(OmniboxFirstSearch(), true);
1004 998
1005 RLZTracker::ClearRlzState(); 999 RLZTracker::ClearRlzState();
1006 1000
1007 ExpectEventRecorded(OmniboxFirstSearch(), false); 1001 ExpectEventRecorded(OmniboxFirstSearch(), false);
1008 } 1002 }
1009 #endif // defined(OS_CHROMEOS) 1003 #endif // defined(OS_CHROMEOS)
1010 1004
1011 } // namespace rlz 1005 } // namespace rlz
OLDNEW
« no previous file with comments | « components/rlz/rlz_tracker_delegate.h ('k') | ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698