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

Unified Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 907323002: Implemented DeviceStatusCollector::GetDeviceSessionStatus() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
index c6b6fb798fb34b9b53ef40af1ec46af312ee0da5..2627752cd3035e4c119f92fe9c0514e315c6cdf9 100644
--- a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
+++ b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_local_account.h"
#include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
@@ -47,6 +48,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
+using ::testing::Return;
using ::testing::ReturnRef;
using base::Time;
using base::TimeDelta;
@@ -57,6 +59,8 @@ namespace em = enterprise_management;
namespace {
const int64 kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000;
+const char kKioskAccountId[] = "kiosk_user@localhost";
+const char kKioskAppId[] = "kiosk_app_id";
scoped_ptr<content::Geoposition> mock_position_to_return_next;
@@ -137,6 +141,12 @@ class TestingDeviceStatusCollector : public policy::DeviceStatusCollector {
return kiosk_mode_;
}
+ std::string GetAppVersion(std::string app_id) override {
+ // Just return the app_id as the version - this makes it easy for tests
+ // to confirm that the correct app's version was requested.
+ return app_id;
+ }
+
void RefreshSampleResourceUsage() {
// Refresh our samples. Sample more than kMaxHardwareSamples times to
// make sure that the code correctly caps the number of cached samples.
@@ -340,6 +350,20 @@ class DeviceStatusCollectorTest : public testing::Test {
location.error_code());
}
+ void MockRunningKioskApp() {
+ DeviceLocalAccount local_account(
bartfab (slow) 2015/02/11 17:28:43 Nit: const.
Andrew T Wilson (Slow) 2015/02/12 15:15:39 moot due to refactoring.
+ policy::DeviceLocalAccount::TYPE_KIOSK_APP,
+ kKioskAccountId,
+ kKioskAppId,
+ std::string());
+ std::vector<DeviceLocalAccount> accounts;
+ accounts.push_back(local_account);
+ SetDeviceLocalAccounts(cros_settings_, accounts);
+ user_manager_->CreateKioskAppUser(local_account.user_id);
+ EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly(
+ Return(true));
+ }
+
protected:
// Convenience method.
int64 ActivePeriodMilliseconds() {
@@ -841,6 +865,42 @@ TEST_F(DeviceStatusCollectorTest, TestCPUSamples) {
EXPECT_EQ(0, status_.cpu_utilization_pct().size());
}
+TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) {
+ // Should not report session status if we don't have an active kiosk app.
+ cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true);
+ status_collector_->set_kiosk_mode(false);
+ em::SessionStatusReportRequest session_status;
+ EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
+}
+
+TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) {
+ // Should not report session status if session status reporting is disabled.
+ cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false);
+ status_collector_->set_kiosk_mode(true);
+ MockRunningKioskApp();
+
+ em::SessionStatusReportRequest session_status;
+ EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
+}
+
+TEST_F(DeviceStatusCollectorTest, ReportSession) {
bartfab (slow) 2015/02/11 17:28:43 Nit: s/ReportSession/ReportSessionStatus/
Andrew T Wilson (Slow) 2015/02/12 15:15:39 Done.
+ cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true);
+ status_collector_->set_kiosk_mode(true);
+
+ // Setup a DeviceLocalAccount for a kiosk app.
bartfab (slow) 2015/02/11 17:28:43 Nit: s/Setup DeviceLocalAccount for a kiosk app/Se
+ MockRunningKioskApp();
+ em::SessionStatusReportRequest session_status;
bartfab (slow) 2015/02/11 17:28:43 Nit: Add blank line above. The setup phase is done
Andrew T Wilson (Slow) 2015/02/12 15:15:39 Done.
+ EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status));
+ ASSERT_EQ(1, session_status.installed_apps_size());
+ EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id());
+ em::AppStatus app = session_status.installed_apps(0);
bartfab (slow) 2015/02/11 17:28:43 Nit: const.
Andrew T Wilson (Slow) 2015/02/12 15:15:39 Done.
+ EXPECT_EQ(kKioskAppId, app.app_id());
+ // Test code just sets the version to the app ID.
+ EXPECT_EQ(kKioskAppId, app.extension_version());
+ EXPECT_FALSE(app.has_status());
+ EXPECT_FALSE(app.has_error());
+}
+
// Fake device state.
struct FakeDeviceData {
const char* device_path;

Powered by Google App Engine
This is Rietveld 408576698