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

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

Powered by Google App Engine
This is Rietveld 408576698