Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 package org.chromium.chrome.browser.omnibox.geo; | 5 package org.chromium.chrome.browser.omnibox.geo; |
| 6 | 6 |
| 7 import static org.junit.Assert.assertEquals; | 7 import static org.junit.Assert.assertEquals; |
| 8 import static org.junit.Assert.assertFalse; | 8 import static org.junit.Assert.assertFalse; |
| 9 import static org.junit.Assert.assertNotEquals; | 9 import static org.junit.Assert.assertNotEquals; |
| 10 import static org.junit.Assert.assertTrue; | 10 import static org.junit.Assert.assertTrue; |
| 11 | 11 |
| 12 import org.junit.Test; | 12 import org.junit.Test; |
| 13 import org.junit.runner.RunWith; | 13 import org.junit.runner.RunWith; |
| 14 import org.robolectric.annotation.Config; | 14 import org.robolectric.annotation.Config; |
| 15 | 15 |
| 16 import org.chromium.chrome.browser.omnibox.geo.PartnerLocationDescriptor.Visible Network.Cell; | |
| 17 import org.chromium.chrome.browser.omnibox.geo.PartnerLocationDescriptor.Visible Network.WiFi; | |
| 16 import org.chromium.chrome.browser.omnibox.geo.VisibleNetworks.VisibleCell; | 18 import org.chromium.chrome.browser.omnibox.geo.VisibleNetworks.VisibleCell; |
| 17 import org.chromium.chrome.browser.omnibox.geo.VisibleNetworks.VisibleCell.Radio Type; | 19 import org.chromium.chrome.browser.omnibox.geo.VisibleNetworks.VisibleCell.Radio Type; |
| 18 import org.chromium.chrome.browser.omnibox.geo.VisibleNetworks.VisibleWifi; | 20 import org.chromium.chrome.browser.omnibox.geo.VisibleNetworks.VisibleWifi; |
| 19 import org.chromium.testing.local.LocalRobolectricTestRunner; | 21 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 20 | 22 |
| 21 import java.util.Arrays; | 23 import java.util.Arrays; |
| 22 import java.util.HashSet; | 24 import java.util.HashSet; |
| 23 import java.util.Set; | 25 import java.util.Set; |
| 24 | 26 |
| 25 /** | 27 /** |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 114 |
| 113 @Test | 115 @Test |
| 114 public void testVisibleWifiHashDifferentLevelAndTimestamp() { | 116 public void testVisibleWifiHashDifferentLevelAndTimestamp() { |
| 115 VisibleWifi visibleWifi3 = VisibleWifi.create(SSID2, BSSID2, LEVEL1, TIM ESTAMP1); | 117 VisibleWifi visibleWifi3 = VisibleWifi.create(SSID2, BSSID2, LEVEL1, TIM ESTAMP1); |
| 116 // visibleWifi3 has the same ssid and bssid as VISIBLE_WIFI2 but differe nt level and | 118 // visibleWifi3 has the same ssid and bssid as VISIBLE_WIFI2 but differe nt level and |
| 117 // timestamp. The level and timestamp are excluded from the VisibleWifi hash function. | 119 // timestamp. The level and timestamp are excluded from the VisibleWifi hash function. |
| 118 assertEquals(VISIBLE_WIFI2.hashCode(), visibleWifi3.hashCode()); | 120 assertEquals(VISIBLE_WIFI2.hashCode(), visibleWifi3.hashCode()); |
| 119 } | 121 } |
| 120 | 122 |
| 121 @Test | 123 @Test |
| 124 public void testVisibleWifiToProto() { | |
| 125 boolean connected = true; | |
| 126 PartnerLocationDescriptor.VisibleNetwork visibleNetwork = VISIBLE_WIFI1. toProto(connected); | |
| 127 WiFi wifi = visibleNetwork.wifi; | |
| 128 | |
| 129 assertEquals(VISIBLE_WIFI1.bssid(), wifi.bssid); | |
| 130 assertEquals(VISIBLE_WIFI1.level(), wifi.levelDbm); | |
| 131 assertEquals(VISIBLE_WIFI1.timestampMs(), visibleNetwork.timestampMs); | |
| 132 assertEquals(connected, visibleNetwork.connected); | |
| 133 } | |
| 134 | |
| 135 @Test | |
| 122 public void testVisibleCellBuilder() { | 136 public void testVisibleCellBuilder() { |
| 123 for (@RadioType int radioType : RADIO_TYPES) { | 137 for (@RadioType int radioType : RADIO_TYPES) { |
| 124 VisibleCell visibleCell = VisibleCell.builder(radioType).build(); | 138 VisibleCell visibleCell = VisibleCell.builder(radioType).build(); |
| 125 assertEquals(radioType, visibleCell.radioType()); | 139 assertEquals(radioType, visibleCell.radioType()); |
| 126 } | 140 } |
| 127 } | 141 } |
| 128 | 142 |
| 129 @Test | 143 @Test |
| 130 public void testVisibleCellEquals() { | 144 public void testVisibleCellEquals() { |
| 131 VisibleCell copyOfVisibleCell1 = | 145 VisibleCell copyOfVisibleCell1 = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 161 assertNotEquals(VISIBLE_CELL2.hashCode(), VISIBLE_CELL1.hashCode()); | 175 assertNotEquals(VISIBLE_CELL2.hashCode(), VISIBLE_CELL1.hashCode()); |
| 162 } | 176 } |
| 163 | 177 |
| 164 @Test | 178 @Test |
| 165 public void testVisibleCellHashDifferentTimestamp() { | 179 public void testVisibleCellHashDifferentTimestamp() { |
| 166 // The timestamp is not included in the VisibleCell hash function. | 180 // The timestamp is not included in the VisibleCell hash function. |
| 167 assertEquals(VISIBLE_CELL1.hashCode(), VISIBLE_CELL1_DIFFERENT_TIMESTAMP .hashCode()); | 181 assertEquals(VISIBLE_CELL1.hashCode(), VISIBLE_CELL1_DIFFERENT_TIMESTAMP .hashCode()); |
| 168 } | 182 } |
| 169 | 183 |
| 170 @Test | 184 @Test |
| 185 public void testVisibleCellToProto() { | |
| 186 boolean connected = true; | |
| 187 PartnerLocationDescriptor.VisibleNetwork visibleNetwork = VISIBLE_CELL1. toProto(connected); | |
| 188 PartnerLocationDescriptor.VisibleNetwork.Cell cell = visibleNetwork.cell ; | |
| 189 | |
| 190 assertEquals(VISIBLE_CELL1.cellId(), cell.cellId); | |
| 191 assertEquals(VISIBLE_CELL1.locationAreaCode(), cell.locationAreaCode); | |
| 192 assertEquals(VISIBLE_CELL1.mobileCountryCode(), cell.mobileCountryCode); | |
| 193 assertEquals(VISIBLE_CELL1.mobileNetworkCode(), cell.mobileNetworkCode); | |
| 194 assertEquals(VISIBLE_CELL1.primaryScramblingCode(), cell.primaryScrambli ngCode); | |
| 195 assertEquals(VISIBLE_CELL1.physicalCellId(), cell.physicalCellId); | |
| 196 assertEquals(VISIBLE_CELL1.trackingAreaCode(), cell.trackingAreaCode); | |
| 197 assertEquals(VISIBLE_CELL1.timestampMs(), visibleNetwork.timestampMs); | |
| 198 assertEquals(connected, visibleNetwork.connected); | |
| 199 | |
| 200 switch (VISIBLE_CELL1.radioType()) { | |
| 201 case VisibleCell.UNKNOWN_RADIO_TYPE: | |
|
Ted C
2017/05/17 17:44:25
I "think" this is a bit misleading. There is only
lbargu
2017/05/18 12:42:48
Done.
| |
| 202 assertTrue(Cell.UNKNOWN == cell.type); | |
| 203 break; | |
| 204 case VisibleCell.UNKNOWN_MISSING_LOCATION_PERMISSION_RADIO_TYPE: | |
| 205 assertTrue(Cell.UNKNOWN == cell.type); | |
| 206 break; | |
| 207 case VisibleCell.WCDMA_RADIO_TYPE: | |
| 208 assertTrue(Cell.WCDMA == cell.type); | |
| 209 break; | |
| 210 case VisibleCell.LTE_RADIO_TYPE: | |
| 211 assertTrue(Cell.LTE == cell.type); | |
| 212 break; | |
| 213 case VisibleCell.GSM_RADIO_TYPE: | |
| 214 assertTrue(Cell.GSM == cell.type); | |
| 215 break; | |
| 216 case VisibleCell.CDMA_RADIO_TYPE: | |
| 217 assertTrue(Cell.CDMA == cell.type); | |
| 218 break; | |
| 219 } | |
| 220 } | |
| 221 | |
| 222 @Test | |
| 171 public void testVisibleNetworksCreate() { | 223 public void testVisibleNetworksCreate() { |
| 172 Set<VisibleCell> expectedVisibleCells = | 224 Set<VisibleCell> expectedVisibleCells = |
| 173 new HashSet<VisibleCell>(Arrays.asList(VISIBLE_CELL1, VISIBLE_CE LL2)); | 225 new HashSet<VisibleCell>(Arrays.asList(VISIBLE_CELL1, VISIBLE_CE LL2)); |
| 174 Set<VisibleWifi> expectedVisibleWifis = | 226 Set<VisibleWifi> expectedVisibleWifis = |
| 175 new HashSet<VisibleWifi>(Arrays.asList(VISIBLE_WIFI1, VISIBLE_WI FI2)); | 227 new HashSet<VisibleWifi>(Arrays.asList(VISIBLE_WIFI1, VISIBLE_WI FI2)); |
| 176 VisibleNetworks visibleNetworks = VisibleNetworks.create( | 228 VisibleNetworks visibleNetworks = VisibleNetworks.create( |
| 177 VISIBLE_WIFI1, VISIBLE_CELL1, expectedVisibleWifis, expectedVisi bleCells); | 229 VISIBLE_WIFI1, VISIBLE_CELL1, expectedVisibleWifis, expectedVisi bleCells); |
| 178 assertEquals(VISIBLE_WIFI1, visibleNetworks.connectedWifi()); | 230 assertEquals(VISIBLE_WIFI1, visibleNetworks.connectedWifi()); |
| 179 assertEquals(VISIBLE_CELL1, visibleNetworks.connectedCell()); | 231 assertEquals(VISIBLE_CELL1, visibleNetworks.connectedCell()); |
| 180 assertEquals(expectedVisibleWifis, visibleNetworks.allVisibleWifis()); | 232 assertEquals(expectedVisibleWifis, visibleNetworks.allVisibleWifis()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 201 assertNotEquals(VISIBLE_NETWORKS1.hashCode(), VISIBLE_NETWORKS2.hashCode ()); | 253 assertNotEquals(VISIBLE_NETWORKS1.hashCode(), VISIBLE_NETWORKS2.hashCode ()); |
| 202 } | 254 } |
| 203 | 255 |
| 204 @Test | 256 @Test |
| 205 public void testVisibleNetworksIsEmpty() { | 257 public void testVisibleNetworksIsEmpty() { |
| 206 VisibleNetworks visibleNetworks = VisibleNetworks.create(null, null, nul l, null); | 258 VisibleNetworks visibleNetworks = VisibleNetworks.create(null, null, nul l, null); |
| 207 assertTrue(visibleNetworks.isEmpty()); | 259 assertTrue(visibleNetworks.isEmpty()); |
| 208 assertFalse(VISIBLE_NETWORKS1.isEmpty()); | 260 assertFalse(VISIBLE_NETWORKS1.isEmpty()); |
| 209 } | 261 } |
| 210 } | 262 } |
| OLD | NEW |