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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 18348016: If requested, report network interfaces to management server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/prefs/testing_pref_service.h" 12 #include "base/prefs/testing_pref_service.h"
13 #include "base/run_loop.h"
13 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/chromeos/settings/cros_settings.h" 15 #include "chrome/browser/chromeos/settings/cros_settings.h"
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 16 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
16 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" 17 #include "chrome/browser/chromeos/settings/cros_settings_provider.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h" 18 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 19 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
19 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" 20 #include "chrome/browser/chromeos/system/mock_statistics_provider.h"
20 #include "chrome/browser/chromeos/system/statistics_provider.h" 21 #include "chrome/browser/chromeos/system/statistics_provider.h"
21 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 22 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chromeos/dbus/dbus_thread_manager.h"
25 #include "chromeos/dbus/shill_device_client.h"
26 #include "chromeos/network/network_handler.h"
23 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/geolocation_provider.h" 28 #include "content/public/browser/geolocation_provider.h"
25 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
26 #include "content/public/test/test_utils.h" 30 #include "content/public/test/test_utils.h"
27 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/cros_system_api/dbus/service_constants.h"
29 34
30 using ::testing::DoAll; 35 using ::testing::DoAll;
31 using ::testing::NotNull; 36 using ::testing::NotNull;
32 using ::testing::Return; 37 using ::testing::Return;
33 using ::testing::SetArgPointee; 38 using ::testing::SetArgPointee;
34 using ::testing::_; 39 using ::testing::_;
35 using base::Time; 40 using base::Time;
36 using base::TimeDelta; 41 using base::TimeDelta;
37 42
38 namespace em = enterprise_management; 43 namespace em = enterprise_management;
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 580
576 // Check that after enabling location reporting again, an error is reported 581 // Check that after enabling location reporting again, an error is reported
577 // if no valid fix is available. 582 // if no valid fix is available.
578 SetMockPositionToReturnNext(invalid_fix); 583 SetMockPositionToReturnNext(invalid_fix);
579 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); 584 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true);
580 // Allow the new pref to propagate to the status collector. 585 // Allow the new pref to propagate to the status collector.
581 message_loop_.RunUntilIdle(); 586 message_loop_.RunUntilIdle();
582 CheckThatALocationErrorIsReported(); 587 CheckThatALocationErrorIsReported();
583 } 588 }
584 589
590 // Fake device state.
591 struct FakeDeviceData {
592 const char* device_path;
593 const char* type;
594 const char* object_path;
595 const char* mac_address;
596 const char* meid;
597 };
598
599 static const FakeDeviceData kFakeDevices[] = {
600 { "/device/ethernet", flimflam::kTypeEthernet, "ethernet",
601 "112233445566", NULL },
pneubeck (no reviews) 2013/07/04 15:51:48 nit: maybe test also a device without mac_address
Mattias Nissler (ping if slow) 2013/07/11 17:41:46 Done.
602 { "/device/cellular", flimflam::kTypeCellular, "cellular",
603 "abcdefabcdef", "meid", },
604 { "/device/wifi", flimflam::kTypeWifi, "wifi",
605 "aabbccddeeff", NULL, },
606 };
607
608 class DeviceStatusCollectorNetworkInterfacesTest
609 : public DeviceStatusCollectorTest {
610 protected:
611 virtual void SetUp() OVERRIDE {
612 chromeos::DBusThreadManager::InitializeWithStub();
613 chromeos::NetworkHandler::Initialize();
614 chromeos::ShillDeviceClient::TestInterface* test_device_client =
615 chromeos::DBusThreadManager::Get()->GetShillDeviceClient()->
616 GetTestInterface();
617 test_device_client->ClearDevices();
618 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) {
619 const FakeDeviceData& dev = kFakeDevices[i];
620 test_device_client->AddDevice(dev.device_path, dev.type,
621 dev.object_path);
622 if (dev.mac_address) {
623 base::StringValue value(dev.mac_address);
pneubeck (no reviews) 2013/07/04 15:51:48 nit: no need for local variable declaration |value
Mattias Nissler (ping if slow) 2013/07/11 17:41:46 Done. Clang used to complain in these cases. That
624 test_device_client->SetDeviceProperty(
625 dev.device_path, flimflam::kAddressProperty, value);
626 }
627 if (dev.meid) {
628 base::StringValue value(dev.meid);
pneubeck (no reviews) 2013/07/04 15:51:48 ditto
Mattias Nissler (ping if slow) 2013/07/11 17:41:46 Done.
629 test_device_client->SetDeviceProperty(
630 dev.device_path, flimflam::kMeidProperty, value);
631 }
632 }
633
634 // Flush out pending state updates.
635 base::RunLoop().RunUntilIdle();
636 }
637
638 virtual void TearDown() OVERRIDE {
639 chromeos::NetworkHandler::Shutdown();
640 chromeos::DBusThreadManager::Shutdown();
641 }
642 };
643
644 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) {
645 // No interfaces should be reported if the policy is off.
646 GetStatus();
647 EXPECT_EQ(0, status_.network_interface_size());
648
649 // Switch the policy on and verify the interface list is present.
650 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true);
651 GetStatus();
652
653 ASSERT_EQ(static_cast<int>(arraysize(kFakeDevices)),
654 status_.network_interface_size());
655 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) {
656 const em::NetworkInterface& iface = status_.network_interface(i);
657 const FakeDeviceData& dev = kFakeDevices[i];
658 EXPECT_EQ(dev.type, iface.type());
659
660 if (dev.mac_address)
pneubeck (no reviews) 2013/07/04 15:51:48 you're testing the logic in the implementation wit
Mattias Nissler (ping if slow) 2013/07/11 17:41:46 That doesn't make a difference, I'd just be swappi
661 EXPECT_EQ(dev.mac_address, iface.mac_address());
662 else
663 EXPECT_FALSE(iface.has_mac_address());
664
665 if (dev.meid)
666 EXPECT_EQ(dev.meid, iface.meid());
667 else
668 EXPECT_FALSE(iface.has_meid());
669 }
670 }
671
585 } // namespace policy 672 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698