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

Unified Diff: chrome/browser/chrome_to_mobile/common/test_cloud_print_request_factory.h

Issue 11038063: Support chrome_to_mobile job receiving Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix format Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chrome_to_mobile/common/test_cloud_print_request_factory.h
diff --git a/chrome/browser/chrome_to_mobile/common/test_cloud_print_request_factory.h b/chrome/browser/chrome_to_mobile/common/test_cloud_print_request_factory.h
new file mode 100644
index 0000000000000000000000000000000000000000..fb9d682589b37ba0990f886249dce38df707e1c6
--- /dev/null
+++ b/chrome/browser/chrome_to_mobile/common/test_cloud_print_request_factory.h
@@ -0,0 +1,115 @@
+// Copyright 2012 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.
+
+#ifndef CHROME_BROWSER_CHROME_TO_MOBILE_COMMON_TEST_CLOUD_PRINT_REQUEST_FACTORY_H_
+#define CHROME_BROWSER_CHROME_TO_MOBILE_COMMON_TEST_CLOUD_PRINT_REQUEST_FACTORY_H_
+
+#include <vector>
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chrome_to_mobile/common/cloud_print_request.h"
+#include "chrome/browser/chrome_to_mobile/common/cloud_print_request_factory.h"
+
+namespace chrome_to_mobile {
+
+class TestCloudPrintRequestFactory;
+
+// A implementation of |CloudPrintRequest| for testing that allows users to set
+// the response data and status.
+class TestCloudPrintRequest : public CloudPrintRequest {
+ public:
+ // |factory| is the factory that creates this request.
+ // This request is tracked in the factory until it is destructed.
+ TestCloudPrintRequest(TestCloudPrintRequestFactory* factory,
+ const GURL& url,
+ Delegate* delegate);
+ virtual ~TestCloudPrintRequest();
+
+ virtual bool HasOAuth2AccessTokenFailure() const OVERRIDE;
+ virtual bool HasCloudPrintAuthError() const OVERRIDE;
+ virtual std::string GetResponseMimeType() const OVERRIDE;
+ virtual std::string GetResponseData(bool* success) const OVERRIDE;
+
+ // Helpers for testing.
+ // Completes the request.
+ void Complete();
+ // Completes the request with the given response data.
+ void Complete(const std::string& response_data,
+ const std::string& mime_type,
+ const bool& success,
+ const bool& has_oauth2_access_token_failure,
+ const bool& has_cloud_print_auth_error);
+ std::string GetRequestPath() const;
+ bool HasCompleted() const;
+
+ private:
+ friend class TestCloudPrintRequestFactory;
+
+ TestCloudPrintRequestFactory * const factory_;
+ const GURL url_;
+ CloudPrintRequest::Delegate * const delegate_;
+
+ bool has_completed_;
+ std::string response_data_;
+ std::string mime_type_;
+ bool success_;
+ bool has_oauth2_access_token_failure_;
+ bool has_cloud_print_auth_error_;
+};
+
+// Changes CloudPrintRequest's Factory for the lifetime of the object.
+class ScopedCloudPrintRequestFactory : public base::NonThreadSafe {
+ public:
+ explicit ScopedCloudPrintRequestFactory(CloudPrintRequestFactory* factory);
+ virtual ~ScopedCloudPrintRequestFactory();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedCloudPrintRequestFactory);
+};
+
+// Simple |CloudPrintRequestFactory| that creates and keeps track of
+// |TestCloudPrintRequests|.
+class TestCloudPrintRequestFactory : public CloudPrintRequestFactory,
+ public ScopedCloudPrintRequestFactory {
+ public:
+ TestCloudPrintRequestFactory();
+ virtual ~TestCloudPrintRequestFactory();
+
+ // |CloudPrintRequestFactory|
+ virtual CloudPrintRequest* CreateAndStart(
+ const GURL& url,
+ const std::string& additional_header,
+ const net::URLFetcher::RequestType& request_type,
+ const std::string& post_data_mime_type,
+ const std::string& post_data,
+ const CloudPrintRequest::Settings& settings,
+ CloudPrintRequest::Delegate* delegate) OVERRIDE;
+
+ // Returns all the pending requests.
+ std::vector<TestCloudPrintRequest*> GetPendingRequests() const;
+ // Returns all the pending requests at |path|.
+ std::vector<TestCloudPrintRequest*> GetPendingRequestsAtPath(
+ const std::string& path) const;
+ // Completes the |index|th request at |path| with |success|, assuming such one
+ // exists.
+ void CompleteRequestAtPath(const std::string& path, int index, bool success);
+ // Completes the |index|th request at |path| with the passed in response data,
+ // assuming such one exists.
+ void CompleteRequestAtPath(
+ const std::string& path, int index,
+ const std::string& response_data, const std::string& mime_type,
+ bool success, bool has_oauth2_access_token_failure,
+ bool has_cloud_print_auth_error);
+
+ private:
+ friend class TestCloudPrintRequest;
+ std::vector<TestCloudPrintRequest*> requests_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestCloudPrintRequestFactory);
+};
+
+} // namespace chrome_to_mobile
+
+#endif // CHROME_BROWSER_CHROME_TO_MOBILE_COMMON_TEST_CLOUD_PRINT_REQUEST_FACTORY_H_

Powered by Google App Engine
This is Rietveld 408576698