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 |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 StartTrackingDataUse(kTabID1, kTestLabel1); | 913 StartTrackingDataUse(kTabID1, kTestLabel1); |
914 EXPECT_TRUE(IsTrackingDataUse(kTabID1)); | 914 EXPECT_TRUE(IsTrackingDataUse(kTabID1)); |
915 EXPECT_TRUE(data_use_tab_model_->data_use_matcher_->HasValidRules()); | 915 EXPECT_TRUE(data_use_tab_model_->data_use_matcher_->HasValidRules()); |
916 | 916 |
917 data_use_tab_model_->OnControlAppInstallStateChange(false); | 917 data_use_tab_model_->OnControlAppInstallStateChange(false); |
918 | 918 |
919 EXPECT_FALSE(IsTrackingDataUse(kTabID1)); | 919 EXPECT_FALSE(IsTrackingDataUse(kTabID1)); |
920 EXPECT_FALSE(data_use_tab_model_->data_use_matcher_->HasValidRules()); | 920 EXPECT_FALSE(data_use_tab_model_->data_use_matcher_->HasValidRules()); |
921 } | 921 } |
922 | 922 |
| 923 // Tests that UI navigation events are buffered until matching rules are fetched |
| 924 // and then processed to start data use tracking. |
| 925 TEST_F(DataUseTabModelTest, ProcessBufferedNavigationEventsAfterRuleFetch) { |
| 926 MockTabDataUseObserver mock_observer; |
| 927 std::vector<std::string> app_package_names, domain_regexes, labels; |
| 928 |
| 929 app_package_names.push_back(kPackageFoo); |
| 930 domain_regexes.push_back(kURLFoo); |
| 931 labels.push_back(kTestLabel1); |
| 932 data_use_tab_model_->AddObserver(&mock_observer); |
| 933 |
| 934 // Navigation event should get buffered, and tracking should not start. |
| 935 EXPECT_CALL(mock_observer, NotifyTrackingStarting(kTabID1)).Times(0); |
| 936 EXPECT_CALL(mock_observer, NotifyTrackingEnding(kTabID1)).Times(0); |
| 937 data_use_tab_model_->OnNavigationEvent( |
| 938 kTabID1, DataUseTabModel::TRANSITION_OMNIBOX_SEARCH, GURL(kURLFoo), |
| 939 std::string()); |
| 940 EXPECT_EQ(1U, data_use_tab_model_->data_use_ui_navigations_->size()); |
| 941 testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 942 |
| 943 // Once matching rules are fetched, data use tracking should start. |
| 944 EXPECT_CALL(mock_observer, NotifyTrackingStarting(kTabID1)).Times(1); |
| 945 EXPECT_CALL(mock_observer, NotifyTrackingEnding(kTabID1)).Times(0); |
| 946 RegisterURLRegexes(app_package_names, domain_regexes, labels); |
| 947 EXPECT_FALSE(data_use_tab_model_->data_use_ui_navigations_.get()); |
| 948 testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 949 |
| 950 // Data use tracking should end. |
| 951 EXPECT_CALL(mock_observer, NotifyTrackingStarting(kTabID1)).Times(0); |
| 952 EXPECT_CALL(mock_observer, NotifyTrackingEnding(kTabID1)).Times(1); |
| 953 data_use_tab_model_->OnNavigationEvent(kTabID1, |
| 954 DataUseTabModel::TRANSITION_BOOKMARK, |
| 955 GURL(std::string()), std::string()); |
| 956 EXPECT_FALSE(data_use_tab_model_->data_use_ui_navigations_.get()); |
| 957 } |
| 958 |
923 } // namespace android | 959 } // namespace android |
924 | 960 |
925 } // namespace chrome | 961 } // namespace chrome |
OLD | NEW |