Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_tab_model.h" | 5 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "base/test/simple_test_tick_clock.h" | 19 #include "base/test/simple_test_tick_clock.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "chrome/browser/android/data_usage/data_use_matcher.h" | 21 #include "chrome/browser/android/data_usage/data_use_matcher.h" |
| 22 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" | |
| 22 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" | 23 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" |
| 23 #include "components/data_usage/core/data_use_aggregator.h" | 24 #include "components/data_usage/core/data_use_aggregator.h" |
| 24 #include "components/data_usage/core/data_use_amortizer.h" | 25 #include "components/data_usage/core/data_use_amortizer.h" |
| 25 #include "components/data_usage/core/data_use_annotator.h" | 26 #include "components/data_usage/core/data_use_annotator.h" |
| 26 #include "components/sessions/core/session_id.h" | 27 #include "components/sessions/core/session_id.h" |
| 27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 // Mock observer to track the calls to start and end tracking events. | 63 // Mock observer to track the calls to start and end tracking events. |
| 63 class MockTabDataUseObserver | 64 class MockTabDataUseObserver |
| 64 : public chrome::android::DataUseTabModel::TabDataUseObserver { | 65 : public chrome::android::DataUseTabModel::TabDataUseObserver { |
| 65 public: | 66 public: |
| 66 MOCK_METHOD1(NotifyTrackingStarting, void(SessionID::id_type tab_id)); | 67 MOCK_METHOD1(NotifyTrackingStarting, void(SessionID::id_type tab_id)); |
| 67 MOCK_METHOD1(NotifyTrackingEnding, void(SessionID::id_type tab_id)); | 68 MOCK_METHOD1(NotifyTrackingEnding, void(SessionID::id_type tab_id)); |
| 68 }; | 69 }; |
| 69 | 70 |
| 71 class TestExternalDataUseObserverBridge | |
| 72 : public chrome::android::ExternalDataUseObserverBridge { | |
| 73 public: | |
| 74 TestExternalDataUseObserverBridge() {} | |
| 75 void FetchMatchingRules() const override {} | |
| 76 void ShouldRegisterAsDataUseObserver(bool should_register) const override{}; | |
| 77 }; | |
| 78 | |
| 70 } // namespace | 79 } // namespace |
| 71 | 80 |
| 72 namespace chrome { | 81 namespace chrome { |
| 73 | 82 |
| 74 namespace android { | 83 namespace android { |
| 75 | 84 |
| 76 class ExternalDataUseObserver; | |
| 77 | |
| 78 class DataUseTabModelTest : public testing::Test { | 85 class DataUseTabModelTest : public testing::Test { |
| 79 public: | 86 public: |
| 80 DataUseTabModelTest() | 87 DataUseTabModelTest() |
| 81 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 88 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 82 | 89 |
| 83 protected: | 90 protected: |
| 84 void SetUp() override { | 91 void SetUp() override { |
| 85 base::RunLoop().RunUntilIdle(); | 92 base::RunLoop().RunUntilIdle(); |
| 86 data_use_tab_model_.reset(new DataUseTabModel()); | 93 data_use_tab_model_.reset(new DataUseTabModel()); |
| 87 data_use_tab_model_->InitOnUIThread( | 94 data_use_tab_model_->InitOnUIThread( |
| 88 content::BrowserThread::GetMessageLoopProxyForThread( | 95 new TestExternalDataUseObserverBridge()); |
|
tbansal1
2016/03/08 18:15:01
Would this not cause memory leak in the test? It s
Raj
2016/03/09 02:27:36
Done.
| |
| 89 content::BrowserThread::IO), | |
| 90 base::WeakPtr<ExternalDataUseObserver>()); | |
| 91 | 96 |
| 92 tick_clock_ = new base::SimpleTestTickClock(); | 97 tick_clock_ = new base::SimpleTestTickClock(); |
| 93 | 98 |
| 94 // Advance to non nil time. | 99 // Advance to non nil time. |
| 95 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); | 100 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); |
| 96 | 101 |
| 97 // |tick_clock_| will be owned by |data_use_tab_model_|. | 102 // |tick_clock_| will be owned by |data_use_tab_model_|. |
| 98 data_use_tab_model_->tick_clock_.reset(tick_clock_); | 103 data_use_tab_model_->tick_clock_.reset(tick_clock_); |
| 99 data_use_tab_model_->OnControlAppInstallStateChange(true); | 104 data_use_tab_model_->OnControlAppInstallStateChange(true); |
| 100 } | 105 } |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 | 913 |
| 909 data_use_tab_model_->OnControlAppInstallStateChange(false); | 914 data_use_tab_model_->OnControlAppInstallStateChange(false); |
| 910 | 915 |
| 911 EXPECT_FALSE(IsTrackingDataUse(kTabID1)); | 916 EXPECT_FALSE(IsTrackingDataUse(kTabID1)); |
| 912 EXPECT_FALSE(data_use_tab_model_->data_use_matcher_->HasValidRules()); | 917 EXPECT_FALSE(data_use_tab_model_->data_use_matcher_->HasValidRules()); |
| 913 } | 918 } |
| 914 | 919 |
| 915 } // namespace android | 920 } // namespace android |
| 916 | 921 |
| 917 } // namespace chrome | 922 } // namespace chrome |
| OLD | NEW |