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

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

Issue 676913002: kiosk: Support update url for enterprise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 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 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/fake_cws.h" 5 #include "chrome/browser/chromeos/app_mode/fake_cws.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 13 matching lines...) Expand all
24 namespace chromeos { 24 namespace chromeos {
25 25
26 namespace { 26 namespace {
27 27
28 const char kWebstoreDomain[] = "cws.com"; 28 const char kWebstoreDomain[] = "cws.com";
29 // Kiosk app crx file download path under web store site. 29 // Kiosk app crx file download path under web store site.
30 const char kCrxDownloadPath[] = "/chromeos/app_mode/webstore/downloads/"; 30 const char kCrxDownloadPath[] = "/chromeos/app_mode/webstore/downloads/";
31 31
32 } // namespace 32 } // namespace
33 33
34 FakeCWS::FakeCWS() : update_check_count_(0) {
35 }
36
37 FakeCWS::~FakeCWS() {
38 }
39
34 void FakeCWS::Init(EmbeddedTestServer* embedded_test_server) { 40 void FakeCWS::Init(EmbeddedTestServer* embedded_test_server) {
35 SetupWebStore(embedded_test_server->base_url()); 41 has_update_template_ =
36 SetupWebStoreGalleryUrl(); 42 "chromeos/app_mode/webstore/update_check/has_update.xml";
37 SetupCrxDownloadAndUpdateUrls(embedded_test_server); 43 no_update_template_ = "chromeos/app_mode/webstore/update_check/no_update.xml";
44 update_check_end_point_ = "/update_check.xml";
45
46 SetupWebStoreURL(embedded_test_server->base_url());
47 OverrideGalleryCommandlineSwitches();
48 embedded_test_server->RegisterRequestHandler(
49 base::Bind(&FakeCWS::HandleRequest, base::Unretained(this)));
50 }
51
52 void FakeCWS::InitAsPrivateStore(EmbeddedTestServer* embedded_test_server,
53 const std::string& update_check_end_point) {
54 has_update_template_ =
55 "chromeos/app_mode/webstore/update_check/has_update_private_store.xml";
56 no_update_template_ = "chromeos/app_mode/webstore/update_check/no_update.xml";
57 update_check_end_point_ = update_check_end_point;
58
59 SetupWebStoreURL(embedded_test_server->base_url());
60 embedded_test_server->RegisterRequestHandler(
61 base::Bind(&FakeCWS::HandleRequest, base::Unretained(this)));
38 } 62 }
39 63
40 void FakeCWS::SetUpdateCrx(const std::string& app_id, 64 void FakeCWS::SetUpdateCrx(const std::string& app_id,
41 const std::string& crx_file, 65 const std::string& crx_file,
42 const std::string& version) { 66 const std::string& version) {
43 GURL crx_download_url = web_store_url_.Resolve(kCrxDownloadPath + crx_file); 67 GURL crx_download_url = web_store_url_.Resolve(kCrxDownloadPath + crx_file);
44 68
45 base::FilePath test_data_dir; 69 base::FilePath test_data_dir;
46 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 70 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
47 base::FilePath crx_file_path = 71 base::FilePath crx_file_path =
48 test_data_dir.AppendASCII("chromeos/app_mode/webstore/downloads") 72 test_data_dir.AppendASCII("chromeos/app_mode/webstore/downloads")
49 .AppendASCII(crx_file); 73 .AppendASCII(crx_file);
50 std::string crx_content; 74 std::string crx_content;
51 ASSERT_TRUE(base::ReadFileToString(crx_file_path, &crx_content)); 75 ASSERT_TRUE(base::ReadFileToString(crx_file_path, &crx_content));
52 76
53 const std::string sha256 = crypto::SHA256HashString(crx_content); 77 const std::string sha256 = crypto::SHA256HashString(crx_content);
54 const std::string sha256_hex = base::HexEncode(sha256.c_str(), sha256.size()); 78 const std::string sha256_hex = base::HexEncode(sha256.c_str(), sha256.size());
55 79
56 SetUpdateCheckContent( 80 SetUpdateCheckContent(
57 "chromeos/app_mode/webstore/update_check/has_update.xml", 81 has_update_template_,
58 crx_download_url, 82 crx_download_url,
59 app_id, 83 app_id,
60 sha256_hex, 84 sha256_hex,
61 base::UintToString(crx_content.size()), 85 base::UintToString(crx_content.size()),
62 version, 86 version,
63 &update_check_content_); 87 &update_check_content_);
64 } 88 }
65 89
66 void FakeCWS::SetNoUpdate(const std::string& app_id) { 90 void FakeCWS::SetNoUpdate(const std::string& app_id) {
67 SetUpdateCheckContent("chromeos/app_mode/webstore/update_check/no_update.xml", 91 SetUpdateCheckContent(no_update_template_,
68 GURL(), 92 GURL(),
69 app_id, 93 app_id,
70 "", 94 "",
71 "", 95 "",
72 "", 96 "",
73 &update_check_content_); 97 &update_check_content_);
74 } 98 }
75 99
76 void FakeCWS::SetupWebStore(const GURL& test_server_url) { 100 int FakeCWS::GetUpdateCheckCountAndReset() {
101 int current_count = update_check_count_;
102 update_check_count_ = 0;
103 return current_count;
104 }
105
106 void FakeCWS::SetupWebStoreURL(const GURL& test_server_url) {
77 std::string webstore_host(kWebstoreDomain); 107 std::string webstore_host(kWebstoreDomain);
78 GURL::Replacements replace_webstore_host; 108 GURL::Replacements replace_webstore_host;
79 replace_webstore_host.SetHostStr(webstore_host); 109 replace_webstore_host.SetHostStr(webstore_host);
80 web_store_url_ = test_server_url.ReplaceComponents(replace_webstore_host); 110 web_store_url_ = test_server_url.ReplaceComponents(replace_webstore_host);
81 } 111 }
82 112
83 void FakeCWS::SetupWebStoreGalleryUrl() { 113 void FakeCWS::OverrideGalleryCommandlineSwitches() {
84 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 114 DCHECK(web_store_url_.is_valid());
115
116 CommandLine* command_line = CommandLine::ForCurrentProcess();
117
118 command_line->AppendSwitchASCII(
85 ::switches::kAppsGalleryURL, 119 ::switches::kAppsGalleryURL,
86 web_store_url_.Resolve("/chromeos/app_mode/webstore").spec()); 120 web_store_url_.Resolve("/chromeos/app_mode/webstore").spec());
87 }
88 121
89 void FakeCWS::SetupCrxDownloadAndUpdateUrls(
90 EmbeddedTestServer* embedded_test_server) {
91 SetupCrxDownloadUrl();
92 SetupCrxUpdateUrl(embedded_test_server);
93 }
94
95 void FakeCWS::SetupCrxDownloadUrl() {
96 std::string downloads_path = std::string(kCrxDownloadPath).append("%s.crx"); 122 std::string downloads_path = std::string(kCrxDownloadPath).append("%s.crx");
97 GURL downloads_url = web_store_url_.Resolve(downloads_path); 123 GURL downloads_url = web_store_url_.Resolve(downloads_path);
98 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 124 command_line->AppendSwitchASCII(::switches::kAppsGalleryDownloadURL,
99 ::switches::kAppsGalleryDownloadURL, downloads_url.spec()); 125 downloads_url.spec());
100 }
101 126
102 void FakeCWS::SetupCrxUpdateUrl(EmbeddedTestServer* embedded_test_server) { 127 GURL update_url = web_store_url_.Resolve(update_check_end_point_);
103 GURL update_url = web_store_url_.Resolve("/update_check.xml"); 128 command_line->AppendSwitchASCII(::switches::kAppsGalleryUpdateURL,
104 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 129 update_url.spec());
105 ::switches::kAppsGalleryUpdateURL, update_url.spec());
106
107 embedded_test_server->RegisterRequestHandler(
108 base::Bind(&FakeCWS::HandleRequest, base::Unretained(this)));
109 } 130 }
110 131
111 void FakeCWS::SetUpdateCheckContent(const std::string& update_check_file, 132 void FakeCWS::SetUpdateCheckContent(const std::string& update_check_file,
112 const GURL& crx_download_url, 133 const GURL& crx_download_url,
113 const std::string& app_id, 134 const std::string& app_id,
114 const std::string& crx_fp, 135 const std::string& crx_fp,
115 const std::string& crx_size, 136 const std::string& crx_size,
116 const std::string& version, 137 const std::string& version,
117 std::string* update_check_content) { 138 std::string* update_check_content) {
118 base::FilePath test_data_dir; 139 base::FilePath test_data_dir;
119 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 140 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
120 base::FilePath update_file = 141 base::FilePath update_file =
121 test_data_dir.AppendASCII(update_check_file.c_str()); 142 test_data_dir.AppendASCII(update_check_file.c_str());
122 ASSERT_TRUE(base::ReadFileToString(update_file, update_check_content)); 143 ASSERT_TRUE(base::ReadFileToString(update_file, update_check_content));
123 144
124 ReplaceSubstringsAfterOffset(update_check_content, 0, "$AppId", app_id); 145 ReplaceSubstringsAfterOffset(update_check_content, 0, "$AppId", app_id);
125 ReplaceSubstringsAfterOffset( 146 ReplaceSubstringsAfterOffset(
126 update_check_content, 0, "$CrxDownloadUrl", crx_download_url.spec()); 147 update_check_content, 0, "$CrxDownloadUrl", crx_download_url.spec());
127 ReplaceSubstringsAfterOffset(update_check_content, 0, "$FP", crx_fp); 148 ReplaceSubstringsAfterOffset(update_check_content, 0, "$FP", crx_fp);
128 ReplaceSubstringsAfterOffset(update_check_content, 0, "$Size", crx_size); 149 ReplaceSubstringsAfterOffset(update_check_content, 0, "$Size", crx_size);
129 ReplaceSubstringsAfterOffset(update_check_content, 0, "$Version", version); 150 ReplaceSubstringsAfterOffset(update_check_content, 0, "$Version", version);
130 } 151 }
131 152
132 scoped_ptr<HttpResponse> FakeCWS::HandleRequest(const HttpRequest& request) { 153 scoped_ptr<HttpResponse> FakeCWS::HandleRequest(const HttpRequest& request) {
133 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 154 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
134 std::string request_path = request_url.path(); 155 std::string request_path = request_url.path();
135 if (!update_check_content_.empty() && 156 if (!update_check_content_.empty() &&
136 request_path.find("/update_check.xml") != std::string::npos) { 157 request_path.find(update_check_end_point_) != std::string::npos) {
158 ++update_check_count_;
137 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 159 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
138 http_response->set_code(net::HTTP_OK); 160 http_response->set_code(net::HTTP_OK);
139 http_response->set_content_type("text/xml"); 161 http_response->set_content_type("text/xml");
140 http_response->set_content(update_check_content_); 162 http_response->set_content(update_check_content_);
141 return http_response.Pass(); 163 return http_response.Pass();
142 } 164 }
143 165
144 return scoped_ptr<HttpResponse>(); 166 return scoped_ptr<HttpResponse>();
145 } 167 }
146 168
147 } // namespace chromeos 169 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/app_mode/fake_cws.h ('k') | chrome/browser/chromeos/app_mode/kiosk_app_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698