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

Unified Diff: chromeos/printing/ppd_provider_unittest.cc

Issue 2343983004: Add PPDProvider barebones implementation and associated cache skeleton. (Closed)
Patch Set: Remove extra includes Created 4 years, 3 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
« chromeos/printing/ppd_provider.cc ('K') | « chromeos/printing/ppd_provider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/printing/ppd_provider_unittest.cc
diff --git a/chromeos/printing/ppd_provider_unittest.cc b/chromeos/printing/ppd_provider_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7d3a2aaf657601f20fc42680287a639ebdca16c8
--- /dev/null
+++ b/chromeos/printing/ppd_provider_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright 2016 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 "base/bind.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "chromeos/printing/ppd_cache.h"
+#include "chromeos/printing/ppd_provider.h"
+#include "net/url_request/test_url_request_interceptor.h"
+#include "net/url_request/url_request_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::base::FilePath;
+using ::base::WaitableEvent;
+using ::std::string;
+
+namespace chromeos {
+namespace printing {
+namespace {
+
+const char kTestQuirksServer[] = "bogusserver.bogus.com";
+const char kTestAPIKey[] = "BOGUSAPIKEY";
+const char kTestManufacturer[] = "Bogus Printer Corp";
+const char kTestModel[] = "MegaPrint 9000";
+const char kQuirksResponse[] =
+ "{\n"
+ " \"compressedPpd\": \"\u000e4manu_a model_1\",\n"
+ " \"lastUpdatedTime\": \"1\"\n"
+ "}\n";
+
+class PPDProviderTest : public ::testing::Test {
+ public:
+ PPDProviderTest()
+ : loop_(base::MessageLoop::TYPE_IO),
+ request_context_getter_(
+ new ::net::TestURLRequestContextGetter(loop_.task_runner().get())) {
+ }
+
+ protected:
+ ::base::MessageLoop loop_;
+ ::base::RunLoop run_loop_;
+ scoped_refptr<::net::URLRequestContextGetter> request_context_getter_;
+};
+
+// Struct that just captures the callback result for a PPDProvider lookup
+struct CapturedLookupResult {
+ bool initialized = false;
+ PPDProvider::LookupResult result;
+ Printer::PPDFile file;
+};
+
+void CaptureLookupResult(CapturedLookupResult* capture,
+ PPDProvider::LookupResult result,
+ Printer::PPDFile file) {
+ capture->initialized = true;
+ capture->result = result;
+ capture->file = file;
+}
+
+TEST_F(PPDProviderTest, hmm) {
+ ::base::ScopedTempDir temp_dir;
+ CHECK(temp_dir.CreateUniqueTempDir());
+ auto cache_options = PPDCache::Options();
+ cache_options.cache_directory = temp_dir.path();
+ auto cache = PPDCache::Create(cache_options);
+ auto provider_options = PPDProvider::Options();
+ provider_options.quirks_server = kTestQuirksServer;
+ provider_options.api_key = kTestAPIKey;
+ auto provider = PPDProvider::Create(request_context_getter_, std::move(cache),
+ provider_options);
+ Printer::PPDFile out;
+
+ ::net::TestURLRequestInterceptor interceptor(
+ "https", kTestQuirksServer, ::base::ThreadTaskRunnerHandle::Get(),
+ ::base::ThreadTaskRunnerHandle::Get());
+
+ GURL expected_url(string("https://") + kTestQuirksServer //
+ + "/v2/printer/manufacturers/" //
+ + kTestManufacturer //
+ + "/models/" //
+ + kTestModel //
+ + "?key=" //
+ + kTestAPIKey);
+
+ FilePath contents_path = temp_dir.path().Append("response");
+ string contents = kQuirksResponse;
+ CHECK(base::WriteFile(contents_path, kQuirksResponse,
+ strlen(kQuirksResponse)) > 0);
+
+ interceptor.SetResponse(expected_url, contents_path);
+
+ CapturedLookupResult captured;
+ provider->Lookup(kTestManufacturer, kTestModel,
+ ::base::Bind(CaptureLookupResult, &captured));
+ run_loop_.RunUntilIdle();
+ ASSERT_TRUE(captured.initialized);
+ ASSERT_EQ(captured.result, PPDProvider::SUCCESS);
+}
+
+} // namespace
+} // namespace printing
+} // namespace chromeos
« chromeos/printing/ppd_provider.cc ('K') | « chromeos/printing/ppd_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698