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

Side by Side Diff: chrome/browser/chromeos/login/kiosk_browsertest.cc

Issue 271263002: New test cases for kiosk app crx file cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "apps/app_window.h" 5 #include "apps/app_window.h"
6 #include "apps/app_window_registry.h" 6 #include "apps/app_window_registry.h"
7 #include "apps/ui/native_app_window.h" 7 #include "apps/ui/native_app_window.h"
8 #include "ash/desktop_background/desktop_background_controller.h" 8 #include "ash/desktop_background/desktop_background_controller.h"
9 #include "ash/desktop_background/desktop_background_controller_observer.h" 9 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
20 #include "chrome/browser/chromeos/app_mode/kiosk_test_common.h"
20 #include "chrome/browser/chromeos/login/app_launch_controller.h" 21 #include "chrome/browser/chromeos/login/app_launch_controller.h"
21 #include "chrome/browser/chromeos/login/fake_user_manager.h" 22 #include "chrome/browser/chromeos/login/fake_user_manager.h"
22 #include "chrome/browser/chromeos/login/mock_user_manager.h" 23 #include "chrome/browser/chromeos/login/mock_user_manager.h"
23 #include "chrome/browser/chromeos/login/oobe_base_test.h" 24 #include "chrome/browser/chromeos/login/oobe_base_test.h"
24 #include "chrome/browser/chromeos/login/startup_utils.h" 25 #include "chrome/browser/chromeos/login/startup_utils.h"
25 #include "chrome/browser/chromeos/login/test/app_window_waiter.h" 26 #include "chrome/browser/chromeos/login/test/app_window_waiter.h"
26 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" 27 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
27 #include "chrome/browser/chromeos/login/wizard_controller.h" 28 #include "chrome/browser/chromeos/login/wizard_controller.h"
28 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 29 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
29 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 30 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
30 #include "chrome/browser/chromeos/profiles/profile_helper.h" 31 #include "chrome/browser/chromeos/profiles/profile_helper.h"
31 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 32 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
32 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 33 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
33 #include "chrome/browser/extensions/extension_service.h" 34 #include "chrome/browser/extensions/extension_service.h"
34 #include "chrome/browser/extensions/extension_test_message_listener.h" 35 #include "chrome/browser/extensions/extension_test_message_listener.h"
35 #include "chrome/browser/profiles/profile_impl.h" 36 #include "chrome/browser/profiles/profile_impl.h"
36 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h" 37 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h"
37 #include "chrome/common/chrome_constants.h" 38 #include "chrome/common/chrome_constants.h"
38 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
39 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
41 #include "chromeos/chromeos_switches.h" 42 #include "chromeos/chromeos_switches.h"
42 #include "chromeos/dbus/cryptohome_client.h" 43 #include "chromeos/dbus/cryptohome_client.h"
43 #include "components/signin/core/common/signin_pref_names.h" 44 #include "components/signin/core/common/signin_pref_names.h"
44 #include "content/public/browser/notification_observer.h" 45 #include "content/public/browser/notification_observer.h"
45 #include "content/public/browser/notification_registrar.h" 46 #include "content/public/browser/notification_registrar.h"
46 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
47 #include "content/public/test/browser_test_utils.h" 48 #include "content/public/test/browser_test_utils.h"
48 #include "crypto/sha2.h"
49 #include "extensions/browser/extension_system.h" 49 #include "extensions/browser/extension_system.h"
50 #include "google_apis/gaia/gaia_constants.h" 50 #include "google_apis/gaia/gaia_constants.h"
51 #include "google_apis/gaia/gaia_switches.h" 51 #include "google_apis/gaia/gaia_switches.h"
52 #include "google_apis/gaia/gaia_urls.h" 52 #include "google_apis/gaia/gaia_urls.h"
53 #include "net/test/embedded_test_server/embedded_test_server.h" 53 #include "net/test/embedded_test_server/embedded_test_server.h"
54 #include "net/test/embedded_test_server/http_request.h"
55 #include "net/test/embedded_test_server/http_response.h"
56
57 using net::test_server::BasicHttpResponse;
58 using net::test_server::HttpRequest;
59 using net::test_server::HttpResponse;
60 54
61 namespace em = enterprise_management; 55 namespace em = enterprise_management;
62 56
63 namespace chromeos { 57 namespace chromeos {
64 58
65 namespace { 59 namespace {
66 60
67 // This is a simple test app that creates an app window and immediately closes 61 // This is a simple test app that creates an app window and immediately closes
68 // it again. Webstore data json is in 62 // it again. Webstore data json is in
69 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/ 63 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
(...skipping 16 matching lines...) Expand all
86 // chrome/test/data/chromeos/app_mode/webstore/downloads/ 80 // chrome/test/data/chromeos/app_mode/webstore/downloads/
87 const char kTestOfflineEnabledKioskApp[] = "ajoggoflpgplnnjkjamcmbepjdjdnpdp"; 81 const char kTestOfflineEnabledKioskApp[] = "ajoggoflpgplnnjkjamcmbepjdjdnpdp";
88 82
89 // An app to test local fs data persistence across app update. V1 app writes 83 // An app to test local fs data persistence across app update. V1 app writes
90 // data into local fs. V2 app reads and verifies the data. 84 // data into local fs. V2 app reads and verifies the data.
91 // Webstore data json is in 85 // Webstore data json is in
92 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/ 86 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
93 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf 87 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf
94 const char kTestLocalFsKioskApp[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf"; 88 const char kTestLocalFsKioskApp[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf";
95 89
90 // Kiosk app crx file download path under web store site.
91 const char kCrxDownloadPath[] = "/chromeos/app_mode/webstore/downloads/";
92
96 // Timeout while waiting for network connectivity during tests. 93 // Timeout while waiting for network connectivity during tests.
97 const int kTestNetworkTimeoutSeconds = 1; 94 const int kTestNetworkTimeoutSeconds = 1;
98 95
99 // Email of owner account for test. 96 // Email of owner account for test.
100 const char kTestOwnerEmail[] = "owner@example.com"; 97 const char kTestOwnerEmail[] = "owner@example.com";
101 98
102 const char kTestEnterpriseAccountId[] = "enterprise-kiosk-app@localhost"; 99 const char kTestEnterpriseAccountId[] = "enterprise-kiosk-app@localhost";
103 const char kTestEnterpriseServiceAccountId[] = "service_account@example.com"; 100 const char kTestEnterpriseServiceAccountId[] = "service_account@example.com";
104 const char kTestRefreshToken[] = "fake-refresh-token"; 101 const char kTestRefreshToken[] = "fake-refresh-token";
105 const char kTestUserinfoToken[] = "fake-userinfo-token"; 102 const char kTestUserinfoToken[] = "fake-userinfo-token";
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator", 890 GetLoginUI()->CallJavascriptFunction("cr.ui.Oobe.handleAccelerator",
894 base::StringValue("kiosk_enable")); 891 base::StringValue("kiosk_enable"));
895 892
896 // And it should show up. 893 // And it should show up.
897 content::WindowedNotificationObserver( 894 content::WindowedNotificationObserver(
898 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE, 895 chrome::NOTIFICATION_KIOSK_ENABLE_WARNING_VISIBLE,
899 content::NotificationService::AllSources()).Wait(); 896 content::NotificationService::AllSources()).Wait();
900 } 897 }
901 898
902 class KioskUpdateTest : public KioskTest, 899 class KioskUpdateTest : public KioskTest,
900 public KioskTestCommon,
903 public testing::WithParamInterface<bool> { 901 public testing::WithParamInterface<bool> {
904 public: 902 public:
905 KioskUpdateTest() {} 903 KioskUpdateTest() {}
906 virtual ~KioskUpdateTest() {} 904 virtual ~KioskUpdateTest() {}
907 905
908 protected: 906 protected:
909 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 907 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
910 // Needs background networking so that ExtensionDownloader works. 908 // Needs background networking so that ExtensionDownloader works.
911 needs_background_networking_ = true; 909 needs_background_networking_ = true;
912 910
(...skipping 12 matching lines...) Expand all
925 923
926 embedded_test_server()->RegisterRequestHandler( 924 embedded_test_server()->RegisterRequestHandler(
927 base::Bind(&KioskUpdateTest::HandleRequest, 925 base::Bind(&KioskUpdateTest::HandleRequest,
928 base::Unretained(this))); 926 base::Unretained(this)));
929 } 927 }
930 928
931 void SetNoUpdate() { 929 void SetNoUpdate() {
932 SetUpdateCheckContent( 930 SetUpdateCheckContent(
933 "chromeos/app_mode/webstore/update_check/no_update.xml", 931 "chromeos/app_mode/webstore/update_check/no_update.xml",
934 GURL(), 932 GURL(),
933 test_app_id(),
935 "", 934 "",
936 "", 935 "",
937 ""); 936 "",
938 } 937 &update_check_content_);
939
940 void SetUpdateCrx(const std::string& crx_file, const std::string& version) {
941 GURL webstore_url = GetTestWebstoreUrl();
942 GURL crx_download_url = webstore_url.Resolve(
943 "/chromeos/app_mode/webstore/downloads/" + crx_file);
944 base::FilePath test_data_dir;
945 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
946 base::FilePath crx_file_path =
947 test_data_dir.AppendASCII("chromeos/app_mode/webstore/downloads")
948 .AppendASCII(crx_file);
949
950 std::string crx_content;
951 ASSERT_TRUE(base::ReadFileToString(crx_file_path, &crx_content));
952
953 const std::string sha256 = crypto::SHA256HashString(crx_content);
954 const std::string sha256_hex =
955 base::HexEncode(sha256.c_str(), sha256.size());
956
957 SetUpdateCheckContent(
958 "chromeos/app_mode/webstore/update_check/has_update.xml",
959 crx_download_url,
960 sha256_hex,
961 base::UintToString(crx_content.size()),
962 version);
963 } 938 }
964 939
965 private: 940 private:
966 void SetUpdateCheckContent(const std::string& update_check_file,
967 const GURL& crx_download_url,
968 const std::string& crx_fp,
969 const std::string& crx_size,
970 const std::string& version) {
971 base::FilePath test_data_dir;
972 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
973 base::FilePath update_file =
974 test_data_dir.AppendASCII(update_check_file.c_str());
975 ASSERT_TRUE(base::ReadFileToString(update_file, &update_check_content_));
976
977 ReplaceSubstringsAfterOffset(
978 &update_check_content_, 0, "$AppId", test_app_id());
979 ReplaceSubstringsAfterOffset(
980 &update_check_content_, 0, "$CrxDownloadUrl", crx_download_url.spec());
981 ReplaceSubstringsAfterOffset(&update_check_content_, 0, "$FP", crx_fp);
982 ReplaceSubstringsAfterOffset(&update_check_content_, 0, "$Size", crx_size);
983 ReplaceSubstringsAfterOffset(
984 &update_check_content_, 0, "$Version", version);
985 }
986
987 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
988 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
989 std::string request_path = request_url.path();
990 if (!update_check_content_.empty() &&
991 request_path == "/update_check.xml") {
992 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
993 http_response->set_code(net::HTTP_OK);
994 http_response->set_content_type("text/xml");
995 http_response->set_content(update_check_content_);
996 return http_response.PassAs<HttpResponse>();
997 }
998
999 return scoped_ptr<HttpResponse>();
1000 }
1001
1002 std::string update_check_content_;
1003
1004 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest); 941 DISALLOW_COPY_AND_ASSIGN(KioskUpdateTest);
1005 }; 942 };
1006 943
1007 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) { 944 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppNoNetwork) {
1008 set_test_app_id(kTestOfflineEnabledKioskApp); 945 set_test_app_id(kTestOfflineEnabledKioskApp);
1009 946
1010 PrepareAppLaunch(); 947 PrepareAppLaunch();
1011 SimulateNetworkOffline(); 948 SimulateNetworkOffline();
1012 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); 949 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1013 950
(...skipping 12 matching lines...) Expand all
1026 963
1027 LaunchApp(test_app_id(), false); 964 LaunchApp(test_app_id(), false);
1028 WaitForAppLaunchSuccess(); 965 WaitForAppLaunchSuccess();
1029 966
1030 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString()); 967 EXPECT_EQ("1.0.0", GetInstalledAppVersion().GetString());
1031 } 968 }
1032 969
1033 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) { 970 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, LaunchOfflineEnabledAppHasUpdate) {
1034 set_test_app_id(kTestOfflineEnabledKioskApp); 971 set_test_app_id(kTestOfflineEnabledKioskApp);
1035 972
1036 SetUpdateCrx("ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx", "2.0.0"); 973 SetUpdateCrx(GetTestWebstoreUrl(),
974 kCrxDownloadPath,
975 test_app_id(),
976 "ajoggoflpgplnnjkjamcmbepjdjdnpdp.crx",
977 "2.0.0");
1037 978
1038 PrepareAppLaunch(); 979 PrepareAppLaunch();
1039 SimulateNetworkOnline(); 980 SimulateNetworkOnline();
1040 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); 981 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1041 982
1042 LaunchApp(test_app_id(), false); 983 LaunchApp(test_app_id(), false);
1043 WaitForAppLaunchSuccess(); 984 WaitForAppLaunchSuccess();
1044 985
1045 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); 986 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1046 } 987 }
1047 988
1048 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PermissionChange) { 989 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PermissionChange) {
1049 set_test_app_id(kTestOfflineEnabledKioskApp); 990 set_test_app_id(kTestOfflineEnabledKioskApp);
1050 991
1051 SetUpdateCrx("ajoggoflpgplnnjkjamcmbepjdjdnpdp_v2_permission_change.crx", 992 SetUpdateCrx(GetTestWebstoreUrl(),
993 kCrxDownloadPath,
994 test_app_id(),
995 "ajoggoflpgplnnjkjamcmbepjdjdnpdp_v2_permission_change.crx",
1052 "2.0.0"); 996 "2.0.0");
1053 997
1054 PrepareAppLaunch(); 998 PrepareAppLaunch();
1055 SimulateNetworkOnline(); 999 SimulateNetworkOnline();
1056 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile"); 1000 SetupAppProfile("chromeos/app_mode/offline_enabled_app_profile");
1057 1001
1058 LaunchApp(test_app_id(), false); 1002 LaunchApp(test_app_id(), false);
1059 WaitForAppLaunchSuccess(); 1003 WaitForAppLaunchSuccess();
1060 1004
1061 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); 1005 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1062 } 1006 }
1063 1007
1064 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_PreserveLocalData) { 1008 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PRE_PreserveLocalData) {
1065 // Installs v1 app and writes some local data. 1009 // Installs v1 app and writes some local data.
1066 set_test_app_id(kTestLocalFsKioskApp); 1010 set_test_app_id(kTestLocalFsKioskApp);
1067 1011
1068 ResultCatcher catcher; 1012 ResultCatcher catcher;
1069 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); 1013 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1070 WaitForAppLaunchSuccess(); 1014 WaitForAppLaunchSuccess();
1071 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 1015 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
1072 } 1016 }
1073 1017
1074 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PreserveLocalData) { 1018 IN_PROC_BROWSER_TEST_P(KioskUpdateTest, PreserveLocalData) {
1075 // Update existing v1 app installed in PRE_PreserveLocalData to v2 1019 // Update existing v1 app installed in PRE_PreserveLocalData to v2
1076 // that reads and verifies the local data. 1020 // that reads and verifies the local data.
1077 set_test_app_id(kTestLocalFsKioskApp); 1021 set_test_app_id(kTestLocalFsKioskApp);
1078 1022
1079 SetUpdateCrx("bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx", 1023 SetUpdateCrx(GetTestWebstoreUrl(),
1024 kCrxDownloadPath,
1025 test_app_id(),
1026 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx",
1080 "2.0.0"); 1027 "2.0.0");
1081 1028
1082 ResultCatcher catcher; 1029 ResultCatcher catcher;
1083 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure()); 1030 StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
1084 WaitForAppLaunchSuccess(); 1031 WaitForAppLaunchSuccess();
1085 1032
1086 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString()); 1033 EXPECT_EQ("2.0.0", GetInstalledAppVersion().GetString());
1087 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 1034 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
1088 } 1035 }
1089 1036
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 content::WindowedNotificationObserver( 1247 content::WindowedNotificationObserver(
1301 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE, 1248 chrome::NOTIFICATION_KIOSK_AUTOLAUNCH_WARNING_VISIBLE,
1302 content::NotificationService::AllSources()).Wait(); 1249 content::NotificationService::AllSources()).Wait();
1303 1250
1304 // Wait for the wallpaper to load. 1251 // Wait for the wallpaper to load.
1305 WaitForWallpaper(); 1252 WaitForWallpaper();
1306 EXPECT_TRUE(wallpaper_loaded()); 1253 EXPECT_TRUE(wallpaper_loaded());
1307 } 1254 }
1308 1255
1309 } // namespace chromeos 1256 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698