| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/status/network_menu_icon.h" | 5 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/cros/cros_library.h" | 7 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 8 #include "chrome/test/base/testing_browser_process.h" | 8 #include "chrome/test/base/testing_browser_process.h" |
| 9 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
| 10 #include "grit/theme_resources_standard.h" | 10 #include "grit/theme_resources_standard.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // 3G connecting = IDR_STATUSBAR_NETWORK_BARS1 (faded). | 137 // 3G connecting = IDR_STATUSBAR_NETWORK_BARS1 (faded). |
| 138 cellular_connecting_image_ = NetworkMenuIcon::GenerateConnectingBitmap( | 138 cellular_connecting_image_ = NetworkMenuIcon::GenerateConnectingBitmap( |
| 139 NetworkMenuIcon::GetImage(NetworkMenuIcon::BARS, 1, | 139 NetworkMenuIcon::GetImage(NetworkMenuIcon::BARS, 1, |
| 140 NetworkMenuIcon::COLOR_DARK)); | 140 NetworkMenuIcon::COLOR_DARK)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 virtual void TearDown() OVERRIDE { | 143 virtual void TearDown() OVERRIDE { |
| 144 } | 144 } |
| 145 | 145 |
| 146 protected: | 146 protected: |
| 147 void SetConnected(Network* network, bool connected) { | 147 void SetConnected(Network* network) { |
| 148 Network::TestApi test_network(network); | 148 Network::TestApi test_network(network); |
| 149 test_network.SetConnected(connected); | 149 test_network.SetConnected(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void SetConnecting(Network* network, bool connecting) { | 152 void SetConnecting(Network* network) { |
| 153 Network::TestApi test_network(network); | 153 Network::TestApi test_network(network); |
| 154 test_network.SetConnecting(connecting); | 154 test_network.SetConnecting(); |
| 155 } |
| 156 |
| 157 void SetDisconnected(Network* network) { |
| 158 Network::TestApi test_network(network); |
| 159 test_network.SetDisconnected(); |
| 155 } | 160 } |
| 156 | 161 |
| 157 void SetActive(Network* network, bool active) { | 162 void SetActive(Network* network, bool active) { |
| 158 if (active) { | 163 if (active) { |
| 159 cros_->SetActiveNetwork(network->type(), network->service_path()); | 164 cros_->SetActiveNetwork(network->type(), network->service_path()); |
| 160 } else { | 165 } else { |
| 161 cros_->SetActiveNetwork(network->type(), ""); | 166 cros_->SetActiveNetwork(network->type(), ""); |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 | 169 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 gfx::ImageSkia cellular_connected_100_image_; | 212 gfx::ImageSkia cellular_connected_100_image_; |
| 208 gfx::ImageSkia cellular_roaming_50_image_; | 213 gfx::ImageSkia cellular_roaming_50_image_; |
| 209 gfx::ImageSkia cellular_disconnected_image_; | 214 gfx::ImageSkia cellular_disconnected_image_; |
| 210 gfx::ImageSkia cellular_connecting_image_; | 215 gfx::ImageSkia cellular_connecting_image_; |
| 211 }; | 216 }; |
| 212 | 217 |
| 213 // Compare icon cache results against expected results fron SetUp(). | 218 // Compare icon cache results against expected results fron SetUp(). |
| 214 TEST_F(NetworkMenuIconTest, EthernetIcon) { | 219 TEST_F(NetworkMenuIconTest, EthernetIcon) { |
| 215 Network* network = cros_->FindNetworkByPath("eth1"); | 220 Network* network = cros_->FindNetworkByPath("eth1"); |
| 216 ASSERT_NE(static_cast<const Network*>(NULL), network); | 221 ASSERT_NE(static_cast<const Network*>(NULL), network); |
| 217 SetConnected(network, true); | 222 SetConnected(network); |
| 218 gfx::ImageSkia icon = NetworkMenuIcon::GetImage(network, | 223 gfx::ImageSkia icon = NetworkMenuIcon::GetImage(network, |
| 219 NetworkMenuIcon::COLOR_DARK); | 224 NetworkMenuIcon::COLOR_DARK); |
| 220 EXPECT_TRUE(CompareImages(icon, ethernet_connected_image_)); | 225 EXPECT_TRUE(CompareImages(icon, ethernet_connected_image_)); |
| 221 | 226 |
| 222 SetConnected(network, false); | 227 SetDisconnected(network); |
| 223 icon = NetworkMenuIcon::GetImage(network, | 228 icon = NetworkMenuIcon::GetImage(network, |
| 224 NetworkMenuIcon::COLOR_DARK); | 229 NetworkMenuIcon::COLOR_DARK); |
| 225 EXPECT_TRUE(CompareImages(icon, ethernet_disconnected_image_)); | 230 EXPECT_TRUE(CompareImages(icon, ethernet_disconnected_image_)); |
| 226 } | 231 } |
| 227 | 232 |
| 228 TEST_F(NetworkMenuIconTest, WifiIcon) { | 233 TEST_F(NetworkMenuIconTest, WifiIcon) { |
| 229 WifiNetwork* network = cros_->FindWifiNetworkByPath("wifi1"); | 234 WifiNetwork* network = cros_->FindWifiNetworkByPath("wifi1"); |
| 230 ASSERT_NE(static_cast<const Network*>(NULL), network); | 235 ASSERT_NE(static_cast<const Network*>(NULL), network); |
| 231 gfx::ImageSkia icon = NetworkMenuIcon::GetImage(network, | 236 gfx::ImageSkia icon = NetworkMenuIcon::GetImage(network, |
| 232 NetworkMenuIcon::COLOR_DARK); | 237 NetworkMenuIcon::COLOR_DARK); |
| 233 EXPECT_TRUE(CompareImages(icon, wifi_connected_100_image_)); | 238 EXPECT_TRUE(CompareImages(icon, wifi_connected_100_image_)); |
| 234 | 239 |
| 235 SetStrength(network, 50); | 240 SetStrength(network, 50); |
| 236 SetEncryption(network, SECURITY_RSN); | 241 SetEncryption(network, SECURITY_RSN); |
| 237 icon = NetworkMenuIcon::GetImage(network, | 242 icon = NetworkMenuIcon::GetImage(network, |
| 238 NetworkMenuIcon::COLOR_DARK); | 243 NetworkMenuIcon::COLOR_DARK); |
| 239 EXPECT_TRUE(CompareImages(icon, wifi_encrypted_50_image_)); | 244 EXPECT_TRUE(CompareImages(icon, wifi_encrypted_50_image_)); |
| 240 | 245 |
| 241 SetConnected(network, false); | 246 SetDisconnected(network); |
| 242 SetStrength(network, 0); | 247 SetStrength(network, 0); |
| 243 SetEncryption(network, SECURITY_NONE); | 248 SetEncryption(network, SECURITY_NONE); |
| 244 icon = NetworkMenuIcon::GetImage(network, | 249 icon = NetworkMenuIcon::GetImage(network, |
| 245 NetworkMenuIcon::COLOR_DARK); | 250 NetworkMenuIcon::COLOR_DARK); |
| 246 EXPECT_TRUE(CompareImages(icon, wifi_disconnected_image_)); | 251 EXPECT_TRUE(CompareImages(icon, wifi_disconnected_image_)); |
| 247 } | 252 } |
| 248 | 253 |
| 249 TEST_F(NetworkMenuIconTest, CellularIcon) { | 254 TEST_F(NetworkMenuIconTest, CellularIcon) { |
| 250 CellularNetwork* network = cros_->FindCellularNetworkByPath("cellular1"); | 255 CellularNetwork* network = cros_->FindCellularNetworkByPath("cellular1"); |
| 251 ASSERT_NE(static_cast<const Network*>(NULL), network); | 256 ASSERT_NE(static_cast<const Network*>(NULL), network); |
| 252 SetConnected(network, true); | 257 SetConnected(network); |
| 253 SetStrength(network, 100); | 258 SetStrength(network, 100); |
| 254 SetRoamingState(network, ROAMING_STATE_HOME); | 259 SetRoamingState(network, ROAMING_STATE_HOME); |
| 255 gfx::ImageSkia icon = NetworkMenuIcon::GetImage(network, | 260 gfx::ImageSkia icon = NetworkMenuIcon::GetImage(network, |
| 256 NetworkMenuIcon::COLOR_DARK); | 261 NetworkMenuIcon::COLOR_DARK); |
| 257 EXPECT_TRUE(CompareImages(icon, cellular_connected_100_image_)); | 262 EXPECT_TRUE(CompareImages(icon, cellular_connected_100_image_)); |
| 258 | 263 |
| 259 SetStrength(network, 50); | 264 SetStrength(network, 50); |
| 260 SetRoamingState(network, ROAMING_STATE_ROAMING); | 265 SetRoamingState(network, ROAMING_STATE_ROAMING); |
| 261 icon = NetworkMenuIcon::GetImage(network, | 266 icon = NetworkMenuIcon::GetImage(network, |
| 262 NetworkMenuIcon::COLOR_DARK); | 267 NetworkMenuIcon::COLOR_DARK); |
| 263 EXPECT_TRUE(CompareImages(icon, cellular_roaming_50_image_)); | 268 EXPECT_TRUE(CompareImages(icon, cellular_roaming_50_image_)); |
| 264 | 269 |
| 265 SetConnected(network, false); | 270 SetDisconnected(network); |
| 266 SetStrength(network, 0); | 271 SetStrength(network, 0); |
| 267 SetRoamingState(network, ROAMING_STATE_HOME); | 272 SetRoamingState(network, ROAMING_STATE_HOME); |
| 268 icon = NetworkMenuIcon::GetImage(network, | 273 icon = NetworkMenuIcon::GetImage(network, |
| 269 NetworkMenuIcon::COLOR_DARK); | 274 NetworkMenuIcon::COLOR_DARK); |
| 270 EXPECT_TRUE(CompareImages(icon, cellular_disconnected_image_)); | 275 EXPECT_TRUE(CompareImages(icon, cellular_disconnected_image_)); |
| 271 } | 276 } |
| 272 | 277 |
| 273 namespace { | 278 namespace { |
| 274 | 279 |
| 275 class TestNetworkMenuIcon : public NetworkMenuIcon { | 280 class TestNetworkMenuIcon : public NetworkMenuIcon { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // See network_library_unit_test.cc for more info. | 316 // See network_library_unit_test.cc for more info. |
| 312 | 317 |
| 313 TEST_F(NetworkMenuIconTest, StatusIconMenuMode) { | 318 TEST_F(NetworkMenuIconTest, StatusIconMenuMode) { |
| 314 TestNetworkMenuIcon menu_icon(NetworkMenuIcon::MENU_MODE); | 319 TestNetworkMenuIcon menu_icon(NetworkMenuIcon::MENU_MODE); |
| 315 gfx::ImageSkia icon; | 320 gfx::ImageSkia icon; |
| 316 | 321 |
| 317 // Set cellular1 to connecting. | 322 // Set cellular1 to connecting. |
| 318 CellularNetwork* cellular1 = cros_->FindCellularNetworkByPath("cellular1"); | 323 CellularNetwork* cellular1 = cros_->FindCellularNetworkByPath("cellular1"); |
| 319 ASSERT_NE(static_cast<const Network*>(NULL), cellular1); | 324 ASSERT_NE(static_cast<const Network*>(NULL), cellular1); |
| 320 SetRoamingState(cellular1, ROAMING_STATE_HOME); // Clear romaing state | 325 SetRoamingState(cellular1, ROAMING_STATE_HOME); // Clear romaing state |
| 321 SetConnecting(cellular1, true); | 326 SetConnecting(cellular1); |
| 322 | 327 |
| 323 // For MENU_MODE, we always display the connecting icon (cellular1). | 328 // For MENU_MODE, we always display the connecting icon (cellular1). |
| 324 icon = menu_icon.GetIconAndText(NULL); | 329 icon = menu_icon.GetIconAndText(NULL); |
| 325 EXPECT_TRUE(CompareImages(icon, cellular_connecting_image_)); | 330 EXPECT_TRUE(CompareImages(icon, cellular_connecting_image_)); |
| 326 | 331 |
| 327 // Set cellular1 to connected; ethernet icon should be shown. | 332 // Set cellular1 to connected; ethernet icon should be shown. |
| 328 SetConnected(cellular1, true); | 333 SetConnected(cellular1); |
| 329 icon = menu_icon.GetIconAndText(NULL); | 334 icon = menu_icon.GetIconAndText(NULL); |
| 330 EXPECT_TRUE(CompareImages(icon, ethernet_connected_image_)); | 335 EXPECT_TRUE(CompareImages(icon, ethernet_connected_image_)); |
| 331 | 336 |
| 332 // Set ethernet to inactive/disconnected; wifi icon should be shown. | 337 // Set ethernet to inactive/disconnected; wifi icon should be shown. |
| 333 Network* eth1 = cros_->FindNetworkByPath("eth1"); | 338 Network* eth1 = cros_->FindNetworkByPath("eth1"); |
| 334 ASSERT_NE(static_cast<const Network*>(NULL), eth1); | 339 ASSERT_NE(static_cast<const Network*>(NULL), eth1); |
| 335 SetActive(eth1, false); | 340 SetActive(eth1, false); |
| 336 SetConnected(eth1, false); | 341 SetDisconnected(eth1); |
| 337 icon = menu_icon.GetIconAndText(NULL); | 342 icon = menu_icon.GetIconAndText(NULL); |
| 338 EXPECT_TRUE(CompareImages(icon, wifi_connected_100_image_)); | 343 EXPECT_TRUE(CompareImages(icon, wifi_connected_100_image_)); |
| 339 } | 344 } |
| 340 | 345 |
| 341 TEST_F(NetworkMenuIconTest, StatusIconDropdownMode) { | 346 TEST_F(NetworkMenuIconTest, StatusIconDropdownMode) { |
| 342 TestNetworkMenuIcon menu_icon(NetworkMenuIcon::DROPDOWN_MODE); | 347 TestNetworkMenuIcon menu_icon(NetworkMenuIcon::DROPDOWN_MODE); |
| 343 gfx::ImageSkia icon; | 348 gfx::ImageSkia icon; |
| 344 | 349 |
| 345 // Set wifi1 to connecting. | 350 // Set wifi1 to connecting. |
| 346 WifiNetwork* wifi1 = cros_->FindWifiNetworkByPath("wifi1"); | 351 WifiNetwork* wifi1 = cros_->FindWifiNetworkByPath("wifi1"); |
| 347 ASSERT_NE(static_cast<const Network*>(NULL), wifi1); | 352 ASSERT_NE(static_cast<const Network*>(NULL), wifi1); |
| 348 SetConnecting(wifi1, true); | 353 SetConnecting(wifi1); |
| 349 | 354 |
| 350 // For DROPDOWN_MODE, we prioritize the connected network (ethernet). | 355 // For DROPDOWN_MODE, we prioritize the connected network (ethernet). |
| 351 icon = menu_icon.GetIconAndText(NULL); | 356 icon = menu_icon.GetIconAndText(NULL); |
| 352 EXPECT_TRUE(CompareImages(icon, ethernet_connected_image_)); | 357 EXPECT_TRUE(CompareImages(icon, ethernet_connected_image_)); |
| 353 | 358 |
| 354 // Set ethernet to inactive/disconnected. | 359 // Set ethernet to inactive/disconnected. |
| 355 Network* ethernet = cros_->FindNetworkByPath("eth1"); | 360 Network* ethernet = cros_->FindNetworkByPath("eth1"); |
| 356 ASSERT_NE(static_cast<const Network*>(NULL), ethernet); | 361 ASSERT_NE(static_cast<const Network*>(NULL), ethernet); |
| 357 SetActive(ethernet, false); | 362 SetActive(ethernet, false); |
| 358 SetConnected(ethernet, false); | 363 SetDisconnected(ethernet); |
| 359 | 364 |
| 360 // Icon should now be cellular connected icon. | 365 // Icon should now be cellular connected icon. |
| 361 icon = menu_icon.GetIconAndText(NULL); | 366 icon = menu_icon.GetIconAndText(NULL); |
| 362 EXPECT_TRUE(CompareImages(icon, cellular_connected_100_image_)); | 367 EXPECT_TRUE(CompareImages(icon, cellular_connected_100_image_)); |
| 363 | 368 |
| 364 // Set cellular1 to disconnected; Icon should now be wimax icon. | 369 // Set cellular1 to disconnected; Icon should now be wimax icon. |
| 365 CellularNetwork* cellular1 = cros_->FindCellularNetworkByPath("cellular1"); | 370 CellularNetwork* cellular1 = cros_->FindCellularNetworkByPath("cellular1"); |
| 366 ASSERT_NE(static_cast<const Network*>(NULL), cellular1); | 371 ASSERT_NE(static_cast<const Network*>(NULL), cellular1); |
| 367 SetConnected(cellular1, false); | 372 SetDisconnected(cellular1); |
| 368 icon = menu_icon.GetIconAndText(NULL); | 373 icon = menu_icon.GetIconAndText(NULL); |
| 369 EXPECT_TRUE(CompareImages(icon, wimax_connected_50_image_)); | 374 EXPECT_TRUE(CompareImages(icon, wimax_connected_50_image_)); |
| 370 | 375 |
| 371 // Set wifi1 to connected. Icon should now be wifi connected icon. | 376 // Set wifi1 to connected. Icon should now be wifi connected icon. |
| 372 SetConnected(wifi1, true); | 377 SetConnected(wifi1); |
| 373 icon = menu_icon.GetIconAndText(NULL); | 378 icon = menu_icon.GetIconAndText(NULL); |
| 374 EXPECT_TRUE(CompareImages(icon, wifi_connected_100_image_)); | 379 EXPECT_TRUE(CompareImages(icon, wifi_connected_100_image_)); |
| 375 } | 380 } |
| 376 | 381 |
| 377 } // namespace chromeos | 382 } // namespace chromeos |
| OLD | NEW |