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

Side by Side Diff: net/android/cellular_signal_strength_unittest.cc

Issue 2763853002: Use Android callback API to obtain cellular signal strength (Closed)
Patch Set: ryansturm comments Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "net/android/cellular_signal_strength.h" 5 #include "net/android/cellular_signal_strength.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/optional.h"
9 #include "net/base/network_change_notifier.h" 10 #include "net/base/network_change_notifier.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 namespace { 15 namespace {
15 16
16 TEST(CellularSignalStrengthAndroidTest, SignalStrengthTest) { 17 TEST(CellularSignalStrengthAndroidTest, SignalStrengthLevelTest) {
17 int signal_strength_dbm = INT32_MIN; 18 android::CellularSignalStrength cellular_signal_strength;
18 bool signal_strength_available = 19
19 android::cellular_signal_strength::GetSignalStrengthDbm( 20 base::Optional<int32_t> signal_strength =
20 &signal_strength_dbm); 21 cellular_signal_strength.GetSignalStrengthLevel();
21 22
22 // Signal strength is unavailable if the device does not have an active 23 // Signal strength is unavailable if the device does not have an active
23 // cellular connection. 24 // cellular connection.
24 if (!NetworkChangeNotifier::IsConnectionCellular( 25 if (!NetworkChangeNotifier::IsConnectionCellular(
25 NetworkChangeNotifier::GetConnectionType())) { 26 NetworkChangeNotifier::GetConnectionType())) {
27 ASSERT_FALSE(signal_strength);
26 return; 28 return;
27 } 29 }
28 30
29 EXPECT_TRUE(signal_strength_available); 31 ASSERT_TRUE(signal_strength);
30 // Signal strength (in dbM) should typically be between -130 and 0. 32 EXPECT_LE(0, signal_strength.value());
31 EXPECT_LE(-130, signal_strength_dbm); 33 EXPECT_GE(4, signal_strength.value());
32 EXPECT_GE(0, signal_strength_dbm);
33 }
34
35 TEST(CellularSignalStrengthAndroidTest, SignalStrengthLevelTest) {
36 int signal_strength_level = INT32_MIN;
37 bool signal_strength_level_available =
38 android::cellular_signal_strength::GetSignalStrengthLevel(
39 &signal_strength_level);
40
41 // Signal strength is unavailable if the device does not have an active
42 // cellular connection.
43 if (!NetworkChangeNotifier::IsConnectionCellular(
44 NetworkChangeNotifier::GetConnectionType())) {
45 return;
46 }
47
48 EXPECT_TRUE(signal_strength_level_available);
49 EXPECT_LE(0, signal_strength_level);
50 EXPECT_GE(4, signal_strength_level);
51 } 34 }
52 35
53 } // namespace 36 } // namespace
54 37
55 } // namespace net 38 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698