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

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc

Issue 1869483002: kiosk: Defer app update until platform matches (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/app_mode/kiosk_app_manager.h" 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/sys_info.h"
18 #include "base/time/time.h"
17 #include "base/values.h" 19 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/app_mode/fake_cws.h" 21 #include "chrome/browser/chromeos/app_mode/fake_cws.h"
20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
22 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" 24 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 25 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
24 #include "chrome/browser/chromeos/policy/device_local_account.h" 26 #include "chrome/browser/chromeos/policy/device_local_account.h"
25 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" 27 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
26 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 const std::string& version, 93 const std::string& version,
92 const std::string& id, 94 const std::string& id,
93 const std::string& required_platform_version) { 95 const std::string& required_platform_version) {
94 base::DictionaryValue value; 96 base::DictionaryValue value;
95 value.SetString("name", name); 97 value.SetString("name", name);
96 value.SetString("version", version); 98 value.SetString("version", version);
97 scoped_ptr<base::ListValue> scripts(new base::ListValue); 99 scoped_ptr<base::ListValue> scripts(new base::ListValue);
98 scripts->AppendString("main.js"); 100 scripts->AppendString("main.js");
99 value.Set("app.background.scripts", std::move(scripts)); 101 value.Set("app.background.scripts", std::move(scripts));
100 value.SetBoolean("kiosk_enabled", true); 102 value.SetBoolean("kiosk_enabled", true);
101 value.SetString("kiosk.required_platform_version", required_platform_version); 103 if (!required_platform_version.empty()) {
104 value.SetString("kiosk.required_platform_version",
105 required_platform_version);
106 }
102 107
103 std::string err; 108 std::string err;
104 scoped_refptr<extensions::Extension> app = 109 scoped_refptr<extensions::Extension> app =
105 extensions::Extension::Create( 110 extensions::Extension::Create(
106 base::FilePath(), 111 base::FilePath(),
107 extensions::Manifest::INTERNAL, 112 extensions::Manifest::INTERNAL,
108 value, 113 value,
109 extensions::Extension::WAS_INSTALLED_BY_DEFAULT, 114 extensions::Extension::WAS_INSTALLED_BY_DEFAULT,
110 id, 115 id,
111 &err); 116 &err);
112 EXPECT_EQ(err, ""); 117 EXPECT_EQ(err, "");
113 return app; 118 return app;
114 } 119 }
115 120
121 void SetPlatformVersion(const std::string& platform_version) {
122 const std::string lsb_release = base::StringPrintf(
123 "CHROMEOS_RELEASE_VERSION=%s", platform_version.c_str());
124 base::SysInfo::SetChromeOSVersionInfoForTest(lsb_release, base::Time::Now());
125 }
126
116 class AppDataLoadWaiter : public KioskAppManagerObserver { 127 class AppDataLoadWaiter : public KioskAppManagerObserver {
117 public: 128 public:
118 AppDataLoadWaiter(KioskAppManager* manager, int expected_data_change) 129 AppDataLoadWaiter(KioskAppManager* manager, int expected_data_change)
119 : manager_(manager), expected_data_change_(expected_data_change) { 130 : manager_(manager), expected_data_change_(expected_data_change) {
120 manager_->AddObserver(this); 131 manager_->AddObserver(this);
121 } 132 }
122 133
123 ~AppDataLoadWaiter() override { manager_->RemoveObserver(this); } 134 ~AppDataLoadWaiter() override { manager_->RemoveObserver(this); }
124 135
125 void Wait() { 136 void Wait() {
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 583
573 // Fake app data load failure so that the manager will attempt to 584 // Fake app data load failure so that the manager will attempt to
574 // load it from crx. 585 // load it from crx.
575 KioskAppData* app_data = GetAppDataMutable(kAppId); 586 KioskAppData* app_data = GetAppDataMutable(kAppId);
576 app_data->SetStatusForTest(KioskAppData::STATUS_ERROR); 587 app_data->SetStatusForTest(KioskAppData::STATUS_ERROR);
577 588
578 // Copy test crx file to temp dir because the cache moves the file. 589 // Copy test crx file to temp dir because the cache moves the file.
579 base::FilePath test_dir; 590 base::FilePath test_dir;
580 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 591 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
581 base::FilePath data_dir = 592 base::FilePath data_dir =
582 test_dir.AppendASCII("chromeos/app_mode/offline_enabled_kiosk_app"); 593 test_dir.AppendASCII("chromeos/app_mode/webstore/downloads/");
583 base::FilePath crx_file = 594 base::FilePath crx_file = data_dir.AppendASCII(
584 data_dir.AppendASCII("v2_required_platform_version_added.crx"); 595 "ajoggoflpgplnnjkjamcmbepjdjdnpdp_v2_required_platform_version_added."
596 "crx");
585 crx_file = CopyFileToTempDir(crx_file); 597 crx_file = CopyFileToTempDir(crx_file);
586 598
587 ExternalCachePutWaiter put_waiter; 599 ExternalCachePutWaiter put_waiter;
588 manager()->PutValidatedExternalExtension( 600 manager()->PutValidatedExternalExtension(
589 kAppId, crx_file, "2.0.0", 601 kAppId, crx_file, "2.0.0",
590 base::Bind(&ExternalCachePutWaiter::OnPutExtension, 602 base::Bind(&ExternalCachePutWaiter::OnPutExtension,
591 base::Unretained(&put_waiter))); 603 base::Unretained(&put_waiter)));
592 put_waiter.Wait(); 604 put_waiter.Wait();
593 ASSERT_TRUE(put_waiter.success()); 605 ASSERT_TRUE(put_waiter.success());
594 606
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 878
867 // No require platform version if auto launched app has a non-zero delay set. 879 // No require platform version if auto launched app has a non-zero delay set.
868 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 1); 880 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 1);
869 EXPECT_EQ("", manager()->GetAutoLaunchAppRequiredPlatformVersion()); 881 EXPECT_EQ("", manager()->GetAutoLaunchAppRequiredPlatformVersion());
870 882
871 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0); 883 settings_helper_.SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0);
872 EXPECT_EQ(kRequiredPlatformVersion, 884 EXPECT_EQ(kRequiredPlatformVersion,
873 manager()->GetAutoLaunchAppRequiredPlatformVersion()); 885 manager()->GetAutoLaunchAppRequiredPlatformVersion());
874 } 886 }
875 887
888 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, IsPlatformCompliant) {
889 SetPlatformVersion("1234.1.2");
890
891 EXPECT_TRUE(manager()->IsPlatformCompliant(""));
892 EXPECT_TRUE(manager()->IsPlatformCompliant("1234"));
893 EXPECT_TRUE(manager()->IsPlatformCompliant("1234.1"));
894 EXPECT_TRUE(manager()->IsPlatformCompliant("1234.1.2"));
895
896 EXPECT_FALSE(manager()->IsPlatformCompliant("123"));
897 EXPECT_FALSE(manager()->IsPlatformCompliant("1234.2"));
898 EXPECT_FALSE(manager()->IsPlatformCompliant("1234.1.1"));
899 EXPECT_FALSE(manager()->IsPlatformCompliant("1234.1.3"));
900
901 EXPECT_FALSE(manager()->IsPlatformCompliant("1234.1.2.3"));
902 EXPECT_FALSE(manager()->IsPlatformCompliant("bad version"));
903 }
904
905 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, IsPlatformCompliantWithApp) {
906 SetPlatformVersion("1234.1.2");
907
908 const char kAppId[] = "app_id";
909 SetExistingApp(kAppId, "App Name", "red16x16.png", "");
910
911 manager()->SetAutoLaunchApp(kAppId, owner_settings_service_.get());
912 manager()->SetEnableAutoLaunch(true);
913 manager()->SetAppWasAutoLaunchedWithZeroDelay(kAppId);
914
915 struct {
916 const std::string required_platform_version;
917 const bool expected_compliant;
918 } kTestCases[] = {
919 {"", true},
920 {"1234", true},
921 {"1234.1", true},
922 {"1234.1.2", true},
923 {"123", false},
924 {"1234.2", false},
925 {"1234.1.1", false},
926 {"1234.1.3", false},
927 };
928
929 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
930 scoped_refptr<extensions::Extension> app = MakeKioskApp(
931 "App Name", "1.0", kAppId, kTestCases[i].required_platform_version);
932 EXPECT_EQ(kTestCases[i].expected_compliant,
933 manager()->IsPlatformCompliantWithApp(app.get()))
934 << "Test case: " << i << ", required_platform_version="
935 << kTestCases[i].required_platform_version;
936 }
937
938 // If an app is not auto launched with zero delay, it is always compliant.
939 const char kNoneAutoLaucnhedAppId[] = "none_auto_launch_app_id";
940 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
941 scoped_refptr<extensions::Extension> app =
942 MakeKioskApp("App Name", "1.0", kNoneAutoLaucnhedAppId,
943 kTestCases[i].required_platform_version);
944 EXPECT_TRUE(manager()->IsPlatformCompliantWithApp(app.get()))
945 << "Test case for non auto launch app: " << i
946 << ", required_platform_version="
947 << kTestCases[i].required_platform_version;
948 }
949 }
950
876 } // namespace chromeos 951 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698