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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop_unittest.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gcm_driver/gcm_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include <stdint.h>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
10 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h"
11 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
12 #include "base/prefs/pref_registry_simple.h" 15 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/testing_pref_service.h" 16 #include "base/prefs/testing_pref_service.h"
14 #include "base/run_loop.h" 17 #include "base/run_loop.h"
15 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
16 #include "base/test/test_simple_task_runner.h" 19 #include "base/test/test_simple_task_runner.h"
17 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
18 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
19 #include "components/gcm_driver/fake_gcm_app_handler.h" 22 #include "components/gcm_driver/fake_gcm_app_handler.h"
20 #include "components/gcm_driver/fake_gcm_client.h" 23 #include "components/gcm_driver/fake_gcm_client.h"
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // Tests a single instance of GCMDriver. 835 // Tests a single instance of GCMDriver.
833 class GCMChannelStatusSyncerTest : public GCMDriverTest { 836 class GCMChannelStatusSyncerTest : public GCMDriverTest {
834 public: 837 public:
835 GCMChannelStatusSyncerTest(); 838 GCMChannelStatusSyncerTest();
836 ~GCMChannelStatusSyncerTest() override; 839 ~GCMChannelStatusSyncerTest() override;
837 840
838 // testing::Test: 841 // testing::Test:
839 void SetUp() override; 842 void SetUp() override;
840 843
841 void CompleteGCMChannelStatusRequest(bool enabled, int poll_interval_seconds); 844 void CompleteGCMChannelStatusRequest(bool enabled, int poll_interval_seconds);
842 bool CompareDelaySeconds(int64 expected_delay_seconds, 845 bool CompareDelaySeconds(int64_t expected_delay_seconds,
843 int64 actual_delay_seconds); 846 int64_t actual_delay_seconds);
844 847
845 GCMChannelStatusSyncer* syncer() { 848 GCMChannelStatusSyncer* syncer() {
846 return driver()->gcm_channel_status_syncer_for_testing(); 849 return driver()->gcm_channel_status_syncer_for_testing();
847 } 850 }
848 851
849 private: 852 private:
850 net::TestURLFetcherFactory url_fetcher_factory_; 853 net::TestURLFetcherFactory url_fetcher_factory_;
851 854
852 DISALLOW_COPY_AND_ASSIGN(GCMChannelStatusSyncerTest); 855 DISALLOW_COPY_AND_ASSIGN(GCMChannelStatusSyncerTest);
853 }; 856 };
(...skipping 27 matching lines...) Expand all
881 response_proto.SerializeToString(&response_string); 884 response_proto.SerializeToString(&response_string);
882 885
883 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 886 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
884 ASSERT_TRUE(fetcher); 887 ASSERT_TRUE(fetcher);
885 fetcher->set_response_code(net::HTTP_OK); 888 fetcher->set_response_code(net::HTTP_OK);
886 fetcher->SetResponseString(response_string); 889 fetcher->SetResponseString(response_string);
887 fetcher->delegate()->OnURLFetchComplete(fetcher); 890 fetcher->delegate()->OnURLFetchComplete(fetcher);
888 } 891 }
889 892
890 bool GCMChannelStatusSyncerTest::CompareDelaySeconds( 893 bool GCMChannelStatusSyncerTest::CompareDelaySeconds(
891 int64 expected_delay_seconds, int64 actual_delay_seconds) { 894 int64_t expected_delay_seconds,
895 int64_t actual_delay_seconds) {
892 // Most of time, the actual delay should not be smaller than the expected 896 // Most of time, the actual delay should not be smaller than the expected
893 // delay. 897 // delay.
894 if (actual_delay_seconds >= expected_delay_seconds) 898 if (actual_delay_seconds >= expected_delay_seconds)
895 return true; 899 return true;
896 // It is also OK that the actual delay is a bit smaller than the expected 900 // It is also OK that the actual delay is a bit smaller than the expected
897 // delay in case that the test runs slowly. 901 // delay in case that the test runs slowly.
898 return expected_delay_seconds - actual_delay_seconds < 30; 902 return expected_delay_seconds - actual_delay_seconds < 30;
899 } 903 }
900 904
901 TEST_F(GCMChannelStatusSyncerTest, DisableAndEnable) { 905 TEST_F(GCMChannelStatusSyncerTest, DisableAndEnable) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 // Wait until the GCM channel status request gets triggered. 1003 // Wait until the GCM channel status request gets triggered.
1000 PumpUILoop(); 1004 PumpUILoop();
1001 1005
1002 // Keep delay such that we can find out the computed delay time. 1006 // Keep delay such that we can find out the computed delay time.
1003 syncer()->set_delay_removed_for_testing(false); 1007 syncer()->set_delay_removed_for_testing(false);
1004 1008
1005 // Complete the request. The default interval is intact. 1009 // Complete the request. The default interval is intact.
1006 CompleteGCMChannelStatusRequest(true, 0); 1010 CompleteGCMChannelStatusRequest(true, 0);
1007 1011
1008 // The next request should be scheduled at the expected default interval. 1012 // The next request should be scheduled at the expected default interval.
1009 int64 actual_delay_seconds = 1013 int64_t actual_delay_seconds =
1010 syncer()->current_request_delay_interval().InSeconds(); 1014 syncer()->current_request_delay_interval().InSeconds();
1011 int64 expected_delay_seconds = 1015 int64_t expected_delay_seconds =
1012 GCMChannelStatusRequest::default_poll_interval_seconds(); 1016 GCMChannelStatusRequest::default_poll_interval_seconds();
1013 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) 1017 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1014 << "expected delay: " << expected_delay_seconds 1018 << "expected delay: " << expected_delay_seconds
1015 << " actual delay: " << actual_delay_seconds; 1019 << " actual delay: " << actual_delay_seconds;
1016 1020
1017 // Simulate browser start by recreating GCMDriver. 1021 // Simulate browser start by recreating GCMDriver.
1018 ShutdownDriver(); 1022 ShutdownDriver();
1019 CreateDriver(); 1023 CreateDriver();
1020 AddAppHandlers(); 1024 AddAppHandlers();
1021 1025
(...skipping 21 matching lines...) Expand all
1043 1047
1044 // Keep delay such that we can find out the computed delay time. 1048 // Keep delay such that we can find out the computed delay time.
1045 syncer()->set_delay_removed_for_testing(false); 1049 syncer()->set_delay_removed_for_testing(false);
1046 1050
1047 // Complete the request. The interval is being changed. 1051 // Complete the request. The interval is being changed.
1048 int new_poll_interval_seconds = 1052 int new_poll_interval_seconds =
1049 GCMChannelStatusRequest::default_poll_interval_seconds() * 2; 1053 GCMChannelStatusRequest::default_poll_interval_seconds() * 2;
1050 CompleteGCMChannelStatusRequest(true, new_poll_interval_seconds); 1054 CompleteGCMChannelStatusRequest(true, new_poll_interval_seconds);
1051 1055
1052 // The next request should be scheduled at the expected updated interval. 1056 // The next request should be scheduled at the expected updated interval.
1053 int64 actual_delay_seconds = 1057 int64_t actual_delay_seconds =
1054 syncer()->current_request_delay_interval().InSeconds(); 1058 syncer()->current_request_delay_interval().InSeconds();
1055 int64 expected_delay_seconds = new_poll_interval_seconds; 1059 int64_t expected_delay_seconds = new_poll_interval_seconds;
1056 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) 1060 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1057 << "expected delay: " << expected_delay_seconds 1061 << "expected delay: " << expected_delay_seconds
1058 << " actual delay: " << actual_delay_seconds; 1062 << " actual delay: " << actual_delay_seconds;
1059 1063
1060 // Simulate browser start by recreating GCMDriver. 1064 // Simulate browser start by recreating GCMDriver.
1061 ShutdownDriver(); 1065 ShutdownDriver();
1062 CreateDriver(); 1066 CreateDriver();
1063 AddAppHandlers(); 1067 AddAppHandlers();
1064 1068
1065 // After start-up, the request should still be scheduled at the expected 1069 // After start-up, the request should still be scheduled at the expected
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 PumpUILoop(); 1287 PumpUILoop();
1284 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); 1288 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result());
1285 1289
1286 // DeleteToken operation will be invoked after GCMClient becomes ready. 1290 // DeleteToken operation will be invoked after GCMClient becomes ready.
1287 GetGCMClient()->PerformDelayedStart(); 1291 GetGCMClient()->PerformDelayedStart();
1288 WaitForAsyncOperation(); 1292 WaitForAsyncOperation();
1289 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); 1293 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
1290 } 1294 }
1291 1295
1292 } // namespace gcm 1296 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | components/gcm_driver/gcm_profile_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698