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

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

Issue 1417353006: Tests: Simplify SequencedWorkerPoolOwner, call Shutdown on destructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adjust formatting and rebase Created 5 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
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 "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/sequenced_worker_pool_owner.h"
11 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/rlz/rlz_tracker_delegate.h" 14 #include "components/rlz/rlz_tracker_delegate.h"
15 #include "net/url_request/url_request_test_util.h" 15 #include "net/url_request/url_request_test_util.h"
16 #include "rlz/test/rlz_test_helpers.h" 16 #include "rlz/test/rlz_test_helpers.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 #if defined(OS_IOS) 19 #if defined(OS_IOS)
20 #include "ui/base/device_form_factor.h" 20 #include "ui/base/device_form_factor.h"
21 #endif 21 #endif
22 22
23 using testing::AssertionResult; 23 using testing::AssertionResult;
24 using testing::AssertionSuccess; 24 using testing::AssertionSuccess;
25 using testing::AssertionFailure; 25 using testing::AssertionFailure;
26 26
27 namespace rlz { 27 namespace rlz {
28 namespace { 28 namespace {
29 29
30 class TestRLZTrackerDelegate : public RLZTrackerDelegate { 30 class TestRLZTrackerDelegate : public RLZTrackerDelegate {
31 public: 31 public:
32 TestRLZTrackerDelegate() 32 TestRLZTrackerDelegate()
33 : worker_pool_(new base::SequencedWorkerPool(1, "TestRLZTracker")), 33 : worker_pool_owner_(1, "TestRLZTracker"),
34 request_context_getter_(new net::TestURLRequestContextGetter( 34 request_context_getter_(new net::TestURLRequestContextGetter(
35 base::ThreadTaskRunnerHandle::Get())) {} 35 base::ThreadTaskRunnerHandle::Get())) {}
36 36
37 ~TestRLZTrackerDelegate() override { worker_pool_->Shutdown(); }
38
39 void set_brand(const char* brand) { brand_override_ = brand; } 37 void set_brand(const char* brand) { brand_override_ = brand; }
40 38
41 void set_reactivation_brand(const char* reactivation_brand) { 39 void set_reactivation_brand(const char* reactivation_brand) {
42 // TODO(thakis): Reactivation doesn't exist on Mac yet. 40 // TODO(thakis): Reactivation doesn't exist on Mac yet.
43 reactivation_brand_override_ = reactivation_brand; 41 reactivation_brand_override_ = reactivation_brand;
44 } 42 }
45 43
46 void SimulateOmniboxUsage() { 44 void SimulateOmniboxUsage() {
47 using std::swap; 45 using std::swap;
48 base::Closure callback; 46 base::Closure callback;
(...skipping 12 matching lines...) Expand all
61 59
62 // RLZTrackerDelegate implementation. 60 // RLZTrackerDelegate implementation.
63 void Cleanup() override { 61 void Cleanup() override {
64 on_omnibox_search_callback_.Reset(); 62 on_omnibox_search_callback_.Reset();
65 on_homepage_search_callback_.Reset(); 63 on_homepage_search_callback_.Reset();
66 } 64 }
67 65
68 bool IsOnUIThread() override { return true; } 66 bool IsOnUIThread() override { return true; }
69 67
70 base::SequencedWorkerPool* GetBlockingPool() override { 68 base::SequencedWorkerPool* GetBlockingPool() override {
71 return worker_pool_.get(); 69 return worker_pool_owner_.pool().get();
72 } 70 }
73 71
74 net::URLRequestContextGetter* GetRequestContext() override { 72 net::URLRequestContextGetter* GetRequestContext() override {
75 return request_context_getter_.get(); 73 return request_context_getter_.get();
76 } 74 }
77 75
78 bool GetBrand(std::string* brand) override { 76 bool GetBrand(std::string* brand) override {
79 *brand = brand_override_; 77 *brand = brand_override_;
80 return true; 78 return true;
81 } 79 }
(...skipping 19 matching lines...) Expand all
101 DCHECK(!callback.is_null()); 99 DCHECK(!callback.is_null());
102 on_omnibox_search_callback_ = callback; 100 on_omnibox_search_callback_ = callback;
103 } 101 }
104 102
105 void SetHomepageSearchCallback(const base::Closure& callback) override { 103 void SetHomepageSearchCallback(const base::Closure& callback) override {
106 DCHECK(!callback.is_null()); 104 DCHECK(!callback.is_null());
107 on_homepage_search_callback_ = callback; 105 on_homepage_search_callback_ = callback;
108 } 106 }
109 107
110 private: 108 private:
111 scoped_refptr<base::SequencedWorkerPool> worker_pool_; 109 base::SequencedWorkerPoolOwner worker_pool_owner_;
112 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 110 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
113 111
114 std::string brand_override_; 112 std::string brand_override_;
115 std::string reactivation_brand_override_; 113 std::string reactivation_brand_override_;
116 base::Closure on_omnibox_search_callback_; 114 base::Closure on_omnibox_search_callback_;
117 base::Closure on_homepage_search_callback_; 115 base::Closure on_homepage_search_callback_;
118 116
119 DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate); 117 DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate);
120 }; 118 };
121 119
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 998
1001 ExpectEventRecorded(OmniboxFirstSearch(), true); 999 ExpectEventRecorded(OmniboxFirstSearch(), true);
1002 1000
1003 RLZTracker::ClearRlzState(); 1001 RLZTracker::ClearRlzState();
1004 1002
1005 ExpectEventRecorded(OmniboxFirstSearch(), false); 1003 ExpectEventRecorded(OmniboxFirstSearch(), false);
1006 } 1004 }
1007 #endif // defined(OS_CHROMEOS) 1005 #endif // defined(OS_CHROMEOS)
1008 1006
1009 } // namespace rlz 1007 } // namespace rlz
OLDNEW
« no previous file with comments | « components/component_updater/component_updater_service_unittest.cc ('k') | components/update_client/update_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698