Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / fake_cws.h
blobbaade207dc53255e703085acf9a119b31985b932
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_FAKE_CWS_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_FAKE_CWS_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/http_request.h"
14 #include "net/test/embedded_test_server/http_response.h"
15 #include "url/gurl.h"
17 namespace chromeos {
19 // Simple fake CWS update check request handler that returns a fixed update
20 // check response. The response is created either from SetUpdateCrx() or
21 // SetNoUpdate().
22 class FakeCWS {
23 public:
24 FakeCWS();
25 ~FakeCWS();
27 // Initializes as CWS request handler and overrides app gallery command line
28 // switches.
29 void Init(net::test_server::EmbeddedTestServer* embedded_test_server);
31 // Initializes as a private store handler using the given server and URL end
32 // point. Private store does not override app gallery command lines and use a
33 // slightly different template (as documented on
34 // https://developer.chrome.com/extensions/autoupdate).
35 void InitAsPrivateStore(
36 net::test_server::EmbeddedTestServer* embedded_test_server,
37 const std::string& update_check_end_point);
39 // Sets up the update check response with has_update template.
40 void SetUpdateCrx(const std::string& app_id,
41 const std::string& crx_file,
42 const std::string& version);
44 // Sets up the update check response with no_update template.
45 void SetNoUpdate(const std::string& app_id);
47 // Returns the current |update_check_count_| and resets it.
48 int GetUpdateCheckCountAndReset();
50 private:
51 void SetupWebStoreURL(const GURL& test_server_url);
52 void OverrideGalleryCommandlineSwitches();
54 bool GetUpdateCheckContent(const std::vector<std::string>& ids,
55 std::string* update_check_content);
57 // Request handler for kiosk app update server.
58 scoped_ptr<net::test_server::HttpResponse> HandleRequest(
59 const net::test_server::HttpRequest& request);
61 GURL web_store_url_;
63 std::string has_update_template_;
64 std::string no_update_template_;
65 std::string update_check_end_point_;
67 // Map keyed by app_id to app_update_content.
68 std::map<std::string, std::string> id_to_update_check_content_map_;
69 int update_check_count_;
71 DISALLOW_COPY_AND_ASSIGN(FakeCWS);
74 } // namespace chromeos
76 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_FAKE_CWS_H_