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

Unified Diff: chrome/browser/chromeos/app_mode/kiosk_test_common.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/app_mode/kiosk_test_common.cc
diff --git a/chrome/browser/chromeos/app_mode/kiosk_test_common.cc b/chrome/browser/chromeos/app_mode/kiosk_test_common.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1288e4c99712656aa5a3c0276606293e85d77daf
--- /dev/null
+++ b/chrome/browser/chromeos/app_mode/kiosk_test_common.cc
@@ -0,0 +1,85 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/app_mode/kiosk_test_common.h"
+
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "crypto/sha2.h"
+
+using net::test_server::BasicHttpResponse;
+
+namespace chromeos {
+
+void KioskTestCommon::SetUpdateCheckContent(
+ const std::string& update_check_file,
+ const GURL& crx_download_url,
+ const std::string& app_id,
+ const std::string& crx_fp,
+ const std::string& crx_size,
+ const std::string& version,
+ std::string* update_check_content) {
+ base::FilePath test_data_dir;
+ PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
+ base::FilePath update_file =
+ test_data_dir.AppendASCII(update_check_file.c_str());
+ ASSERT_TRUE(base::ReadFileToString(update_file, update_check_content));
+
+ ReplaceSubstringsAfterOffset(update_check_content, 0, "$AppId", app_id);
+ ReplaceSubstringsAfterOffset(
+ update_check_content, 0, "$CrxDownloadUrl", crx_download_url.spec());
+ ReplaceSubstringsAfterOffset(update_check_content, 0, "$FP", crx_fp);
+ ReplaceSubstringsAfterOffset(update_check_content, 0, "$Size", crx_size);
+ ReplaceSubstringsAfterOffset(update_check_content, 0, "$Version", version);
+}
+
+scoped_ptr<HttpResponse> KioskTestCommon::HandleRequest(
+ const HttpRequest& request) {
+ GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
+ std::string request_path = request_url.path();
+ if (!update_check_content_.empty() &&
+ request_path.find("/update_check.xml") != std::string::npos) {
+ scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
+ http_response->set_code(net::HTTP_OK);
+ http_response->set_content_type("text/xml");
+ http_response->set_content(update_check_content_);
+ return http_response.PassAs<HttpResponse>();
+ }
+
+ return scoped_ptr<HttpResponse>();
+}
+
+void KioskTestCommon::SetUpdateCrx(const GURL& webstore_url,
+ const std::string& crx_donwload_path,
+ const std::string& app_id,
+ const std::string& crx_file,
+ const std::string& version) {
+ GURL crx_download_url = webstore_url.Resolve(crx_donwload_path + crx_file);
+
+ base::FilePath test_data_dir;
+ PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
+ base::FilePath crx_file_path =
+ test_data_dir.AppendASCII("chromeos/app_mode/webstore/downloads")
+ .AppendASCII(crx_file);
+ std::string crx_content;
+ ASSERT_TRUE(base::ReadFileToString(crx_file_path, &crx_content));
+
+ const std::string sha256 = crypto::SHA256HashString(crx_content);
+ const std::string sha256_hex = base::HexEncode(sha256.c_str(), sha256.size());
+
+ SetUpdateCheckContent(
+ "chromeos/app_mode/webstore/update_check/has_update.xml",
+ crx_download_url,
+ app_id,
+ sha256_hex,
+ base::UintToString(crx_content.size()),
+ version,
+ &update_check_content_);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698