OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/app_mode/kiosk_test_common.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" |
| 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "crypto/sha2.h" |
| 14 |
| 15 using net::test_server::BasicHttpResponse; |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 void KioskTestCommon::SetUpdateCheckContent( |
| 20 const std::string& update_check_file, |
| 21 const GURL& crx_download_url, |
| 22 const std::string& app_id, |
| 23 const std::string& crx_fp, |
| 24 const std::string& crx_size, |
| 25 const std::string& version, |
| 26 std::string* update_check_content) { |
| 27 base::FilePath test_data_dir; |
| 28 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 29 base::FilePath update_file = |
| 30 test_data_dir.AppendASCII(update_check_file.c_str()); |
| 31 ASSERT_TRUE(base::ReadFileToString(update_file, update_check_content)); |
| 32 |
| 33 ReplaceSubstringsAfterOffset(update_check_content, 0, "$AppId", app_id); |
| 34 ReplaceSubstringsAfterOffset( |
| 35 update_check_content, 0, "$CrxDownloadUrl", crx_download_url.spec()); |
| 36 ReplaceSubstringsAfterOffset(update_check_content, 0, "$FP", crx_fp); |
| 37 ReplaceSubstringsAfterOffset(update_check_content, 0, "$Size", crx_size); |
| 38 ReplaceSubstringsAfterOffset(update_check_content, 0, "$Version", version); |
| 39 } |
| 40 |
| 41 scoped_ptr<HttpResponse> KioskTestCommon::HandleRequest( |
| 42 const HttpRequest& request) { |
| 43 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 44 std::string request_path = request_url.path(); |
| 45 if (!update_check_content_.empty() && |
| 46 request_path.find("/update_check.xml") != std::string::npos) { |
| 47 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 48 http_response->set_code(net::HTTP_OK); |
| 49 http_response->set_content_type("text/xml"); |
| 50 http_response->set_content(update_check_content_); |
| 51 return http_response.PassAs<HttpResponse>(); |
| 52 } |
| 53 |
| 54 return scoped_ptr<HttpResponse>(); |
| 55 } |
| 56 |
| 57 void KioskTestCommon::SetUpdateCrx(const GURL& webstore_url, |
| 58 const std::string& crx_donwload_path, |
| 59 const std::string& app_id, |
| 60 const std::string& crx_file, |
| 61 const std::string& version) { |
| 62 GURL crx_download_url = webstore_url.Resolve(crx_donwload_path + crx_file); |
| 63 |
| 64 base::FilePath test_data_dir; |
| 65 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 66 base::FilePath crx_file_path = |
| 67 test_data_dir.AppendASCII("chromeos/app_mode/webstore/downloads") |
| 68 .AppendASCII(crx_file); |
| 69 std::string crx_content; |
| 70 ASSERT_TRUE(base::ReadFileToString(crx_file_path, &crx_content)); |
| 71 |
| 72 const std::string sha256 = crypto::SHA256HashString(crx_content); |
| 73 const std::string sha256_hex = base::HexEncode(sha256.c_str(), sha256.size()); |
| 74 |
| 75 SetUpdateCheckContent( |
| 76 "chromeos/app_mode/webstore/update_check/has_update.xml", |
| 77 crx_download_url, |
| 78 app_id, |
| 79 sha256_hex, |
| 80 base::UintToString(crx_content.size()), |
| 81 version, |
| 82 &update_check_content_); |
| 83 } |
| 84 |
| 85 } // namespace chromeos |
OLD | NEW |