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

Side by Side Diff: chrome/browser/android/data_usage/data_use_ui_tab_model_unittest.cc

Issue 2158913002: Make DataUseTabModel and DataUseMatcher more independent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fix Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/android/data_usage/data_use_ui_tab_model.h" 5 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind_helpers.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "chrome/browser/android/data_usage/data_use_tab_model.h" 18 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
18 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h" 19 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h"
19 #include "chrome/browser/android/data_usage/external_data_use_observer.h" 20 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sessions/session_tab_helper.h" 22 #include "chrome/browser/sessions/session_tab_helper.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "components/data_usage/core/data_use_aggregator.h" 24 #include "components/data_usage/core/data_use_aggregator.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Mock observer to track the calls to start and end tracking events. 60 // Mock observer to track the calls to start and end tracking events.
60 class MockTabDataUseObserver : public DataUseTabModel::TabDataUseObserver { 61 class MockTabDataUseObserver : public DataUseTabModel::TabDataUseObserver {
61 public: 62 public:
62 MOCK_METHOD1(NotifyTrackingStarting, void(SessionID::id_type tab_id)); 63 MOCK_METHOD1(NotifyTrackingStarting, void(SessionID::id_type tab_id));
63 MOCK_METHOD1(NotifyTrackingEnding, void(SessionID::id_type tab_id)); 64 MOCK_METHOD1(NotifyTrackingEnding, void(SessionID::id_type tab_id));
64 MOCK_METHOD0(OnDataUseTabModelReady, void()); 65 MOCK_METHOD0(OnDataUseTabModelReady, void());
65 }; 66 };
66 67
67 class TestDataUseTabModel : public DataUseTabModel { 68 class TestDataUseTabModel : public DataUseTabModel {
68 public: 69 public:
69 TestDataUseTabModel() {} 70 TestDataUseTabModel()
71 : DataUseTabModel(base::Bind(&TestDataUseTabModel::FetchMatchingRules,
72 base::Unretained(this)),
73 base::Bind(&TestDataUseTabModel::OnMatchingRulesFetched,
74 base::Unretained(this))) {}
70 ~TestDataUseTabModel() override {} 75 ~TestDataUseTabModel() override {}
71 76
77 void FetchMatchingRules() {}
78
79 void OnMatchingRulesFetched(bool is_valid) {}
80
72 using DataUseTabModel::NotifyObserversOfTrackingStarting; 81 using DataUseTabModel::NotifyObserversOfTrackingStarting;
73 using DataUseTabModel::NotifyObserversOfTrackingEnding; 82 using DataUseTabModel::NotifyObserversOfTrackingEnding;
74 }; 83 };
75 84
76 class DataUseUITabModelTest : public testing::Test { 85 class DataUseUITabModelTest : public testing::Test {
77 public: 86 public:
78 DataUseUITabModelTest() 87 DataUseUITabModelTest()
79 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} 88 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
80 DataUseUITabModel* data_use_ui_tab_model() { return &data_use_ui_tab_model_; } 89 DataUseUITabModel* data_use_ui_tab_model() { return &data_use_ui_tab_model_; }
81 90
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 122
114 data_use_aggregator_.reset( 123 data_use_aggregator_.reset(
115 new data_usage::DataUseAggregator(nullptr, nullptr)); 124 new data_usage::DataUseAggregator(nullptr, nullptr));
116 125
117 external_data_use_observer_.reset(new ExternalDataUseObserver( 126 external_data_use_observer_.reset(new ExternalDataUseObserver(
118 data_use_aggregator_.get(), io_task_runner_, ui_task_runner_)); 127 data_use_aggregator_.get(), io_task_runner_, ui_task_runner_));
119 // Wait for |external_data_use_observer_| to create the Java object. 128 // Wait for |external_data_use_observer_| to create the Java object.
120 base::RunLoop().RunUntilIdle(); 129 base::RunLoop().RunUntilIdle();
121 130
122 data_use_tab_model_.reset(new TestDataUseTabModel()); 131 data_use_tab_model_.reset(new TestDataUseTabModel());
123 data_use_tab_model_->InitOnUIThread(
124 external_data_use_observer_->external_data_use_observer_bridge_);
125 } 132 }
126 133
127 void SetUpDataUseUITabModel() { 134 void SetUpDataUseUITabModel() {
128 data_use_ui_tab_model_.SetDataUseTabModel(data_use_tab_model_.get()); 135 data_use_ui_tab_model_.SetDataUseTabModel(data_use_tab_model_.get());
129 data_use_tab_model_->OnControlAppInstallStateChange(true); 136 data_use_tab_model_->OnControlAppInstallStateChange(true);
130 } 137 }
131 138
132 private: 139 private:
133 content::TestBrowserThreadBundle thread_bundle_; 140 content::TestBrowserThreadBundle thread_bundle_;
134 DataUseUITabModel data_use_ui_tab_model_; 141 DataUseUITabModel data_use_ui_tab_model_;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 base::RunLoop().RunUntilIdle(); 608 base::RunLoop().RunUntilIdle();
602 RegisterURLRegexes(std::vector<std::string>(url_regexes.size(), kFooPackage), 609 RegisterURLRegexes(std::vector<std::string>(url_regexes.size(), kFooPackage),
603 url_regexes, 610 url_regexes,
604 std::vector<std::string>(url_regexes.size(), kFooLabel)); 611 std::vector<std::string>(url_regexes.size(), kFooLabel));
605 base::RunLoop().RunUntilIdle(); 612 base::RunLoop().RunUntilIdle();
606 } 613 }
607 614
608 } // namespace android 615 } // namespace android
609 616
610 } // namespace chrome 617 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698